Skip to content

Commit 053677f

Browse files
committed
feat: support setting Nutanix project on machines
1 parent 9aecf48 commit 053677f

File tree

7 files changed

+50
-0
lines changed

7 files changed

+50
-0
lines changed

api/v1alpha1/nutanix_node_types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ type NutanixMachineDetails struct {
5757
// systemDiskSize is size (in Quantity format) of the system disk of the VM
5858
// The minimum systemDiskSize is 20Gi bytes
5959
SystemDiskSize resource.Quantity `json:"systemDiskSize"`
60+
61+
// a Prism Central project where to add the resources
62+
// +optional
63+
Project *NutanixResourceIdentifier `json:"project,omitempty"`
6064
}
6165

6266
func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
@@ -101,6 +105,10 @@ func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
101105
Description: "systemDiskSize is size (in Quantity format) of the system disk of the VM eg. 20Gi",
102106
Type: "string",
103107
},
108+
"project": NutanixResourceIdentifier{}.VariableSchemaFromDescription(
109+
//nolint:lll // Long description.
110+
"a Prism Central project where to add the resources",
111+
).OpenAPIV3Schema,
104112
},
105113
Required: []string{
106114
"vcpusPerSocket",

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ spec:
2929
name: os-image-name
3030
type: name
3131
memorySize: 4Gi
32+
project:
33+
type: name
34+
name: project-name
3235
subnets:
3336
- name: subnet-name
3437
type: name
@@ -47,6 +50,9 @@ spec:
4750
name: os-image-name
4851
type: name
4952
memorySize: 4Gi
53+
project:
54+
type: name
55+
name: project-name
5056
subnets:
5157
- name: subnet-name
5258
type: name
@@ -75,6 +81,9 @@ spec:
7581
name: os-image-name
7682
type: name
7783
memorySize: 4Gi
84+
project:
85+
type: name
86+
name: project-name
7887
providerID: nutanix://vm-uuid
7988
subnet:
8089
- name: subnet-name
@@ -102,6 +111,9 @@ spec:
102111
name: os-image-name
103112
type: name
104113
memorySize: 4Gi
114+
project:
115+
type: name
116+
name: project-name
105117
providerID: nutanix://vm-uuid
106118
subnet:
107119
- name: subnet-name

examples/capi-quick-start/nutanix-cluster-cilium-helm-addon.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ spec:
129129
name: ${NUTANIX_MACHINE_TEMPLATE_IMAGE_NAME}
130130
type: name
131131
memorySize: 4Gi
132+
project:
133+
type: name
134+
name: ${NUTANIX_PROJECT_NAME}
132135
subnets:
133136
- name: ${NUTANIX_SUBNET_NAME}
134137
type: name

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1010
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
11+
"k8s.io/utils/ptr"
1112
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
1213
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1314
ctrl "sigs.k8s.io/controller-runtime"
@@ -108,6 +109,10 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate(
108109
spec.Subnets[i] = capxv1.NutanixResourceIdentifier(subnet)
109110
}
110111

112+
if nutanixMachineDetailsVar.Project != nil {
113+
spec.Project = ptr.To(capxv1.NutanixResourceIdentifier(*nutanixMachineDetailsVar.Project))
114+
}
115+
111116
obj.Spec.Template.Spec = spec
112117
return nil
113118
},

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ var (
4141
Name: ptr.To("fake-subnet"),
4242
},
4343
},
44+
Project: ptr.To(v1alpha1.NutanixResourceIdentifier{
45+
Type: capxv1.NutanixIdentifierName,
46+
Name: ptr.To("fake-project"),
47+
}),
4448
}
4549

4650
matchersForAllFieldsSet = []capitest.JSONPatchMatcher{
@@ -94,6 +98,14 @@ var (
9498
Path: "/spec/template/spec/subnet",
9599
ValueMatcher: gomega.HaveLen(1),
96100
},
101+
{
102+
Operation: "add",
103+
Path: "/spec/template/spec/project",
104+
ValueMatcher: gomega.SatisfyAll(
105+
gomega.HaveKeyWithValue("type", "name"),
106+
gomega.HaveKeyWithValue("name", "fake-project"),
107+
),
108+
},
97109
}
98110
)
99111

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import (
1919
func TestVariableValidation(t *testing.T) {
2020
testImageName := "fake-image"
2121
testPEClusterName := "fake-pe-cluster"
22+
testProject := ptr.To(v1alpha1.NutanixResourceIdentifier{
23+
Type: capxv1.NutanixIdentifierName,
24+
Name: ptr.To("fake-project"),
25+
})
2226
capitest.ValidateDiscoverVariables(
2327
t,
2428
clusterconfig.MetaVariableName,
@@ -43,6 +47,7 @@ func TestVariableValidation(t *testing.T) {
4347
Name: &testPEClusterName,
4448
},
4549
MemorySize: resource.MustParse("8Gi"),
50+
Project: testProject,
4651
SystemDiskSize: resource.MustParse("40Gi"),
4752
Subnets: []v1alpha1.NutanixResourceIdentifier{},
4853
},

0 commit comments

Comments
 (0)