Skip to content

Commit

Permalink
Add vGpus field in Harvester clusters provision
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 Apr 18, 2024
1 parent 8ee0f7f commit b487acb
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 4 deletions.
4 changes: 4 additions & 0 deletions pkg/harvester-manager/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ harvesterManager:
addLabel: Add Workload Selector
topologyKey:
placeholder: 'topology.kubernetes.io/zone'
vGpu:
title: VGPUs
label: VGPU type
placeholder: 'Please select a VGPU'
60 changes: 58 additions & 2 deletions pkg/harvester-manager/machine-config/harvester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import InfoBox from '@shell/components/InfoBox';
import Loading from '@shell/components/Loading';
import CreateEditView from '@shell/mixins/create-edit-view';
import LabeledSelect from '@shell/components/form/LabeledSelect';
import ArrayListSelect from '@shell/components/form/ArrayListSelect';
import { LabeledInput } from '@components/Form/LabeledInput';
import UnitInput from '@shell/components/form/UnitInput';
import YamlEditor from '@shell/components/YamlEditor';
Expand Down Expand Up @@ -79,11 +80,13 @@ const SOURCE_TYPE = {
IMAGE: 'image',
};
const VGPU_PREFIX = { NVIDIA: 'nvidia.com/' };
export default {
name: 'ConfigComponentHarvester',
components: {
Checkbox, draggable, Loading, LabeledSelect, LabeledInput, UnitInput, Banner, YamlEditor, NodeAffinity, PodAffinity, InfoBox
ArrayListSelect, Checkbox, draggable, Loading, LabeledSelect, LabeledInput, UnitInput, Banner, YamlEditor, NodeAffinity, PodAffinity, InfoBox
},
mixins: [CreateEditView],
Expand Down Expand Up @@ -321,6 +324,7 @@ export default {
vmAffinity = { affinity: clone(vmAffinityObj) };
let vGpus = [];
let networkData = '';
let userData = '';
let installAgent;
Expand Down Expand Up @@ -350,6 +354,12 @@ export default {
}
}
if (this.value.vgpuInfo) {
const vGPURequests = JSON.parse(this.value.vgpuInfo)?.vGPURequests;
vGpus = vGPURequests?.map((r) => r.deviceName?.replace(VGPU_PREFIX.NVIDIA, '')).filter((r) => r) || [];
}
return {
credential: null,
vmAffinity,
Expand Down Expand Up @@ -378,7 +388,8 @@ export default {
userDataIsBase64,
networkDataIsBase64,
vmAffinityIsBase64,
SOURCE_TYPE
SOURCE_TYPE,
vGpus,
};
},
Expand Down Expand Up @@ -448,6 +459,21 @@ export default {
topologyKeyPlaceholder: this.t('harvesterManager.affinity.topologyKey.placeholder')
};
},
vGpuOptions() {
const vGpus = this.allNodeObjects.reduce((acc, node) => {
const nodeVGpus = Object.keys(node.status.allocatable || {})
.filter((k) => k.startsWith(VGPU_PREFIX.NVIDIA) && node.status.allocatable[k] > 0)
.map((k) => k.replace(VGPU_PREFIX.NVIDIA, '')) || [];
return [
...acc,
...nodeVGpus
];
}, []);
return vGpus.filter((x) => !this.vGpus.includes(x));
}
},
watch: {
Expand Down Expand Up @@ -812,6 +838,19 @@ export default {
}
},
updateVGpu() {
const vGPURequests = this.vGpus?.filter((name) => name).reduce((acc, name, i) => ([
...acc,
{
name: `vgpu${ i + 1 }`,
deviceName: `${ VGPU_PREFIX.NVIDIA }${ name }`
}
])
, []);
this.value.vgpuInfo = vGPURequests.length > 0 ? JSON.stringify({ vGPURequests }) : '';
},
addCloudConfigComment(value) {
if (typeof value === 'object' && value !== null) {
return `#cloud-config\n${ jsyaml.dump(value) }`;
Expand Down Expand Up @@ -1262,6 +1301,23 @@ export default {
</button>
<portal :to="'advanced-'+uuid">
<h3 class="mt-20">
{{ t("harvesterManager.vGpu.title") }}
</h3>
<div>
<ArrayListSelect
v-model="vGpus"
:array-list-props="{ addAllowed: true }"
:mode="mode"
:disabled="disabled"
:options="vGpuOptions"
:clearable="true"
label-key="harvesterManager.vGpu.label"
:placeholder="t('harvesterManager.vGpu.placeholder')"
@input="updateVGpu"
/>
</div>
<h3 class="mt-20">
{{ t("cluster.credential.harvester.userData.title") }}
</h3>
Expand Down
4 changes: 2 additions & 2 deletions shell/components/form/ArrayListSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default {
},
addAllowed() {
return this.filteredOptions.length > 0;
return this.arrayListProps?.addAllowed || this.filteredOptions.length > 0;
},
defaultAddValue() {
Expand All @@ -48,7 +48,7 @@ export default {
methods: {
updateRow(index, value) {
this.value.splice(index, 1, value);
this.$emit(value);
this.$emit('input', this.value);
},
calculateOptions(value) {
const valueOption = this.options.find((o) => o.value === value);
Expand Down

0 comments on commit b487acb

Please sign in to comment.