diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachinePciDevices/index.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachinePciDevices/index.vue index ceff7530668..a187c5bee75 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachinePciDevices/index.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachinePciDevices/index.vue @@ -121,9 +121,8 @@ export default { if (vm.metadata.name === this.vm?.metadata?.name) { return inUse; } - const devices = get(vm, 'spec.template.spec.domain.devices.hostDevices') || []; - devices.forEach((device) => { + vm.hostDevices.forEach((device) => { inUse[device.name] = { usedBy: [vm.metadata.name] }; }); @@ -134,19 +133,14 @@ export default { }, devicesByNode() { - const out = {}; + return this.enabledDevices?.reduce((acc, device) => { + const name = device.status?.nodeName; - this.enabledDevices.forEach((deviceCRD) => { - const nodeName = deviceCRD.status?.nodeName; - - if (!out[nodeName]) { - out[nodeName] = [deviceCRD]; - } else { - out[nodeName].push(deviceCRD); - } - }); - - return out; + return name ? { + ...acc, + [name]: [ ...(acc[name] || []), device ], + } : acc; + }, {}); }, // determine which nodes contain all devices selected diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineUSBDevices/index.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineUSBDevices/index.vue index 00997603203..86f30374c2e 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineUSBDevices/index.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineUSBDevices/index.vue @@ -120,9 +120,8 @@ export default { if (vm.metadata.name === this.vm?.metadata?.name) { return inUse; } - const devices = get(vm, 'spec.template.spec.domain.devices.hostDevices') || []; - devices.forEach((device) => { + vm.hostDevices.forEach((device) => { inUse[device.name] = { usedBy: [vm.metadata.name] }; }); @@ -133,19 +132,14 @@ export default { }, devicesByNode() { - const out = {}; + return this.enabledDevices?.reduce((acc, device) => { + const name = device.status?.nodeName; - this.enabledDevices.forEach((deviceCRD) => { - const nodeName = deviceCRD.status?.nodeName; - - if (!out[nodeName]) { - out[nodeName] = [deviceCRD]; - } else { - out[nodeName].push(deviceCRD); - } - }); - - return out; + return name ? { + ...acc, + [name]: [ ...(acc[name] || []), device ], + } : acc; + }, {}); }, compatibleNodes() { diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue index 5bcf09f8ce9..0093b2b12d1 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue @@ -89,9 +89,8 @@ export default { if (vm.metadata.name === this.vm?.metadata?.name) { return inUse; } - const devices = get(vm, 'spec.template.spec.domain.devices.hostDevices') || []; - - devices.forEach((device) => { + + vm.hostDevices.forEach((device) => { inUse[device.name] = { usedBy: [vm.metadata.name] }; }); @@ -102,19 +101,14 @@ export default { }, devicesByNode() { - const out = {}; - - this.enabledDevices.forEach((deviceCRD) => { - const nodeName = deviceCRD.spec?.nodeName; + return this.enabledDevices?.reduce((acc, device) => { + const name = device.spec?.nodeName; - if (!out[nodeName]) { - out[nodeName] = [deviceCRD]; - } else { - out[nodeName].push(deviceCRD); - } - }); - - return out; + return name ? { + ...acc, + [name]: [ ...(acc[name] || []), device ], + } : acc; + }, {}); }, compatibleNodes() { diff --git a/pkg/harvester/models/kubevirt.io.virtualmachine.js b/pkg/harvester/models/kubevirt.io.virtualmachine.js index 3adef26c56e..97a74c3adcc 100644 --- a/pkg/harvester/models/kubevirt.io.virtualmachine.js +++ b/pkg/harvester/models/kubevirt.io.virtualmachine.js @@ -1079,6 +1079,10 @@ export default class VirtVm extends HarvesterResource { }); } + get hostDevices() { + return this.spec?.template?.spec?.domain?.devices?.hostDevices || []; + } + setInstanceLabels(val) { if ( !this.spec?.template?.metadata?.labels ) { set(this, 'spec.template.metadata.labels', {});