Skip to content

Commit 70a8726

Browse files
authored
feat: adds GPU mutation (#591)
**What problem does this PR solve?**: **Which issue(s) this PR fixes**: Addresses: https://jira.nutanix.com/browse/D2IQ-100465 **How Has This Been Tested?**: <!-- Please describe the tests that you ran to verify your changes. Provide output from the tests and any manual steps needed to replicate the tests. --> This hasn't been tested yet. I am planning on doing this soon. **Special notes for your reviewer**: <!-- Use this to provide any additional information to the reviewers. This may include: - Best way to review the PR. - Where the author wants the most review attention on. - etc. -->
1 parent 219c745 commit 70a8726

File tree

7 files changed

+130
-1
lines changed

7 files changed

+130
-1
lines changed

api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,29 @@ spec:
270270
required:
271271
- type
272272
type: object
273+
gpus:
274+
description: List of GPU devices that need to be added
275+
to the machines.
276+
items:
277+
properties:
278+
deviceID:
279+
description: deviceID is the id of the GPU entity.
280+
format: int64
281+
type: integer
282+
name:
283+
description: name is the GPU name
284+
type: string
285+
type:
286+
description: Type is the identifier type to use
287+
for this resource.
288+
enum:
289+
- deviceID
290+
- name
291+
type: string
292+
required:
293+
- type
294+
type: object
295+
type: array
273296
image:
274297
description: |-
275298
image identifies the image uploaded to Prism Central (PC). The identifier

api/v1alpha1/crds/caren.nutanix.com_nutanixnodeconfigs.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,29 @@ spec:
8888
required:
8989
- type
9090
type: object
91+
gpus:
92+
description: List of GPU devices that need to be added to
93+
the machines.
94+
items:
95+
properties:
96+
deviceID:
97+
description: deviceID is the id of the GPU entity.
98+
format: int64
99+
type: integer
100+
name:
101+
description: name is the GPU name
102+
type: string
103+
type:
104+
description: Type is the identifier type to use for
105+
this resource.
106+
enum:
107+
- deviceID
108+
- name
109+
type: string
110+
required:
111+
- type
112+
type: object
113+
type: array
91114
image:
92115
description: |-
93116
image identifies the image uploaded to Prism Central (PC). The identifier

api/v1alpha1/nutanix_node_types.go

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ type NutanixMachineDetails struct {
6060
// The project must already be present in the Prism Central.
6161
// +kubebuilder:validation:Optional
6262
Project *NutanixResourceIdentifier `json:"project,omitempty"`
63+
64+
// List of GPU devices that need to be added to the machines.
65+
// +kubebuilder:validation:Optional
66+
GPUs []capxv1.NutanixGPU `json:"gpus,omitempty"`
6367
}
6468

6569
// NutanixIdentifierType is an enumeration of different resource identifier types.

api/v1alpha1/zz_generated.deepcopy.go

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/customization/nutanix/machine-details.md

+43
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,46 @@ spec:
228228
type: name
229229
name: project-name
230230
```
231+
232+
### (Optional) Add a GPU to a machine deployment
233+
234+
```yaml
235+
apiVersion: cluster.x-k8s.io/v1beta1
236+
kind: Cluster
237+
metadata:
238+
name: <NAME>
239+
spec:
240+
topology:
241+
variables:
242+
- name: workerConfig
243+
value:
244+
nutanix:
245+
machineDetails:
246+
gpus:
247+
- type: name
248+
name: "Ampere 40"
249+
workers:
250+
- class: nutanix-quick-start-worker
251+
metadata:
252+
annotations:
253+
cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: "1"
254+
cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: "1"
255+
name: gpu-0
256+
```
257+
258+
Applying this configuration will result in the following value being set:
259+
260+
- control-plane `NutanixMachineTemplate`:
261+
262+
```yaml
263+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
264+
kind: NutanixMachineTemplate
265+
metadata:
266+
name: nutanix-quick-start-gpu-nmt
267+
spec:
268+
template:
269+
spec:
270+
gpus:
271+
- type: name
272+
name: "Ampere 40"
273+
```

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate(
122122
capxv1.NutanixResourceIdentifier(*nutanixMachineDetailsVar.Project),
123123
)
124124
}
125-
125+
spec.GPUs = make(
126+
[]capxv1.NutanixGPU,
127+
len(nutanixMachineDetailsVar.GPUs),
128+
)
129+
copy(spec.GPUs, nutanixMachineDetailsVar.GPUs)
126130
obj.Spec.Template.Spec = spec
127131
return nil
128132
},

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

+24
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: []capxv1.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.HaveKeyWithValue("deviceID", gomega.BeNumerically("==", 1)),
82+
),
83+
),
84+
},
6185
{
6286
Operation: "add",
6387
Path: "/spec/template/spec/bootType",

0 commit comments

Comments
 (0)