fix: VM's machine type options is not support (#307)

* feat: get options from API

Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>

* feat: add feature flag

Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>

* refactor: remove default value

Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>

* refactor: fallback to none

Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>

---------

Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>
This commit is contained in:
Yiya Chen 2025-06-02 12:38:04 +08:00 committed by GitHub
parent d6da4898b4
commit 7ecc9c320d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 9 deletions

View File

@ -37,7 +37,9 @@ const FEATURE_FLAGS = {
'liveMigrationProgress' 'liveMigrationProgress'
], ],
'v1.5.1': [], 'v1.5.1': [],
'v1.6.0': [] 'v1.6.0': [
'vmMachineTypes'
]
}; };
const generateFeatureFlags = () => { const generateFeatureFlags = () => {

View File

@ -114,13 +114,11 @@ export default {
}, },
machineTypeOptions() { machineTypeOptions() {
return [{ return this.machineTypes.map((type) => {
label: 'None', if (!type) return { label: 'None', value: '' };
value: ''
}, { return { label: type, value: type };
label: 'q35', });
value: 'q35'
}];
}, },
templateOptions() { templateOptions() {

View File

@ -157,6 +157,7 @@ export default {
diskRows: [], diskRows: [],
networkRows: [], networkRows: [],
machineType: '', machineType: '',
machineTypes: [],
secretName: '', secretName: '',
secretRef: null, secretRef: null,
showAdvanced: false, showAdvanced: false,
@ -295,6 +296,9 @@ export default {
async created() { async created() {
await this.$store.dispatch(`${ this.inStore }/findAll`, { type: SECRET }); await this.$store.dispatch(`${ this.inStore }/findAll`, { type: SECRET });
const machineTypes = this.value.vmMachineTypesFeatureEnabled ? await this.$store.dispatch('harvester/request', { url: '/v1/harvester/clusters/local?link=machineTypes' }) : [''];
this.machineTypes = machineTypes;
this.getInitConfig({ value: this.value, init: this.isCreate }); this.getInitConfig({ value: this.value, init: this.isCreate });
}, },
@ -331,7 +335,8 @@ export default {
const maintenanceStrategy = vm.metadata.labels?.[HCI_ANNOTATIONS.VM_MAINTENANCE_MODE_STRATEGY] || 'Migrate'; const maintenanceStrategy = vm.metadata.labels?.[HCI_ANNOTATIONS.VM_MAINTENANCE_MODE_STRATEGY] || 'Migrate';
const runStrategy = spec.runStrategy || 'RerunOnFailure'; const runStrategy = spec.runStrategy || 'RerunOnFailure';
const machineType = value.machineType; const machineType = spec.template.spec.domain?.machine?.type || this.machineTypes[0];
const cpu = spec.template.spec.domain?.cpu?.cores; const cpu = spec.template.spec.domain?.cpu?.cores;
const memory = spec.template.spec.domain.resources.limits.memory; const memory = spec.template.spec.domain.resources.limits.memory;
const reservedMemory = vm.metadata?.annotations?.[HCI_ANNOTATIONS.VM_RESERVED_MEMORY]; const reservedMemory = vm.metadata?.annotations?.[HCI_ANNOTATIONS.VM_RESERVED_MEMORY];

View File

@ -1205,6 +1205,10 @@ export default class VirtVm extends HarvesterResource {
return this.$rootGetters['harvester-common/getFeatureEnabled']('thirdPartyStorage'); return this.$rootGetters['harvester-common/getFeatureEnabled']('thirdPartyStorage');
} }
get vmMachineTypesFeatureEnabled() {
return this.$rootGetters['harvester-common/getFeatureEnabled']('vmMachineTypes');
}
setInstanceLabels(val) { setInstanceLabels(val) {
if ( !this.spec?.template?.metadata?.labels ) { if ( !this.spec?.template?.metadata?.labels ) {
set(this, 'spec.template.metadata.labels', {}); set(this, 'spec.template.metadata.labels', {});