Skip to content

feat: adds GPU mutation #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,29 @@ spec:
required:
- type
type: object
gpus:
description: List of GPU devices that need to be added
to the machines.
items:
properties:
deviceID:
description: DeviceID is the id of the GPU entity.
format: int64
type: integer
name:
description: Name is the GPU name
type: string
type:
description: Type is the identifier type to use
for this resource.
enum:
- deviceID
- name
type: string
required:
- type
type: object
type: array
image:
description: |-
image identifies the image uploaded to Prism Central (PC). The identifier
Expand Down
23 changes: 23 additions & 0 deletions api/v1alpha1/crds/caren.nutanix.com_nutanixnodeconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ spec:
required:
- type
type: object
gpus:
description: List of GPU devices that need to be added to
the machines.
items:
properties:
deviceID:
description: DeviceID is the id of the GPU entity.
format: int64
type: integer
name:
description: Name is the GPU name
type: string
type:
description: Type is the identifier type to use for
this resource.
enum:
- deviceID
- name
type: string
required:
- type
type: object
type: array
image:
description: |-
image identifies the image uploaded to Prism Central (PC). The identifier
Expand Down
21 changes: 21 additions & 0 deletions api/v1alpha1/nutanix_node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ type NutanixMachineDetails struct {
// The project must already be present in the Prism Central.
// +kubebuilder:validation:Optional
Project *NutanixResourceIdentifier `json:"project,omitempty"`

// List of GPU devices that need to be added to the machines.
// +kubebuilder:validation:Optional
GPUs []NutanixGPU `json:"gpus,omitempty"`
}

type NutanixGPU struct {
// Type is the identifier type to use for this resource.
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum:=deviceID;name
Type NutanixGPUIdentifierType `json:"type"`

// DeviceID is the id of the GPU entity.
// +optional
DeviceID *int64 `json:"deviceID,omitempty"`

// Name is the GPU name
// +optional
Name *string `json:"name,omitempty"`
}

// NutanixIdentifierType is an enumeration of different resource identifier types.
Expand All @@ -71,3 +90,5 @@ type NutanixBootType capxv1.NutanixBootType
type NutanixResourceIdentifier capxv1.NutanixResourceIdentifier

type NutanixCategoryIdentifier capxv1.NutanixCategoryIdentifier

type NutanixGPUIdentifierType capxv1.NutanixGPUIdentifierType
32 changes: 32 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions docs/content/customization/nutanix/machine-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,46 @@ spec:
type: name
name: project-name
```

### (Optional) Add a GPU to a machine deployment

```yaml
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: <NAME>
spec:
topology:
variables:
- name: workerConfig
value:
nutanix:
machineDetails:
gpus:
- type: name
name: "Ampere 40"
workers:
- class: nutanix-quick-start-worker
metadata:
annotations:
cluster.x-k8s.io/cluster-api-autoscaler-node-group-max-size: "1"
cluster.x-k8s.io/cluster-api-autoscaler-node-group-min-size: "1"
name: gpu-0
```

Applying this configuration will result in the following value being set:

- control-plane `NutanixMachineTemplate`:

```yaml
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixMachineTemplate
metadata:
name: nutanix-quick-start-gpu-nmt
spec:
template:
spec:
gpus:
- type: name
name: "Ampere 40"
```
18 changes: 18 additions & 0 deletions pkg/handlers/nutanix/mutation/machinedetails/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate(
capxv1.NutanixResourceIdentifier(*nutanixMachineDetailsVar.Project),
)
}
if nutanixMachineDetailsVar.GPUs != nil {
spec.GPUs = make(
[]capxv1.NutanixGPU,
len(nutanixMachineDetailsVar.GPUs),
)

for i, gpu := range nutanixMachineDetailsVar.GPUs {
gpuType := capxv1.NutanixGPUIdentifierType(gpu.Type)
spec.GPUs[i] = capxv1.NutanixGPU{
Type: gpuType,
}
if gpuType == capxv1.NutanixGPUIdentifierName {
spec.GPUs[i].Name = gpu.Name
continue
}
spec.GPUs[i].DeviceID = gpu.DeviceID
}
}

obj.Spec.Template.Spec = spec
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,33 @@ var (
Type: capxv1.NutanixIdentifierName,
Name: ptr.To("fake-project"),
}),
GPUs: []v1alpha1.NutanixGPU{
{
Type: "name",
Name: ptr.To("gpu1"),
},
{
Type: "deviceID",
DeviceID: ptr.To(int64(1)),
},
},
}

matchersForAllFieldsSet = []capitest.JSONPatchMatcher{
{
Operation: "add",
Path: "/spec/template/spec/gpus",
ValueMatcher: gomega.ContainElements(
gomega.SatisfyAll(
gomega.HaveKeyWithValue("type", "name"),
gomega.HaveKeyWithValue("name", "gpu1"),
),
gomega.SatisfyAll(
gomega.HaveKeyWithValue("type", "deviceID"),
gomega.HaveKeyWithValue("deviceID", gomega.BeNumerically("==", 1)),
),
),
},
{
Operation: "add",
Path: "/spec/template/spec/bootType",
Expand Down
Loading