diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachinePciDevices/index.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachinePciDevices/index.vue index 952a7dd8..d6e75a31 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachinePciDevices/index.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachinePciDevices/index.vue @@ -97,11 +97,13 @@ export default { }); const devices = [ - ...this.otherDevices(this.value.domain.devices.hostDevices || []), + ...this.otherDevices(this.value?.domain?.devices?.hostDevices || []), ...formatted, ]; - set(this.value.domain.devices, 'hostDevices', devices); + if (devices.length > 0) { + set(this.value.domain.devices, 'hostDevices', devices); + } } }, @@ -121,7 +123,9 @@ export default { return inUse; } - vm.hostDevices.forEach((device) => { + const hostDevices = vm?.hostDevices || []; + + hostDevices.forEach((device) => { inUse[device.name] = { usedBy: [vm.metadata.name] }; }); diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineUSBDevices/index.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineUSBDevices/index.vue index 6a0204f9..72dec502 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineUSBDevices/index.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineUSBDevices/index.vue @@ -80,11 +80,13 @@ export default { }); const devices = [ - ...this.otherDevices(this.value.domain.devices.hostDevices || []), + ...this.otherDevices(this.value?.domain?.devices?.hostDevices || []), ...formatted, ]; - set(this.value.domain.devices, 'hostDevices', devices); + if (devices.length > 0) { + set(this.value.domain.devices, 'hostDevices', devices); + } } }, @@ -121,7 +123,9 @@ export default { return inUse; } - vm.hostDevices.forEach((device) => { + const hostDevices = vm?.hostDevices || []; + + hostDevices.forEach((device) => { inUse[device.name] = { usedBy: [vm.metadata.name] }; }); diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/index.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/index.vue index ce6a5624..98f5a30f 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/index.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/index.vue @@ -2,6 +2,7 @@ import { isEqual } from 'lodash'; import { mapGetters } from 'vuex'; import Tabbed from '@shell/components/Tabbed'; +import { clone } from '@shell/utils/object'; import Tab from '@shell/components/Tabbed/Tab'; import { Checkbox } from '@components/Form/Checkbox'; import CruResource from '@shell/components/CruResource'; @@ -17,7 +18,6 @@ import UsbDevices from './VirtualMachineUSBDevices/index'; import KeyValue from '@shell/components/form/KeyValue'; import { clear } from '@shell/utils/array'; -import { clone } from '@shell/utils/object'; import { saferDump } from '@shell/utils/create-yaml'; import { exceptionToErrorsArray } from '@shell/utils/error'; import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations'; @@ -410,12 +410,16 @@ export default { const cloneDeepNewVM = clone(this.value); delete cloneDeepNewVM?.metadata; + delete cloneDeepNewVM?.__clone; + delete this.cloneVM?.metadata; delete this.cloneVM?.__clone; const oldVM = JSON.parse(JSON.stringify(this.cloneVM)); const newVM = JSON.parse(JSON.stringify(cloneDeepNewVM)); + // we won't show restart dialog in yaml page as we don't have a way to detect change in yaml editor. + // only check VM is changed in form page. if (isEqual(oldVM, newVM)) { return; } @@ -424,7 +428,11 @@ export default { this.isOpen = true; this.$nextTick(() => { - this.$refs.restartDialog.resolve = resolve; + if (this?.$refs?.restartDialog) { + this.$refs.restartDialog.resolve = resolve; + } else { + return resolve(); + } }); }); }, diff --git a/pkg/harvester/mixins/harvester-vm/index.js b/pkg/harvester/mixins/harvester-vm/index.js index 8fa08a9f..019ea722 100644 --- a/pkg/harvester/mixins/harvester-vm/index.js +++ b/pkg/harvester/mixins/harvester-vm/index.js @@ -871,7 +871,7 @@ export default { } } - if (out.length === 0 && !!this.spec.template.spec.accessCredentials) { + if (out.length === 0 && !!this.spec.template.spec.accessCredentials === false) { delete this.spec.template.spec.accessCredentials; } else { this.spec.template.spec.accessCredentials = out;