diff --git a/pkg/harvester/config/labels-annotations.js b/pkg/harvester/config/labels-annotations.js index 1a01034507f..ba1864ffb03 100644 --- a/pkg/harvester/config/labels-annotations.js +++ b/pkg/harvester/config/labels-annotations.js @@ -51,5 +51,6 @@ export const HCI = { PARENT_SRIOV_GPU: 'harvesterhci.io/parentSRIOVGPUDevice', VM_MAINTENANCE_MODE_STRATEGY: 'harvesterhci.io/maintain-mode-strategy', NODE_CPU_MANAGER_UPDATE_STATUS: 'harvesterhci.io/cpu-manager-update-status', - CPU_MANAGER: 'cpumanager' + CPU_MANAGER: 'cpumanager', + VM_DEVICE_ALLOCATION_DETAILS: 'harvesterhci.io/deviceAllocationDetails', }; diff --git a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue index a1af6ad95e9..d34ce4a765f 100644 --- a/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue +++ b/pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue @@ -8,6 +8,7 @@ import VGpuDeviceList from './VGpuDeviceList'; import remove from 'lodash/remove'; import { set } from '@shell/utils/object'; +import { uniq } from '@shell/utils/array'; export default { name: 'VirtualMachineVGpuDevices', @@ -45,7 +46,10 @@ export default { this[key] = res[key]; } - (this.value?.domain?.devices?.gpus || []).forEach(({ name }) => { + uniq([ + ...(this.value?.domain?.devices?.gpus || []).map(({ name }) => name), + ...Object.values(this.vm?.provisionedVGpus).reduce((acc, gpus) => [...acc, ...gpus], []) + ]).forEach((name) => { if (this.enabledDevices.find(device => device?.metadata?.name === name)) { this.selectedDevices.push(name); } diff --git a/pkg/harvester/models/kubevirt.io.virtualmachine.js b/pkg/harvester/models/kubevirt.io.virtualmachine.js index c1cc091c12f..627bbdd3381 100644 --- a/pkg/harvester/models/kubevirt.io.virtualmachine.js +++ b/pkg/harvester/models/kubevirt.io.virtualmachine.js @@ -1099,6 +1099,16 @@ export default class VirtVm extends HarvesterResource { return this.spec?.template?.spec?.domain?.devices?.hostDevices || []; } + get provisionedVGpus() { + try { + const deviceAllocationDetails = JSON.parse(this.metadata?.annotations[HCI_ANNOTATIONS.VM_DEVICE_ALLOCATION_DETAILS] || '{}'); + + return deviceAllocationDetails?.gpus || {}; + } catch (error) { + return {}; + } + } + setInstanceLabels(val) { if ( !this.spec?.template?.metadata?.labels ) { set(this, 'spec.template.metadata.labels', {});