Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: User-defined resource quota and GPU limit are not displayed in the quotas card for the multi-cluster project #2873

Merged
merged 2 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ import { ICON_TYPES } from 'utils/constants'

import styles from './index.scss'

const QuotaItem = ({ name, total, used }) => {
const transformName = (text = '', type) =>
type === 'userDefined' && !text.includes('gpu')
? text
: t(text.replace(/[. ]/g, '_').toUpperCase())

const QuotaItem = ({ name, total, used, type }) => {
let ratio = 0

if (name === 'limits.cpu' || name === 'requests.cpu') {
Expand All @@ -46,12 +51,18 @@ const QuotaItem = ({ name, total, used }) => {
}

ratio = Math.min(Math.max(ratio, 0), 1)
const labelName = name.indexOf('gpu') > -1 ? 'gpu' : name
const labelText = labelName === 'gpu' ? `${labelName}.limit` : labelName
const iconType =
name.indexOf('gpu') > -1
? ICON_TYPES['gpu']
: ICON_TYPES[name] ?? 'resource'

return (
<div className={styles.quota}>
<Icon name={ICON_TYPES[name]} size={40} />
<Icon name={iconType} size={40} />
<div className={styles.item}>
<div>{t(name.replace('.', '_').toUpperCase())}</div>
<div>{transformName(labelText, type)}</div>
<p>{t('RESOURCE_TYPE_SCAP')}</p>
</div>
<div className={styles.item}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,20 @@ export default class ResourceQuota extends React.Component {

get items() {
const detail = this.store.data
const hard = get(detail, 'hard', {})
const quotaMaps = Object.values(QUOTAS_MAP).map(value => value.name)
const userDinedKeys = Object.keys(hard)
.filter(key => quotaMaps.indexOf(key) === -1)
.map(item => [item, { name: item, type: 'userDefined' }])
return Object.entries(QUOTAS_MAP)
.concat(userDinedKeys)
.map(([key, value]) => ({
key,
name: key,
total: get(detail, `hard["${value.name}"]`),
used: get(detail, `used["${value.name}"]`, 0),
left: get(detail, `left["${value.name}"]`),
type: value?.type ?? 'system',
}))
.filter(({ total, used, name }) => {
if (!total && !Number(used) && RESERVED_KEYS.indexOf(name) === -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ const QuotaItem = ({ name, total, used }) => {
return usedValue
}

const transformName = (text = '') =>
ICON_TYPES[labelName] ? t(text.replace(/[. ]/g, '_').toUpperCase()) : text

if (name === 'limits.cpu' || name === 'requests.cpu') {
if (total) {
ratio = Number(cpuFormat(used)) / Number(cpuFormat(total))
Expand Down Expand Up @@ -118,7 +121,7 @@ const QuotaItem = ({ name, total, used }) => {
<div className={styles.quota}>
<Icon name={ICON_TYPES[labelName] || 'resource'} size={40} />
<div className={styles.item}>
<div>{t(labelText.replace(/[. ]/g, '_').toUpperCase())}</div>
<div>{transformName(labelText)}</div>
<p>{t('RESOURCE_TYPE_SCAP')}</p>
</div>
<div className={styles.item}>
Expand Down