Skip to content

Commit f529289

Browse files
committed
feat: support setting Nutanix project on machines
1 parent c33c2d0 commit f529289

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

api/v1alpha1/nutanix_node_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ type NutanixMachineDetails struct {
6262
// systemDiskSize is size (in Quantity format) of the system disk of the VM
6363
// The minimum systemDiskSize is 20Gi bytes
6464
SystemDiskSize resource.Quantity `json:"systemDiskSize"`
65+
66+
// add the virtual machines to the project defined in Prism Central.
67+
// The project must already be present in the Prism Central.
68+
// +optional
69+
Project *NutanixResourceIdentifier `json:"project,omitempty"`
6570
}
6671

6772
func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
@@ -112,6 +117,10 @@ func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
112117
Description: "systemDiskSize is size (in Quantity format) of the system disk of the VM eg. 20Gi",
113118
Type: "string",
114119
},
120+
"project": NutanixResourceIdentifier{}.VariableSchemaFromDescription(
121+
//nolint:lll // Long description.
122+
"add the virtual machines to the project defined in Prism Central. The project must already be present in the Prism Central.",
123+
).OpenAPIV3Schema,
115124
},
116125
Required: []string{
117126
"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
@@ -78,6 +84,9 @@ spec:
7884
name: os-image-name
7985
type: name
8086
memorySize: 4Gi
87+
project:
88+
type: name
89+
name: project-name
8190
providerID: nutanix://vm-uuid
8291
subnet:
8392
- name: subnet-name
@@ -108,6 +117,9 @@ spec:
108117
name: os-image-name
109118
type: name
110119
memorySize: 4Gi
120+
project:
121+
type: name
122+
name: project-name
111123
providerID: nutanix://vm-uuid
112124
subnet:
113125
- name: subnet-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"
@@ -116,6 +117,10 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate(
116117
spec.AdditionalCategories[i] = capxv1.NutanixCategoryIdentifier(category)
117118
}
118119

120+
if nutanixMachineDetailsVar.Project != nil {
121+
spec.Project = ptr.To(capxv1.NutanixResourceIdentifier(*nutanixMachineDetailsVar.Project))
122+
}
123+
119124
obj.Spec.Template.Spec = spec
120125
return nil
121126
},

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ var (
5151
Value: "fake-value2",
5252
},
5353
},
54+
Project: ptr.To(v1alpha1.NutanixResourceIdentifier{
55+
Type: capxv1.NutanixIdentifierName,
56+
Name: ptr.To("fake-project"),
57+
}),
5458
}
5559

5660
matchersForAllFieldsSet = []capitest.JSONPatchMatcher{
@@ -118,6 +122,14 @@ var (
118122
),
119123
),
120124
},
125+
{
126+
Operation: "add",
127+
Path: "/spec/template/spec/project",
128+
ValueMatcher: gomega.SatisfyAll(
129+
gomega.HaveKeyWithValue("type", "name"),
130+
gomega.HaveKeyWithValue("name", "fake-project"),
131+
),
132+
},
121133
}
122134
)
123135

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
AdditionalCategories: []v1alpha1.NutanixCategoryIdentifier{

0 commit comments

Comments
 (0)