Skip to content

Commit

Permalink
Merge pull request #2880 from weili520/delete_resource_deault_gpu
Browse files Browse the repository at this point in the history
fix: Delete gpu field when editing project default resource
  • Loading branch information
ks-ci-bot authored Dec 29, 2021
2 parents df7f53c + 721e3e4 commit 7482b45
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 25 deletions.
15 changes: 1 addition & 14 deletions src/actions/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with KubeSphere Console. If not, see <https://www.gnu.org/licenses/>.
*/

import { get, set, omitBy, isEmpty, omit } from 'lodash'
import { get, set, omitBy, isEmpty } from 'lodash'
import { Notify } from '@kube-design/components'
import { Modal } from 'components/Base'
import QuotaEditModal from 'components/Modals/QuotaEdit'
Expand Down Expand Up @@ -122,19 +122,6 @@ export default {
}) {
const modal = Modal.open({
onOk: async data => {
const gpu = get(data, 'gpu', {})
data = omit(data, 'gpu')
detail = omit(detail, 'limit.gpu')

// if requests and limits is unsetted, they will be undefined
// for set gpu params, it should be an object
if (isEmpty(data.default) && isEmpty(data.defaultRequest)) {
data = { ...data, default: {}, defaultRequest: {} }
}
if (!isEmpty(gpu) && gpu.type !== '' && gpu.value !== '') {
set(data, `default["${gpu.type}"]`, Number(gpu.value))
}

// deal with the case that input number as 4.
const { limits, requests } = limits_Request_EndsWith_Dot({
limits: data.default,
Expand Down
9 changes: 7 additions & 2 deletions src/components/Inputs/ResourceLimit/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,13 @@ export default class ResourceLimit extends React.Component {
}

// pass gpu input config into limits and requests field
set(result, 'limits', { ...result.limits, [`${gpu.type}`]: gpu.value })
set(result, 'requests', { ...result.requests, [`${gpu.type}`]: gpu.value })
if (!!gpu.type && !!gpu.value) {
set(result, 'limits', { ...result.limits, [`${gpu.type}`]: gpu.value })
set(result, 'requests', {
...result.requests,
[`${gpu.type}`]: gpu.value,
})
}

onChange(result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with KubeSphere Console. If not, see <https://www.gnu.org/licenses/>.
*/

import { get } from 'lodash'
import { get, endsWith, isEmpty } from 'lodash'
import React from 'react'

import { Icon } from '@kube-design/components'
Expand All @@ -36,6 +36,15 @@ class DefaultResource extends React.Component {
const memoryRequest = memoryFormat(
get(detail, 'limit.defaultRequest.memory')
)
// get GPU config from the supported type
const supportGpu = globals.config.supportGpuType
const defaultRequest = get(detail, 'limit.defaultRequest', {})
const gpuType = supportGpu.filter(type =>
Object.keys(defaultRequest).some(key => endsWith(key, type))
)
const gpu = isEmpty(gpuType)
? {}
: { value: defaultRequest[`${gpuType[0]}`], type: gpuType }

return (
<Panel title={t('DEFAULT_CONTAINER_QUOTA_PL')}>
Expand Down Expand Up @@ -68,6 +77,17 @@ class DefaultResource extends React.Component {
<p>{t('MEMORY_LIMIT_SCAP')}</p>
</div>
</div>
<div className={styles.contentItem}>
<img src="/assets/GPU.svg" size={48} />
<div className={styles.item}>
<div>{gpu.value ? gpu.type : t('NONE')}</div>
<p>{t('GPU_TYPE_SCAP')}</p>
</div>
<div className={styles.item}>
<div>{gpu.value ? gpu.value : t('NO_LIMIT_TCAP')}</div>
<p>{t('GPU_LIMIT_SCAP')}</p>
</div>
</div>
</div>
</Panel>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
@import '~scss/mixins';

.item {
min-width: 160px;
margin-left: 12px;
flex: 1;

& > div {
@include TypographyTitleH6($dark-color07);
Expand All @@ -18,8 +18,10 @@
display: flex;
justify-content: flex-start;
padding: 8px 12px;
overflow: auto;
}

.contentItem {
display: flex;
flex: 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ export default class DefaultResourceEditModal extends React.Component {
return {
requests: get(this.props.detail, 'limit.defaultRequest', {}),
limits: get(this.props.detail, 'limit.default', {}),
gpu: get(this.props.detail, 'limit.gpu', {
type: '',
value: '',
}),
}
}

Expand All @@ -94,7 +90,6 @@ export default class DefaultResourceEditModal extends React.Component {
data: {
default: data.limits,
defaultRequest: data.requests,
gpu: data.gpu,
},
})
}
Expand Down
12 changes: 10 additions & 2 deletions src/pages/projects/containers/BaseInfo/DefaultResource/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* along with KubeSphere Console. If not, see <https://www.gnu.org/licenses/>.
*/

import { get } from 'lodash'
import { get, endsWith, isEmpty } from 'lodash'
import React from 'react'

import { Icon } from '@kube-design/components'
Expand All @@ -36,7 +36,15 @@ class DefaultResource extends React.Component {
const memoryRequest = memoryFormat(
get(detail, 'limit.defaultRequest.memory')
)
const gpu = get(detail, 'limit.gpu', {})
// get GPU config from the supported type
const supportGpu = globals.config.supportGpuType
const defaultRequest = get(detail, 'limit.defaultRequest', {})
const gpuType = supportGpu.filter(type =>
Object.keys(defaultRequest).some(key => endsWith(key, type))
)
const gpu = isEmpty(gpuType)
? {}
: { value: defaultRequest[`${gpuType[0]}`], type: gpuType }

return (
<Panel title={t('DEFAULT_CONTAINER_QUOTA_PL')}>
Expand Down

0 comments on commit 7482b45

Please sign in to comment.