Skip to content

Commit

Permalink
Select vGpus by type; Remove vGpu profile from labels
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 Aug 8, 2024
1 parent 9ea14af commit 965287d
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions pkg/harvester-manager/machine-config/harvester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Banner } from '@components/Banner';
import { clone, get } from '@shell/utils/object';
import { uniq, removeObject } from '@shell/utils/array';
import { _CREATE } from '@shell/config/query-params';
import { _CREATE, _VIEW } from '@shell/config/query-params';
import { mapGetters } from 'vuex';
import {
Expand Down Expand Up @@ -376,7 +376,7 @@ export default {
if (this.value.vgpuInfo) {
const vGPURequests = JSON.parse(this.value.vgpuInfo)?.vGPURequests;
vGpus = vGPURequests?.map((r) => r?.name).filter((r) => r) || [];
vGpus = vGPURequests?.map((r) => r?.deviceName).filter((f) => f) || [];
}
return {
Expand Down Expand Up @@ -482,10 +482,14 @@ export default {
},
vGpuOptions() {
return uniq([
const vGpuTypes = uniq([
...this.vGpusInit,
...Object.keys(this.vGpuDevices).filter((k) => this.vGpuDevices[k].enabled && this.vGpuDevices[k].allocatable > 0),
...Object.values(this.vGpuDevices)
.filter((vGpu) => vGpu.enabled && vGpu.allocatable > 0 && !!vGpu.type)
.map((vGpu) => vGpu.type),
]);
return vGpuTypes;
}
},
Expand Down Expand Up @@ -884,13 +888,14 @@ export default {
},
updateVGpu() {
const vGPURequests = this.vGpus?.filter((name) => name).reduce((acc, name) => ([
...acc,
{
name,
deviceName: this.vGpuDevices[name]?.type,
}
]), []);
/**
* We are assigning the first vGpu profile found for each vGpu type selected by the user.
* This will not work if we will remove the limit of only one vGpu assignable to each cluster.
*/
const vGPURequests = this.vGpus?.filter((f) => f).map((deviceName) => ({
name: Object.values(this.vGpuDevices).filter((f) => f.type === deviceName)?.[0]?.id || '',
deviceName,
})) || [];
this.value.vgpuInfo = vGPURequests.length > 0 ? JSON.stringify({ vGPURequests }) : '';
},
Expand Down Expand Up @@ -1091,19 +1096,23 @@ export default {
},
vGpuOptionLabel(opt) {
const vGpu = this.vGpuDevices[opt];
let label = opt.replace(VGPU_PREFIX.NVIDIA, '');
if (vGpu) {
let label = `${ vGpu.type?.replace(VGPU_PREFIX.NVIDIA, '') } - ${ vGpu.id }`;
if (this.mode === _VIEW) {
return label;
}
if (vGpu.allocatable > 0) {
label += ` (allocatable: ${ vGpu.allocatable })`;
}
/**
* We get the allocatable label from the first vGpu profile found for each vGpu type.
* This is consistent as long as vGpu profiles with the same vGpu type, have the same allocable number.
*/
const vGpu = Object.values(this.vGpuDevices).filter((f) => f.type === opt)?.[0];
return label;
if (vGpu?.allocatable > 0) {
label += ` (allocatable: ${ vGpu.allocatable })`;
}
return opt;
return label;
}
}
};
Expand Down

0 comments on commit 965287d

Please sign in to comment.