Skip to content

Commit 1d22fb9

Browse files
Add variable for setting the additional categories on cluster (#396)
The diff also includes a patch to set the additional categories on nutanixmachinetemplate resources for control plane and worker machine deployments.
1 parent 4a18e44 commit 1d22fb9

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed

templates/cluster-template-clusterclass.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,31 @@ spec:
272272
- nutanix-quick-start-worker
273273
enabledIf: '{{if .project}}true{{end}}'
274274
name: add-project
275+
- definitions:
276+
- jsonPatches:
277+
- op: add
278+
path: /spec/template/spec/additionalCategories
279+
valueFrom:
280+
variable: additionalCategories
281+
selector:
282+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
283+
kind: NutanixMachineTemplate
284+
matchResources:
285+
controlPlane: true
286+
- jsonPatches:
287+
- op: add
288+
path: /spec/template/spec/additionalCategories
289+
valueFrom:
290+
variable: additionalCategories
291+
selector:
292+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
293+
kind: NutanixMachineTemplate
294+
matchResources:
295+
machineDeploymentClass:
296+
names:
297+
- nutanix-quick-start-worker
298+
enabledIf: '{{if .additionalCategories}}true{{end}}'
299+
name: add-additional-categories
275300
variables:
276301
- name: sshKey
277302
required: true
@@ -403,6 +428,18 @@ spec:
403428
uuid:
404429
type: string
405430
type: object
431+
- name: additionalCategories
432+
required: false
433+
schema:
434+
openAPIV3Schema:
435+
items:
436+
properties:
437+
key:
438+
type: string
439+
value:
440+
type: string
441+
type: object
442+
type: array
406443
workers:
407444
machineDeployments:
408445
- class: nutanix-quick-start-worker

templates/clusterclass/clusterclass.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,31 @@ spec:
288288
path: /spec/template/spec/project
289289
valueFrom:
290290
variable: project
291+
- name: add-additional-categories
292+
enabledIf: "{{if .additionalCategories}}true{{end}}"
293+
definitions:
294+
- selector:
295+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
296+
kind: NutanixMachineTemplate
297+
matchResources:
298+
controlPlane: true
299+
jsonPatches:
300+
- op: add
301+
path: /spec/template/spec/additionalCategories
302+
valueFrom:
303+
variable: additionalCategories
304+
- selector:
305+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
306+
kind: NutanixMachineTemplate
307+
matchResources:
308+
machineDeploymentClass:
309+
names:
310+
- nutanix-quick-start-worker
311+
jsonPatches:
312+
- op: add
313+
path: /spec/template/spec/additionalCategories
314+
valueFrom:
315+
variable: additionalCategories
291316
variables:
292317
- name: sshKey
293318
required: true
@@ -419,3 +444,15 @@ spec:
419444
enum:
420445
- name
421446
- uuid
447+
- name: additionalCategories
448+
required: false
449+
schema:
450+
openAPIV3Schema:
451+
type: array
452+
items:
453+
type: object
454+
properties:
455+
key:
456+
type: string
457+
value:
458+
type: string

templates/template_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,4 +374,30 @@ var _ = Describe("Cluster Class Template Patches Test Suite", Ordered, func() {
374374
HaveEach(HaveField("Spec.Template.Spec.Project.Name", HaveValue(Equal("00000000-0000-0000-0000-000000000001"))))))
375375
})
376376
})
377+
378+
Describe("patches for additional categories", func() {
379+
It("should have correct categories", func() {
380+
clusterManifest := "testdata/cluster-with-additional-categories.yaml"
381+
obj, err := getClusterManifest(clusterManifest)
382+
Expect(err).NotTo(HaveOccurred())
383+
384+
err = clnt.Create(context.Background(), obj) // Create the cluster
385+
Expect(err).NotTo(HaveOccurred())
386+
387+
Eventually(func() error {
388+
_, err = fetchNutanixCluster(clnt, obj.GetName())
389+
return err
390+
}).Within(time.Minute).Should(Succeed())
391+
392+
Eventually(func() ([]*v1beta1.NutanixMachineTemplate, error) {
393+
return fetchMachineTemplates(clnt, obj.GetName())
394+
}).Within(time.Minute).Should(And(HaveLen(2),
395+
HaveEach(HaveExistingField("Spec.Template.Spec.AdditionalCategories")),
396+
HaveEach(HaveField("Spec.Template.Spec.AdditionalCategories", HaveLen(1))),
397+
HaveEach(HaveField("Spec.Template.Spec.AdditionalCategories", ContainElement(v1beta1.NutanixCategoryIdentifier{
398+
Key: "fake-category-key",
399+
Value: "fake-category-value",
400+
})))))
401+
})
402+
})
377403
})
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
apiVersion: cluster.x-k8s.io/v1beta1
2+
kind: Cluster
3+
metadata:
4+
labels:
5+
ccm: nutanix
6+
cluster.x-k8s.io/cluster-name: cluster-with-additional-categories
7+
name: cluster-with-additional-categories
8+
spec:
9+
topology:
10+
class: nutanix-quick-start
11+
controlPlane:
12+
metadata: {}
13+
replicas: 1
14+
variables:
15+
- name: sshKey
16+
value: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMe61GqA9gqeX3zDCiwuU8zEDt3ckLnfVm8ZxN7UuFyL user@host
17+
- name: controlPlaneEndpoint
18+
value:
19+
IP: 1.2.3.4
20+
port: 6443
21+
- name: prismCentralEndpoint
22+
value:
23+
address: prismcentral.fake
24+
credentialSecret: nutanix-quick-start-pc-creds
25+
insecure: false
26+
port: 9440
27+
- name: controlPlaneMachineDetails
28+
value:
29+
bootType: legacy
30+
clusterName: fake-cluster
31+
imageName: ubuntu-2204-kube-v1.29.2.qcow2
32+
memorySize: 4Gi
33+
subnetName: fake-subnet
34+
systemDiskSize: 40Gi
35+
vcpuSockets: 2
36+
vcpusPerSocket: 1
37+
- name: workerMachineDetails
38+
value:
39+
bootType: legacy
40+
clusterName: fake-cluster
41+
imageName: ubuntu-2204-kube-v1.29.2.qcow2
42+
memorySize: 4Gi
43+
subnetName: fake-subnet
44+
systemDiskSize: 40Gi
45+
vcpuSockets: 2
46+
vcpusPerSocket: 1
47+
- name: additionalCategories
48+
value:
49+
- key: fake-category-key
50+
value: fake-category-value
51+
version: v1.29.2
52+
workers:
53+
machineDeployments:
54+
- class: nutanix-quick-start-worker
55+
name: md-0
56+
replicas: 2

0 commit comments

Comments
 (0)