forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quota charts now show all resource types
- Loading branch information
Showing
26 changed files
with
537 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
.../packages/console-app/src/components/resource-quota/AppliedClusterResourceQuotaCharts.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import * as React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { DonutChart } from '@console/internal/components/graphs/donut'; | ||
import { AppliedClusterResourceQuotaKind } from '@console/internal/module/k8s'; | ||
import { getUsedPercentage, getLabelAndUsage } from './utils'; | ||
|
||
import './resource-quota.scss'; | ||
|
||
type AppliedClusterResourceQuotaChartsProps = { | ||
appliedClusterResourceQuota: AppliedClusterResourceQuotaKind; | ||
namespace: string; | ||
}; | ||
|
||
const AppliedClusterResourceQuotaCharts = ({ | ||
appliedClusterResourceQuota, | ||
namespace, | ||
}: AppliedClusterResourceQuotaChartsProps): JSX.Element => { | ||
const { t } = useTranslation(); | ||
const nsQuotas = appliedClusterResourceQuota.status?.namespaces?.find( | ||
(ns) => ns.namespace === namespace, | ||
); | ||
|
||
const charts = Object.keys(nsQuotas?.status?.hard ?? {}).map((resourceName) => { | ||
const clusterHard = appliedClusterResourceQuota.status.total?.hard?.[resourceName]; | ||
const clusterUsed = appliedClusterResourceQuota.status.total?.used?.[resourceName]; | ||
const nsUsed = nsQuotas.status.used?.[resourceName]; | ||
const clusterUsage = getUsedPercentage(clusterHard, clusterUsed); | ||
const unused = 100 - clusterUsage; | ||
|
||
const { label, percent: nsUsage } = getLabelAndUsage({ | ||
resourceName, | ||
used: nsUsed, | ||
hard: clusterHard, | ||
}); | ||
|
||
const percentOtherNamespaces = clusterUsage - nsUsage; | ||
|
||
return ( | ||
<div | ||
key={resourceName} | ||
className="co-resource-quota__chart" | ||
data-test="resource-quota-gauge-chart" | ||
> | ||
<DonutChart | ||
data={[ | ||
{ | ||
x: 'Namespace', | ||
y: nsUsage, | ||
}, | ||
{ | ||
x: 'Other namespaces', | ||
y: percentOtherNamespaces, | ||
}, | ||
{ | ||
x: 'Unused', | ||
y: unused, | ||
}, | ||
]} | ||
title={resourceName} | ||
label={label} | ||
/> | ||
</div> | ||
); | ||
}); | ||
|
||
return ( | ||
<div className="co-resource-quota-chart-row"> | ||
{charts.length ? charts : <>{t('console-app~No quota')}</>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default AppliedClusterResourceQuotaCharts; |
58 changes: 58 additions & 0 deletions
58
frontend/packages/console-app/src/components/resource-quota/ClusterResourceQuotaCharts.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { DonutChart } from '@console/internal/components/graphs/donut'; | ||
import { ClusterResourceQuotaKind } from '@console/internal/module/k8s'; | ||
import { getLabelAndUsage } from './utils'; | ||
|
||
import './resource-quota.scss'; | ||
|
||
type ClusterResourceQuotaChartsProps = { | ||
clusterResourceQuota: ClusterResourceQuotaKind; | ||
}; | ||
|
||
const ClusterResourceQuotaCharts = ({ | ||
clusterResourceQuota, | ||
}: ClusterResourceQuotaChartsProps): JSX.Element => { | ||
const { t } = useTranslation(); | ||
const charts = Object.keys(clusterResourceQuota.status?.total?.hard ?? {}).map((resourceName) => { | ||
const clusterHard = clusterResourceQuota.status.total.hard[resourceName]; | ||
const clusterUsed = clusterResourceQuota.status.total.used?.[resourceName]; | ||
|
||
const { label, percent } = getLabelAndUsage({ | ||
resourceName, | ||
used: clusterUsed, | ||
hard: clusterHard, | ||
}); | ||
|
||
return ( | ||
<div | ||
key={resourceName} | ||
className="co-resource-quota__chart" | ||
data-test="resource-quota-gauge-chart" | ||
> | ||
<DonutChart | ||
data={[ | ||
{ | ||
x: 'Used', | ||
y: percent, | ||
}, | ||
{ | ||
x: 'Unused', | ||
y: 100 - percent, | ||
}, | ||
]} | ||
title={resourceName} | ||
label={label} | ||
/> | ||
</div> | ||
); | ||
}); | ||
|
||
return ( | ||
<div className="co-resource-quota-chart-row"> | ||
{charts.length ? charts : <>{t('console-app~No quota')}</>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ClusterResourceQuotaCharts; |
46 changes: 46 additions & 0 deletions
46
frontend/packages/console-app/src/components/resource-quota/ResourceQuotaCharts.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { GaugeChart } from '@console/internal/components/graphs/gauge'; | ||
import { ResourceQuotaKind } from '@console/internal/module/k8s'; | ||
import { getLabelAndUsage } from './utils'; | ||
|
||
import './resource-quota.scss'; | ||
|
||
type ResourceQuotaChartsProps = { | ||
resourceQuota: ResourceQuotaKind; | ||
}; | ||
|
||
const ResourceQuotaCharts = ({ resourceQuota }: ResourceQuotaChartsProps): JSX.Element => { | ||
const { t } = useTranslation(); | ||
const charts = Object.keys(resourceQuota.status?.hard ?? {}).map((resourceName) => { | ||
const hard = resourceQuota.status.hard[resourceName]; | ||
const used = resourceQuota.status.used?.[resourceName]; | ||
|
||
const { label, percent } = getLabelAndUsage({ resourceName, used, hard }); | ||
return ( | ||
<div | ||
key={resourceName} | ||
className="co-resource-quota__chart" | ||
data-test="resource-quota-gauge-chart" | ||
> | ||
<GaugeChart | ||
data={{ | ||
x: `${percent}%`, | ||
y: percent, | ||
}} | ||
thresholds={[{ value: 90 }, { value: 101 }]} | ||
title={resourceName} | ||
label={label} | ||
/> | ||
</div> | ||
); | ||
}); | ||
|
||
return ( | ||
<div className="co-resource-quota-chart-row"> | ||
{charts.length ? charts : <>{t('console-app~No quota')}</>} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ResourceQuotaCharts; |
3 changes: 3 additions & 0 deletions
3
frontend/packages/console-app/src/components/resource-quota/resource-quota.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.co-resource-quota__chart { | ||
min-width: 170px; | ||
} |
47 changes: 47 additions & 0 deletions
47
frontend/packages/console-app/src/components/resource-quota/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { convertToBaseValue, humanizePercentage } from '@console/internal/components/utils'; | ||
|
||
const genericCountResources = [ | ||
'configmaps', | ||
'persistentvolumeclaims', | ||
'pods', | ||
'replicationcontrollers', | ||
'resourcequotas', | ||
'services', | ||
'services.loadbalancers', | ||
'services.nodeports', | ||
'secrets', | ||
'openshift.io/imagestreams', | ||
]; | ||
|
||
export const getUsedPercentage = (hard: string, used: string) => { | ||
let usedNum = convertToBaseValue(used); | ||
let hardNum = convertToBaseValue(hard); | ||
|
||
if (!usedNum || !hardNum) { | ||
// try to get the value without unit | ||
usedNum = parseInt(usedNum, 10); | ||
hardNum = parseInt(hardNum, 10); | ||
} | ||
|
||
return !usedNum || !hardNum ? 0 : (usedNum / hardNum) * 100; | ||
}; | ||
|
||
export const getLabelAndUsage = ({ | ||
resourceName, | ||
used, | ||
hard, | ||
}: { | ||
resourceName: string; | ||
used: string; | ||
hard: string; | ||
}) => { | ||
const useCount = | ||
resourceName.startsWith('count/') || genericCountResources.includes(resourceName); | ||
|
||
const percent = getUsedPercentage(hard, used); | ||
|
||
return { | ||
label: useCount ? `${used || 0} of ${hard}` : humanizePercentage(percent).string, | ||
percent, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.