Skip to content

Commit

Permalink
Add support for Harvester <1.3.2 versions - allocatable info is empty
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 9, 2024
1 parent 965287d commit 1328c7b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions pkg/harvester-manager/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ harvesterManager:
title: VGPUs
label: VGPU type
placeholder: 'Please select a VGPU'
allocatable: allocatable
allocatableUnknown: missing allocation info
32 changes: 22 additions & 10 deletions pkg/harvester-manager/machine-config/harvester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ export default {
const vGpuTypes = uniq([
...this.vGpusInit,
...Object.values(this.vGpuDevices)
.filter((vGpu) => vGpu.enabled && vGpu.allocatable > 0 && !!vGpu.type)
.filter((vGpu) => vGpu.enabled && !!vGpu.type && (vGpu.allocatable > 0 || vGpu.allocatable === 'unknown'))
.map((vGpu) => vGpu.type),
]);
Expand Down Expand Up @@ -706,24 +706,34 @@ export default {
const url = `/k8s/clusters/${ clusterId }/v1`;
const vGpus = await this.$store.dispatch('cluster/request', { url: `${ url }/${ HCI.VGPU_DEVICE }` });
const harvesterCluster = await this.$store.dispatch('cluster/request', { url: `${ url }/harvester/cluster/local` });
let deviceCapacity = {};
let deviceCapacity = null;
if (harvesterCluster?.links?.deviceCapacity) {
deviceCapacity = await this.$store.dispatch('cluster/request', { url: harvesterCluster?.links?.deviceCapacity });
try {
const harvesterCluster = await this.$store.dispatch('cluster/request', { url: `${ url }/harvester/cluster/local` });
if (harvesterCluster?.links?.deviceCapacity) {
deviceCapacity = await this.$store.dispatch('cluster/request', { url: harvesterCluster?.links?.deviceCapacity });
}
} catch (e) {
}
this.vGpuDevices = (vGpus?.data || [])
.reduce((acc, v) => {
const type = v.spec.vGPUTypeName ? `${ VGPU_PREFIX.NVIDIA }${ v.spec.vGPUTypeName.replace(' ', '_') }` : '';
let allocatable = 'unknown';
if (deviceCapacity) {
allocatable = deviceCapacity[type] ? Number(deviceCapacity[type]) : 0;
}
return {
...acc,
[v.id]: {
id: v.id,
enabled: v.spec.enabled,
allocatable: deviceCapacity[type] ? Number(deviceCapacity[type]) : 0,
id: v.id,
enabled: v.spec.enabled,
allocatable,
type,
},
};
Expand Down Expand Up @@ -1108,8 +1118,10 @@ export default {
*/
const vGpu = Object.values(this.vGpuDevices).filter((f) => f.type === opt)?.[0];
if (vGpu?.allocatable > 0) {
label += ` (allocatable: ${ vGpu.allocatable })`;
if (vGpu?.allocatable === 'unknown') {
label += ` (${ this.t('harvesterManager.vGpu.allocatableUnknown') })`;
} else if(vGpu?.allocatable > 0) {

Check warning on line 1123 in pkg/harvester-manager/machine-config/harvester.vue

View workflow job for this annotation

GitHub Actions / lint

Expected space(s) after "if"
label += ` (${ this.t('harvesterManager.vGpu.allocatable') }: ${ vGpu.allocatable })`;
}
return label;
Expand Down

0 comments on commit 1328c7b

Please sign in to comment.