Skip to content

Commit c33c2d0

Browse files
authored
feat: Add additionalCategories field to Nutanix machine details patch (#525)
Adds the `additionalCategories` field to the Nutanix machine details patch. Fixes https://jira.nutanix.com/browse/D2IQ-100464
1 parent 8d3091e commit c33c2d0

File tree

6 files changed

+103
-0
lines changed

6 files changed

+103
-0
lines changed

api/v1alpha1/nutanix_node_types.go

+32
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ type NutanixMachineDetails struct {
5151
// The identifier (uuid or name) can be obtained from the console or API.
5252
Subnets []NutanixResourceIdentifier `json:"subnets"`
5353

54+
// List of categories that need to be added to the machines. Categories must already
55+
// exist in Prism Central. One category key can have more than one value.
56+
// +optional
57+
AdditionalCategories []NutanixCategoryIdentifier `json:"additionalCategories,omitempty"`
58+
5459
// Defines the boot type of the virtual machine. Only supports UEFI and Legacy
5560
BootType NutanixBootType `json:"bootType,omitempty"`
5661

@@ -93,6 +98,12 @@ func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
9398
"subnet identifies the network subnet to use for the machine. The identifier (uuid or name) can be obtained from the console or API.",
9499
).OpenAPIV3Schema),
95100
},
101+
"additionalCategories": {
102+
Type: "array",
103+
//nolint:lll // Description is long.
104+
Description: "List of categories that need to be added to the machines. Categories must already exist in Prism Central. One category key can have more than one value.",
105+
Items: ptr.To(NutanixCategoryIdentifier{}.VariableSchema().OpenAPIV3Schema),
106+
},
96107
"bootType": NutanixBootType(
97108
capxv1.NutanixBootTypeLegacy,
98109
).VariableSchema().
@@ -173,3 +184,24 @@ func (NutanixResourceIdentifier) VariableSchemaFromDescription(
173184
},
174185
}
175186
}
187+
188+
type NutanixCategoryIdentifier capxv1.NutanixCategoryIdentifier
189+
190+
func (NutanixCategoryIdentifier) VariableSchema() clusterv1.VariableSchema {
191+
return clusterv1.VariableSchema{
192+
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
193+
Description: "Nutanix Category Identifier",
194+
Type: "object",
195+
Properties: map[string]clusterv1.JSONSchemaProps{
196+
"key": {
197+
Type: "string",
198+
Description: "key is the Key of category in PC.",
199+
},
200+
"value": {
201+
Type: "string",
202+
Description: "value is the category value linked to the category key in PC.",
203+
},
204+
},
205+
},
206+
}
207+
}

api/v1alpha1/zz_generated.deepcopy.go

+20
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

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ spec:
5050
subnets:
5151
- name: subnet-name
5252
type: name
53+
additionalCategories:
54+
- key: example-key
55+
value: example-value
5356
systemDiskSize: 40Gi
5457
vcpuSockets: 2
5558
vcpusPerSocket: 1
@@ -79,6 +82,9 @@ spec:
7982
subnet:
8083
- name: subnet-name
8184
type: name
85+
additionalCategories:
86+
- key: example-key
87+
value: example-value
8288
systemDiskSize: 40Gi
8389
vcpuSockets: 2
8490
vcpusPerSocket: 1
@@ -106,6 +112,9 @@ spec:
106112
subnet:
107113
- name: subnet-name
108114
type: name
115+
additionalCategories:
116+
- key: example-key
117+
value: example-value
109118
systemDiskSize: 40Gi
110119
vcpuSockets: 2
111120
vcpusPerSocket: 1

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

+8
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate(
108108
spec.Subnets[i] = capxv1.NutanixResourceIdentifier(subnet)
109109
}
110110

111+
spec.AdditionalCategories = make(
112+
[]capxv1.NutanixCategoryIdentifier,
113+
len(nutanixMachineDetailsVar.AdditionalCategories),
114+
)
115+
for i, category := range nutanixMachineDetailsVar.AdditionalCategories {
116+
spec.AdditionalCategories[i] = capxv1.NutanixCategoryIdentifier(category)
117+
}
118+
111119
obj.Spec.Template.Spec = spec
112120
return nil
113121
},

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

+24
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ var (
4141
Name: ptr.To("fake-subnet"),
4242
},
4343
},
44+
AdditionalCategories: []v1alpha1.NutanixCategoryIdentifier{
45+
{
46+
Key: "fake-key",
47+
Value: "fake-value",
48+
},
49+
{
50+
Key: "fake-key2",
51+
Value: "fake-value2",
52+
},
53+
},
4454
}
4555

4656
matchersForAllFieldsSet = []capitest.JSONPatchMatcher{
@@ -94,6 +104,20 @@ var (
94104
Path: "/spec/template/spec/subnet",
95105
ValueMatcher: gomega.HaveLen(1),
96106
},
107+
{
108+
Operation: "add",
109+
Path: "/spec/template/spec/additionalCategories",
110+
ValueMatcher: gomega.ContainElements(
111+
gomega.SatisfyAll(
112+
gomega.HaveKeyWithValue("key", "fake-key"),
113+
gomega.HaveKeyWithValue("value", "fake-value"),
114+
),
115+
gomega.SatisfyAll(
116+
gomega.HaveKeyWithValue("key", "fake-key2"),
117+
gomega.HaveKeyWithValue("value", "fake-value2"),
118+
),
119+
),
120+
},
97121
}
98122
)
99123

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

+10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ func TestVariableValidation(t *testing.T) {
4545
MemorySize: resource.MustParse("8Gi"),
4646
SystemDiskSize: resource.MustParse("40Gi"),
4747
Subnets: []v1alpha1.NutanixResourceIdentifier{},
48+
AdditionalCategories: []v1alpha1.NutanixCategoryIdentifier{
49+
{
50+
Key: "fake-key",
51+
Value: "fake-value1",
52+
},
53+
{
54+
Key: "fake-key",
55+
Value: "fake-value2",
56+
},
57+
},
4858
},
4959
},
5060
},

0 commit comments

Comments
 (0)