Skip to content

feat: Add additionalCategories field to Nutanix machine details patch #525

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
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
32 changes: 32 additions & 0 deletions api/v1alpha1/nutanix_node_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ type NutanixMachineDetails struct {
// The identifier (uuid or name) can be obtained from the console or API.
Subnets []NutanixResourceIdentifier `json:"subnets"`

// 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.
// +optional
AdditionalCategories []NutanixCategoryIdentifier `json:"additionalCategories,omitempty"`

// Defines the boot type of the virtual machine. Only supports UEFI and Legacy
BootType NutanixBootType `json:"bootType,omitempty"`

Expand Down Expand Up @@ -93,6 +98,12 @@ func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema {
"subnet identifies the network subnet to use for the machine. The identifier (uuid or name) can be obtained from the console or API.",
).OpenAPIV3Schema),
},
"additionalCategories": {
Type: "array",
//nolint:lll // Description is long.
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.",
Items: ptr.To(NutanixCategoryIdentifier{}.VariableSchema().OpenAPIV3Schema),
},
"bootType": NutanixBootType(
capxv1.NutanixBootTypeLegacy,
).VariableSchema().
Expand Down Expand Up @@ -173,3 +184,24 @@ func (NutanixResourceIdentifier) VariableSchemaFromDescription(
},
}
}

type NutanixCategoryIdentifier capxv1.NutanixCategoryIdentifier

func (NutanixCategoryIdentifier) VariableSchema() clusterv1.VariableSchema {
return clusterv1.VariableSchema{
OpenAPIV3Schema: clusterv1.JSONSchemaProps{
Description: "Nutanix Category Identifier",
Type: "object",
Properties: map[string]clusterv1.JSONSchemaProps{
"key": {
Type: "string",
Description: "key is the Key of category in PC.",
},
"value": {
Type: "string",
Description: "value is the category value linked to the category key in PC.",
},
},
},
}
}
20 changes: 20 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.

9 changes: 9 additions & 0 deletions docs/content/customization/nutanix/machine-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ spec:
subnets:
- name: subnet-name
type: name
additionalCategories:
- key: example-key
value: example-value
systemDiskSize: 40Gi
vcpuSockets: 2
vcpusPerSocket: 1
Expand Down Expand Up @@ -79,6 +82,9 @@ spec:
subnet:
- name: subnet-name
type: name
additionalCategories:
- key: example-key
value: example-value
systemDiskSize: 40Gi
vcpuSockets: 2
vcpusPerSocket: 1
Expand Down Expand Up @@ -106,6 +112,9 @@ spec:
subnet:
- name: subnet-name
type: name
additionalCategories:
- key: example-key
value: example-value
systemDiskSize: 40Gi
vcpuSockets: 2
vcpusPerSocket: 1
Expand Down
8 changes: 8 additions & 0 deletions pkg/handlers/nutanix/mutation/machinedetails/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ func (h *nutanixMachineDetailsPatchHandler) Mutate(
spec.Subnets[i] = capxv1.NutanixResourceIdentifier(subnet)
}

spec.AdditionalCategories = make(
[]capxv1.NutanixCategoryIdentifier,
len(nutanixMachineDetailsVar.AdditionalCategories),
)
for i, category := range nutanixMachineDetailsVar.AdditionalCategories {
spec.AdditionalCategories[i] = capxv1.NutanixCategoryIdentifier(category)
}

obj.Spec.Template.Spec = spec
return nil
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ var (
Name: ptr.To("fake-subnet"),
},
},
AdditionalCategories: []v1alpha1.NutanixCategoryIdentifier{
{
Key: "fake-key",
Value: "fake-value",
},
{
Key: "fake-key2",
Value: "fake-value2",
},
},
}

matchersForAllFieldsSet = []capitest.JSONPatchMatcher{
Expand Down Expand Up @@ -94,6 +104,20 @@ var (
Path: "/spec/template/spec/subnet",
ValueMatcher: gomega.HaveLen(1),
},
{
Operation: "add",
Path: "/spec/template/spec/additionalCategories",
ValueMatcher: gomega.ContainElements(
gomega.SatisfyAll(
gomega.HaveKeyWithValue("key", "fake-key"),
gomega.HaveKeyWithValue("value", "fake-value"),
),
gomega.SatisfyAll(
gomega.HaveKeyWithValue("key", "fake-key2"),
gomega.HaveKeyWithValue("value", "fake-value2"),
),
),
},
}
)

Expand Down
10 changes: 10 additions & 0 deletions pkg/handlers/nutanix/mutation/machinedetails/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ func TestVariableValidation(t *testing.T) {
MemorySize: resource.MustParse("8Gi"),
SystemDiskSize: resource.MustParse("40Gi"),
Subnets: []v1alpha1.NutanixResourceIdentifier{},
AdditionalCategories: []v1alpha1.NutanixCategoryIdentifier{
{
Key: "fake-key",
Value: "fake-value1",
},
{
Key: "fake-key",
Value: "fake-value2",
},
},
},
},
},
Expand Down
Loading