Skip to content

Commit

Permalink
Update selected vGpus devices adding the provisioned devices
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
  • Loading branch information
torchiaf committed Sep 24, 2024
1 parent a2a67e7 commit ca6ff46
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/harvester/config/labels-annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/harvester/models/kubevirt.io.virtualmachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {});
Expand Down

0 comments on commit ca6ff46

Please sign in to comment.