Skip to content

Commit 767aef4

Browse files
Fix the cardinality of subnet and source of subnet data (#405)
The cardinality of subnets in the clusterclass was incorrect and the source of subnet for worker machine deployment was incorrect. This changes the subnet cardinality from 1 to n and changes the source of subnets for worker machine deployments to workermachinedetails variable.
1 parent 5c2df1b commit 767aef4

12 files changed

+207
-36
lines changed

templates/cluster-template-clusterclass.yaml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ spec:
175175
- op: add
176176
path: /spec/template/spec/subnet
177177
valueFrom:
178-
template: |
179-
- type: name
180-
name: {{ .controlPlaneMachineDetails.subnetName }}
178+
variable: controlPlaneMachineDetails.subnets
181179
selector:
182180
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
183181
kind: NutanixMachineTemplate
@@ -239,9 +237,7 @@ spec:
239237
- op: add
240238
path: /spec/template/spec/subnet
241239
valueFrom:
242-
template: |
243-
- type: name
244-
name: {{ .controlPlaneMachineDetails.subnetName }}
240+
variable: workerMachineDetails.subnets
245241
selector:
246242
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
247243
kind: NutanixMachineTemplate
@@ -397,8 +393,20 @@ spec:
397393
type: string
398394
memorySize:
399395
type: string
400-
subnetName:
401-
type: string
396+
subnets:
397+
items:
398+
properties:
399+
name:
400+
type: string
401+
type:
402+
enum:
403+
- name
404+
- uuid
405+
type: string
406+
uuid:
407+
type: string
408+
type: object
409+
type: array
402410
systemDiskSize:
403411
type: string
404412
vcpuSockets:
@@ -440,8 +448,20 @@ spec:
440448
type: string
441449
memorySize:
442450
type: string
443-
subnetName:
444-
type: string
451+
subnets:
452+
items:
453+
properties:
454+
name:
455+
type: string
456+
type:
457+
enum:
458+
- name
459+
- uuid
460+
type: string
461+
uuid:
462+
type: string
463+
type: object
464+
type: array
445465
systemDiskSize:
446466
type: string
447467
vcpuSockets:

templates/cluster-template-topology.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ spec:
326326
clusterName: ${NUTANIX_PRISM_ELEMENT_CLUSTER_NAME}
327327
imageName: ${NUTANIX_MACHINE_TEMPLATE_IMAGE_NAME}
328328
memorySize: ${NUTANIX_MACHINE_MEMORY_SIZE=4Gi}
329-
subnetName: ${NUTANIX_SUBNET_NAME}
329+
subnets:
330+
- name: ${NUTANIX_SUBNET_NAME}
331+
type: name
330332
systemDiskSize: ${NUTANIX_SYSTEMDISK_SIZE=40Gi}
331333
vcpuSockets: ${NUTANIX_MACHINE_VCPU_SOCKET=2}
332334
vcpusPerSocket: ${NUTANIX_MACHINE_VCPU_PER_SOCKET=1}
@@ -336,7 +338,9 @@ spec:
336338
clusterName: ${NUTANIX_PRISM_ELEMENT_CLUSTER_NAME}
337339
imageName: ${NUTANIX_MACHINE_TEMPLATE_IMAGE_NAME}
338340
memorySize: ${NUTANIX_MACHINE_MEMORY_SIZE=4Gi}
339-
subnetName: ${NUTANIX_SUBNET_NAME}
341+
subnets:
342+
- name: ${NUTANIX_SUBNET_NAME}
343+
type: name
340344
systemDiskSize: ${NUTANIX_SYSTEMDISK_SIZE=40Gi}
341345
vcpuSockets: ${NUTANIX_MACHINE_VCPU_SOCKET=2}
342346
vcpusPerSocket: ${NUTANIX_MACHINE_VCPU_PER_SOCKET=1}

templates/clusterclass/clusterclass.yaml

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ spec:
197197
- op: add
198198
path: /spec/template/spec/subnet
199199
valueFrom:
200-
template: |
201-
- type: name
202-
name: {{ .controlPlaneMachineDetails.subnetName }}
200+
variable: controlPlaneMachineDetails.subnets
203201
- name: update-control-plane-machine-template-gpus
204202
enabledIf: "{{if .controlPlaneMachineDetails.gpus}}true{{end}}"
205203
definitions:
@@ -263,9 +261,7 @@ spec:
263261
- op: add
264262
path: /spec/template/spec/subnet
265263
valueFrom:
266-
template: |
267-
- type: name
268-
name: {{ .controlPlaneMachineDetails.subnetName }}
264+
variable: workerMachineDetails.subnets
269265
- name: update-worker-machine-template-gpus
270266
enabledIf: "{{if .workerMachineDetails.gpus}}true{{end}}"
271267
definitions:
@@ -399,8 +395,20 @@ spec:
399395
type: string
400396
clusterName:
401397
type: string
402-
subnetName:
403-
type: string
398+
subnets:
399+
type: array
400+
items:
401+
type: object
402+
properties:
403+
name:
404+
type: string
405+
uuid:
406+
type: string
407+
type:
408+
type: string
409+
enum:
410+
- name
411+
- uuid
404412
gpus:
405413
type: array
406414
items:
@@ -442,8 +450,20 @@ spec:
442450
type: string
443451
clusterName:
444452
type: string
445-
subnetName:
446-
type: string
453+
subnets:
454+
type: array
455+
items:
456+
type: object
457+
properties:
458+
name:
459+
type: string
460+
uuid:
461+
type: string
462+
type:
463+
type: string
464+
enum:
465+
- name
466+
- uuid
447467
gpus:
448468
type: array
449469
items:

templates/template_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,4 +440,43 @@ var _ = Describe("Cluster Class Template Patches Test Suite", Ordered, func() {
440440
))
441441
})
442442
})
443+
444+
Describe("patches for subnets", func() {
445+
It("should have correct subnets", func() {
446+
clusterManifest := "testdata/cluster-with-subnets.yaml"
447+
obj, err := getClusterManifest(clusterManifest)
448+
Expect(err).NotTo(HaveOccurred())
449+
450+
err = clnt.Create(context.Background(), obj) // Create the cluster
451+
Expect(err).NotTo(HaveOccurred())
452+
453+
Eventually(func() (*v1beta1.NutanixMachineTemplate, error) {
454+
return fetchControlPlaneMachineTemplate(clnt, obj.GetName())
455+
}).Within(time.Minute).Should(And(HaveExistingField("Spec.Template.Spec.Subnets"),
456+
HaveField("Spec.Template.Spec.Subnets", HaveLen(2)),
457+
HaveField("Spec.Template.Spec.Subnets", ContainElement(v1beta1.NutanixResourceIdentifier{
458+
Type: v1beta1.NutanixIdentifierName,
459+
Name: ptr.To("shared-subnet"),
460+
})),
461+
HaveField("Spec.Template.Spec.Subnets", ContainElement(v1beta1.NutanixResourceIdentifier{
462+
Type: v1beta1.NutanixIdentifierName,
463+
Name: ptr.To("controlplane-subnet"),
464+
}))))
465+
466+
Eventually(func() ([]*v1beta1.NutanixMachineTemplate, error) {
467+
return fetchWorkerMachineTemplates(clnt, obj.GetName())
468+
}).Within(time.Minute).Should(And(HaveLen(1),
469+
HaveEach(HaveExistingField("Spec.Template.Spec.Subnets")),
470+
HaveEach(HaveField("Spec.Template.Spec.Subnets", HaveLen(2))),
471+
HaveEach(HaveField("Spec.Template.Spec.Subnets", ContainElement(v1beta1.NutanixResourceIdentifier{
472+
Type: v1beta1.NutanixIdentifierName,
473+
Name: ptr.To("shared-subnet"),
474+
}))),
475+
HaveEach(HaveField("Spec.Template.Spec.Subnets", ContainElement(v1beta1.NutanixResourceIdentifier{
476+
Type: v1beta1.NutanixIdentifierName,
477+
Name: ptr.To("worker-subnet"),
478+
}))),
479+
))
480+
})
481+
})
443482
})

templates/testdata/cluster-with-additional-categories.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ spec:
3030
clusterName: fake-cluster
3131
imageName: ubuntu-2204-kube-v1.29.2.qcow2
3232
memorySize: 4Gi
33-
subnetName: fake-subnet
33+
subnets:
34+
- type: name
35+
name: fake-subnet
3436
systemDiskSize: 40Gi
3537
vcpuSockets: 2
3638
vcpusPerSocket: 1
@@ -43,7 +45,9 @@ spec:
4345
clusterName: fake-cluster
4446
imageName: ubuntu-2204-kube-v1.29.2.qcow2
4547
memorySize: 4Gi
46-
subnetName: fake-subnet
48+
subnets:
49+
- type: name
50+
name: fake-subnet
4751
systemDiskSize: 40Gi
4852
vcpuSockets: 2
4953
vcpusPerSocket: 1

templates/testdata/cluster-with-control-plane-endpoint.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ spec:
3030
clusterName: fake-cluster
3131
imageName: ubuntu-2204-kube-v1.29.2.qcow2
3232
memorySize: 4Gi
33-
subnetName: fake-subnet
33+
subnets:
34+
- type: name
35+
name: fake-subnet
3436
systemDiskSize: 40Gi
3537
vcpuSockets: 2
3638
vcpusPerSocket: 1
@@ -40,7 +42,9 @@ spec:
4042
clusterName: fake-cluster
4143
imageName: ubuntu-2204-kube-v1.29.2.qcow2
4244
memorySize: 4Gi
43-
subnetName: fake-subnet
45+
subnets:
46+
- type: name
47+
name: fake-subnet
4448
systemDiskSize: 40Gi
4549
vcpuSockets: 2
4650
vcpusPerSocket: 1

templates/testdata/cluster-with-failure-domain.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ spec:
3131
clusterName: fake
3232
imageName: ubuntu-2204-kube-v1.29.2.qcow2
3333
memorySize: 4Gi
34-
subnetName: fake-subnet
34+
subnets:
35+
- type: name
36+
name: fake-subnet
3537
systemDiskSize: 40Gi
3638
vcpuSockets: 2
3739
vcpusPerSocket: 1
@@ -41,7 +43,9 @@ spec:
4143
clusterName: fake
4244
imageName: ubuntu-2204-kube-v1.29.2.qcow2
4345
memorySize: 4Gi
44-
subnetName: fake-subnet
46+
subnets:
47+
- type: name
48+
name: fake-subnet
4549
systemDiskSize: 40Gi
4650
vcpuSockets: 2
4751
vcpusPerSocket: 1

templates/testdata/cluster-with-gpu.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ spec:
3030
clusterName: fake-cluster
3131
imageName: ubuntu-2204-kube-v1.29.2.qcow2
3232
memorySize: 4Gi
33-
subnetName: fake-subnet
33+
subnets:
34+
- type: name
35+
name: fake-subnet
3436
systemDiskSize: 40Gi
3537
vcpuSockets: 2
3638
vcpusPerSocket: 1
@@ -43,7 +45,9 @@ spec:
4345
clusterName: fake-cluster
4446
imageName: ubuntu-2204-kube-v1.29.2.qcow2
4547
memorySize: 4Gi
46-
subnetName: fake-subnet
48+
subnets:
49+
- type: name
50+
name: fake-subnet
4751
systemDiskSize: 40Gi
4852
vcpuSockets: 2
4953
vcpusPerSocket: 1

templates/testdata/cluster-with-project-name.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ spec:
3030
clusterName: fake-cluster
3131
imageName: ubuntu-2204-kube-v1.29.2.qcow2
3232
memorySize: 4Gi
33-
subnetName: fake-subnet
33+
subnets:
34+
- type: name
35+
name: fake-subnet
3436
systemDiskSize: 40Gi
3537
vcpuSockets: 2
3638
vcpusPerSocket: 1
@@ -40,7 +42,9 @@ spec:
4042
clusterName: fake-cluster
4143
imageName: ubuntu-2204-kube-v1.29.2.qcow2
4244
memorySize: 4Gi
43-
subnetName: fake-subnet
45+
subnets:
46+
- type: name
47+
name: fake-subnet
4448
systemDiskSize: 40Gi
4549
vcpuSockets: 2
4650
vcpusPerSocket: 1

templates/testdata/cluster-with-project-uuid.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ spec:
3030
clusterName: fake-cluster
3131
imageName: ubuntu-2204-kube-v1.29.2.qcow2
3232
memorySize: 4Gi
33-
subnetName: fake-subnet
33+
subnets:
34+
- type: name
35+
name: fake-subnet
3436
systemDiskSize: 40Gi
3537
vcpuSockets: 2
3638
vcpusPerSocket: 1
@@ -40,7 +42,9 @@ spec:
4042
clusterName: fake-cluster
4143
imageName: ubuntu-2204-kube-v1.29.2.qcow2
4244
memorySize: 4Gi
43-
subnetName: fake-subnet
45+
subnets:
46+
- type: name
47+
name: fake-subnet
4448
systemDiskSize: 40Gi
4549
vcpuSockets: 2
4650
vcpusPerSocket: 1

0 commit comments

Comments
 (0)