From 1328c7b7a70ba980c693478b0b6013a36893160a Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Fri, 9 Aug 2024 13:15:39 +0200 Subject: [PATCH] Add support for Harvester <1.3.2 versions - allocatable info is empty Signed-off-by: Francesco Torchia --- pkg/harvester-manager/l10n/en-us.yaml | 2 ++ .../machine-config/harvester.vue | 32 +++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/harvester-manager/l10n/en-us.yaml b/pkg/harvester-manager/l10n/en-us.yaml index 6506b3e03c4..7da28f81e5e 100644 --- a/pkg/harvester-manager/l10n/en-us.yaml +++ b/pkg/harvester-manager/l10n/en-us.yaml @@ -24,3 +24,5 @@ harvesterManager: title: VGPUs label: VGPU type placeholder: 'Please select a VGPU' + allocatable: allocatable + allocatableUnknown: missing allocation info diff --git a/pkg/harvester-manager/machine-config/harvester.vue b/pkg/harvester-manager/machine-config/harvester.vue index dcdadc2bf4f..9d50e56c7f4 100644 --- a/pkg/harvester-manager/machine-config/harvester.vue +++ b/pkg/harvester-manager/machine-config/harvester.vue @@ -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), ]); @@ -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, }, }; @@ -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) { + label += ` (${ this.t('harvesterManager.vGpu.allocatable') }: ${ vGpu.allocatable })`; } return label;