Skip to content

Commit

Permalink
Refactoring devices models
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 17, 2024
1 parent 2368e33 commit 0479ab7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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] };
});
Expand All @@ -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 ],

Check warning on line 141 in pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachinePciDevices/index.vue

View workflow job for this annotation

GitHub Actions / lint

There should be no space after '['

Check warning on line 141 in pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachinePciDevices/index.vue

View workflow job for this annotation

GitHub Actions / lint

There should be no space before ']'
} : acc;
}, {});
},
// determine which nodes contain all devices selected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] };
});
Expand All @@ -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 ],

Check warning on line 140 in pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineUSBDevices/index.vue

View workflow job for this annotation

GitHub Actions / lint

There should be no space after '['

Check warning on line 140 in pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineUSBDevices/index.vue

View workflow job for this annotation

GitHub Actions / lint

There should be no space before ']'
} : acc;
}, {});
},
compatibleNodes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Check warning on line 92 in pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
vm.hostDevices.forEach((device) => {
inUse[device.name] = { usedBy: [vm.metadata.name] };
});
Expand All @@ -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 ],

Check warning on line 109 in pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue

View workflow job for this annotation

GitHub Actions / lint

There should be no space after '['

Check warning on line 109 in pkg/harvester/edit/kubevirt.io.virtualmachine/VirtualMachineVGpuDevices/index.vue

View workflow job for this annotation

GitHub Actions / lint

There should be no space before ']'
} : acc;
}, {});
},
compatibleNodes() {
Expand Down
4 changes: 4 additions & 0 deletions pkg/harvester/models/kubevirt.io.virtualmachine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {});
Expand Down

0 comments on commit 0479ab7

Please sign in to comment.