Skip to content

feat: support setting Nutanix project on machines #535

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 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions api/v1alpha1/nutanix_node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ type NutanixMachineDetails struct {
// systemDiskSize is size (in Quantity format) of the system disk of the VM
// The minimum systemDiskSize is 20Gi bytes
SystemDiskSize resource.Quantity `json:"systemDiskSize"`

// add the virtual machines to the project defined in Prism Central.
// The project must already be present in the Prism Central.
// +optional
Project *NutanixResourceIdentifier `json:"project,omitempty"`
}

func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
Expand Down Expand Up @@ -112,6 +117,10 @@ func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
Description: "systemDiskSize is size (in Quantity format) of the system disk of the VM eg. 20Gi",
Type: "string",
},
"project": NutanixResourceIdentifier{}.VariableSchemaFromDescription(
//nolint:lll // Long description.
"add the virtual machines to the project defined in Prism Central. The project must already be present in the Prism Central.",
).OpenAPIV3Schema,
},
Required: []string{
"vcpusPerSocket",
Expand Down
5 changes: 5 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.

120 changes: 119 additions & 1 deletion docs/content/customization/nutanix/machine-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Configure Machine Details of Control plane and Worker nodes

## Examples

### Set Machine details of Control Plane and Worker nodes
### (Required) Set Machine details for Control Plane and Worker nodes

```yaml
apiVersion: cluster.x-k8s.io/v1beta1
Expand Down Expand Up @@ -119,3 +119,121 @@ spec:
vcpuSockets: 2
vcpusPerSocket: 1
```

### (Optional) Set Additional Categories for Control Plane and Worker nodes

```yaml
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: <NAME>
spec:
topology:
variables:
- name: clusterConfig
value:
controlPlane:
nutanix:
machineDetails:
additionalCategories:
- key: example-key
value: example-value
- name: workerConfig
value:
nutanix:
machineDetails:
additionalCategories:
- key: example-key
value: example-value
```

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-cp-nmt
spec:
template:
spec:
additionalCategories:
- key: example-key
value: example-value
```

- worker `NutanixMachineTemplate`:

```yaml
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixMachineTemplate
metadata:
name: nutanix-quick-start-md-nmt
spec:
template:
spec:
additionalCategories:
- key: example-key
value: example-value
```

### (Optional) Set Project for Control Plane and Worker nodes

```yaml
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: <NAME>
spec:
topology:
variables:
- name: clusterConfig
value:
controlPlane:
nutanix:
machineDetails:
project:
type: name
name: project-name
- name: workerConfig
value:
nutanix:
machineDetails:
project:
type: name
name: project-name
```

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-cp-nmt
spec:
template:
spec:
project:
type: name
name: project-name
```

- worker `NutanixMachineTemplate`:

```yaml
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixMachineTemplate
metadata:
name: nutanix-quick-start-md-nmt
spec:
template:
spec:
project:
type: name
name: project-name
```
5 changes: 5 additions & 0 deletions pkg/handlers/nutanix/mutation/machinedetails/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/utils/ptr"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -116,6 +117,10 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate(
spec.AdditionalCategories[i] = capxv1.NutanixCategoryIdentifier(category)
}

if nutanixMachineDetailsVar.Project != nil {
spec.Project = ptr.To(capxv1.NutanixResourceIdentifier(*nutanixMachineDetailsVar.Project))
}

obj.Spec.Template.Spec = spec
return nil
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ var (
Value: "fake-value2",
},
},
Project: ptr.To(v1alpha1.NutanixResourceIdentifier{
Type: capxv1.NutanixIdentifierName,
Name: ptr.To("fake-project"),
}),
}

matchersForAllFieldsSet = []capitest.JSONPatchMatcher{
Expand Down Expand Up @@ -118,6 +122,14 @@ var (
),
),
},
{
Operation: "add",
Path: "/spec/template/spec/project",
ValueMatcher: gomega.SatisfyAll(
gomega.HaveKeyWithValue("type", "name"),
gomega.HaveKeyWithValue("name", "fake-project"),
),
},
}
)

Expand Down
Loading
Loading