From 8c03fee1345fe9fad43144abac3350f56bb58a37 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Wed, 18 Sep 2024 00:07:52 +0200 Subject: [PATCH] Update selected vGpus devices adding the provisioned devices Signed-off-by: Francesco Torchia --- pkg/harvester/config/labels-annotations.js | 3 ++- .../VirtualMachineVGpuDevices/index.vue | 6 +++++- pkg/harvester/models/kubevirt.io.virtualmachine.js | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) 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 70c5c4fdeb7..3d80d5062fe 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 { get, set } from '@shell/utils/object'; +import { uniq } from '@shell/utils/array'; export default { name: 'VirtualMachinedevices', @@ -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 3adef26c56e..b00b2da43e0 100644 --- a/pkg/harvester/models/kubevirt.io.virtualmachine.js +++ b/pkg/harvester/models/kubevirt.io.virtualmachine.js @@ -1079,6 +1079,16 @@ export default class VirtVm extends HarvesterResource { }); } + 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', {});