mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2025-12-13 21:21:44 +00:00
fix: bring default valueContext fwhen customizing vm-import controller
Signed-off-by: andy.lee <andy.lee@suse.com>
This commit is contained in:
parent
7b6efa624f
commit
2d6bc65b26
@ -1,34 +1,31 @@
|
|||||||
<script>
|
<script>
|
||||||
|
import merge from 'lodash/merge';
|
||||||
|
import jsyaml from 'js-yaml';
|
||||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||||
import Tabbed from '@shell/components/Tabbed';
|
import Tabbed from '@shell/components/Tabbed';
|
||||||
import Tab from '@shell/components/Tabbed/Tab';
|
import Tab from '@shell/components/Tabbed/Tab';
|
||||||
import { RadioGroup } from '@components/Form/Radio';
|
import { RadioGroup } from '@components/Form/Radio';
|
||||||
import LabeledSelect from '@shell/components/form/LabeledSelect';
|
import LabeledSelect from '@shell/components/form/LabeledSelect';
|
||||||
|
|
||||||
import CreateEditView from '@shell/mixins/create-edit-view';
|
import CreateEditView from '@shell/mixins/create-edit-view';
|
||||||
|
|
||||||
import { STORAGE_CLASS } from '@shell/config/types';
|
import { STORAGE_CLASS } from '@shell/config/types';
|
||||||
import { allHash } from '@shell/utils/promise';
|
import { allHash } from '@shell/utils/promise';
|
||||||
import { set, get, clone } from '@shell/utils/object';
|
|
||||||
|
|
||||||
const VALUES_YAML_KEYS = [
|
|
||||||
'resources.requests.cpu',
|
|
||||||
'resources.requests.memory',
|
|
||||||
'resources.limits.cpu',
|
|
||||||
'resources.limits.memory',
|
|
||||||
'pvcClaim.enabled',
|
|
||||||
'pvcClaim.size',
|
|
||||||
'pvcClaim.storageClassName',
|
|
||||||
];
|
|
||||||
|
|
||||||
const DEFAULT_VALUES = {
|
const DEFAULT_VALUES = {
|
||||||
'resources.requests.cpu': '0.5',
|
resources: {
|
||||||
'resources.requests.memory': '2Gi',
|
requests: {
|
||||||
'resources.limits.cpu': '2',
|
cpu: '0.5',
|
||||||
'resources.limits.memory': '4Gi',
|
memory: '2Gi'
|
||||||
'pvcClaim.enabled': false,
|
},
|
||||||
'pvcClaim.size': '200Gi',
|
limits: {
|
||||||
'pvcClaim.storageClassName': '',
|
cpu: '2',
|
||||||
|
memory: '4Gi'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
pvcClaim: {
|
||||||
|
enabled: false,
|
||||||
|
size: '200Gi',
|
||||||
|
storageClassName: ''
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -64,19 +61,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
let valuesObj = {};
|
const valuesContent = this.parseValuesContent();
|
||||||
|
|
||||||
try {
|
|
||||||
valuesObj = JSON.parse(this.value?.spec?.valuesContent || '{}');
|
|
||||||
} catch (err) {}
|
|
||||||
|
|
||||||
const valuesContent = clone(valuesObj);
|
|
||||||
|
|
||||||
VALUES_YAML_KEYS.map((key) => {
|
|
||||||
if (!get(valuesObj, key)) {
|
|
||||||
set(valuesContent, key, DEFAULT_VALUES[key]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return { valuesContent };
|
return { valuesContent };
|
||||||
},
|
},
|
||||||
@ -100,8 +85,21 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
parseValuesContent() {
|
||||||
|
try {
|
||||||
|
return merge({}, DEFAULT_VALUES, jsyaml.load(this.value.spec.valuesContent));
|
||||||
|
} catch (err) {
|
||||||
|
this.$store.dispatch('growl/fromError', {
|
||||||
|
title: this.$store.getters['i18n/t']('generic.notification.title.error'),
|
||||||
|
err: err.data || err,
|
||||||
|
}, { root: true });
|
||||||
|
|
||||||
|
return DEFAULT_VALUES;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
set(this.value, 'spec.valuesContent', JSON.stringify(this.valuesContent));
|
this.value.spec.valuesContent = jsyaml.dump(this.valuesContent);
|
||||||
},
|
},
|
||||||
|
|
||||||
setDefaultClassName() {
|
setDefaultClassName() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user