Skip to content

Commit 4c26db9

Browse files
committed
feat: wires up GPUs to mutation handler w/ tests
1 parent f56078b commit 4c26db9

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

pkg/handlers/nutanix/mutation/machinedetails/inject.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,24 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate(
122122
capxv1.NutanixResourceIdentifier(*nutanixMachineDetailsVar.Project),
123123
)
124124
}
125+
if nutanixMachineDetailsVar.GPUs != nil {
126+
spec.GPUs = make(
127+
[]capxv1.NutanixGPU,
128+
len(nutanixMachineDetailsVar.GPUs),
129+
)
130+
131+
for i, gpu := range nutanixMachineDetailsVar.GPUs {
132+
gpuType := capxv1.NutanixGPUIdentifierType(gpu.Type)
133+
spec.GPUs[i] = capxv1.NutanixGPU{
134+
Type: gpuType,
135+
}
136+
if gpuType == capxv1.NutanixGPUIdentifierName {
137+
spec.GPUs[i].Name = gpu.Name
138+
continue
139+
}
140+
spec.GPUs[i].DeviceID = gpu.DeviceID
141+
}
142+
}
125143

126144
obj.Spec.Template.Spec = spec
127145
return nil

pkg/handlers/nutanix/mutation/machinedetails/inject_control_plane_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,33 @@ var (
5555
Type: capxv1.NutanixIdentifierName,
5656
Name: ptr.To("fake-project"),
5757
}),
58+
GPUs: []v1alpha1.NutanixGPU{
59+
{
60+
Type: "name",
61+
Name: ptr.To("gpu1"),
62+
},
63+
{
64+
Type: "deviceID",
65+
DeviceID: ptr.To(int64(1)),
66+
},
67+
},
5868
}
5969

6070
matchersForAllFieldsSet = []capitest.JSONPatchMatcher{
71+
{
72+
Operation: "add",
73+
Path: "/spec/template/spec/gpus",
74+
ValueMatcher: gomega.ContainElements(
75+
gomega.SatisfyAll(
76+
gomega.HaveKeyWithValue("type", "name"),
77+
gomega.HaveKeyWithValue("name", "gpu1"),
78+
),
79+
gomega.SatisfyAll(
80+
gomega.HaveKeyWithValue("type", "deviceID"),
81+
gomega.HaveKey("deviceID"),
82+
),
83+
),
84+
},
6185
{
6286
Operation: "add",
6387
Path: "/spec/template/spec/bootType",

0 commit comments

Comments
 (0)