From 767aef48f3656fd225b010afb7ae0b7691830558 Mon Sep 17 00:00:00 2001 From: Sid Shukla Date: Fri, 5 Apr 2024 11:12:02 +0200 Subject: [PATCH] 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. --- templates/cluster-template-clusterclass.yaml | 40 +++++++++---- templates/cluster-template-topology.yaml | 8 ++- templates/clusterclass/clusterclass.yaml | 40 +++++++++---- templates/template_test.go | 39 ++++++++++++ .../cluster-with-additional-categories.yaml | 8 ++- .../cluster-with-control-plane-endpoint.yaml | 8 ++- .../testdata/cluster-with-failure-domain.yaml | 8 ++- templates/testdata/cluster-with-gpu.yaml | 8 ++- .../testdata/cluster-with-project-name.yaml | 8 ++- .../testdata/cluster-with-project-uuid.yaml | 8 ++- templates/testdata/cluster-with-subnets.yaml | 60 +++++++++++++++++++ templates/topology/cluster-with-topology.yaml | 8 ++- 12 files changed, 207 insertions(+), 36 deletions(-) create mode 100644 templates/testdata/cluster-with-subnets.yaml diff --git a/templates/cluster-template-clusterclass.yaml b/templates/cluster-template-clusterclass.yaml index c42760244d..d5d4909022 100644 --- a/templates/cluster-template-clusterclass.yaml +++ b/templates/cluster-template-clusterclass.yaml @@ -175,9 +175,7 @@ spec: - op: add path: /spec/template/spec/subnet valueFrom: - template: | - - type: name - name: {{ .controlPlaneMachineDetails.subnetName }} + variable: controlPlaneMachineDetails.subnets selector: apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: NutanixMachineTemplate @@ -239,9 +237,7 @@ spec: - op: add path: /spec/template/spec/subnet valueFrom: - template: | - - type: name - name: {{ .controlPlaneMachineDetails.subnetName }} + variable: workerMachineDetails.subnets selector: apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 kind: NutanixMachineTemplate @@ -397,8 +393,20 @@ spec: type: string memorySize: type: string - subnetName: - type: string + subnets: + items: + properties: + name: + type: string + type: + enum: + - name + - uuid + type: string + uuid: + type: string + type: object + type: array systemDiskSize: type: string vcpuSockets: @@ -440,8 +448,20 @@ spec: type: string memorySize: type: string - subnetName: - type: string + subnets: + items: + properties: + name: + type: string + type: + enum: + - name + - uuid + type: string + uuid: + type: string + type: object + type: array systemDiskSize: type: string vcpuSockets: diff --git a/templates/cluster-template-topology.yaml b/templates/cluster-template-topology.yaml index 8d6de08e1a..116ac7f34d 100644 --- a/templates/cluster-template-topology.yaml +++ b/templates/cluster-template-topology.yaml @@ -326,7 +326,9 @@ spec: clusterName: ${NUTANIX_PRISM_ELEMENT_CLUSTER_NAME} imageName: ${NUTANIX_MACHINE_TEMPLATE_IMAGE_NAME} memorySize: ${NUTANIX_MACHINE_MEMORY_SIZE=4Gi} - subnetName: ${NUTANIX_SUBNET_NAME} + subnets: + - name: ${NUTANIX_SUBNET_NAME} + type: name systemDiskSize: ${NUTANIX_SYSTEMDISK_SIZE=40Gi} vcpuSockets: ${NUTANIX_MACHINE_VCPU_SOCKET=2} vcpusPerSocket: ${NUTANIX_MACHINE_VCPU_PER_SOCKET=1} @@ -336,7 +338,9 @@ spec: clusterName: ${NUTANIX_PRISM_ELEMENT_CLUSTER_NAME} imageName: ${NUTANIX_MACHINE_TEMPLATE_IMAGE_NAME} memorySize: ${NUTANIX_MACHINE_MEMORY_SIZE=4Gi} - subnetName: ${NUTANIX_SUBNET_NAME} + subnets: + - name: ${NUTANIX_SUBNET_NAME} + type: name systemDiskSize: ${NUTANIX_SYSTEMDISK_SIZE=40Gi} vcpuSockets: ${NUTANIX_MACHINE_VCPU_SOCKET=2} vcpusPerSocket: ${NUTANIX_MACHINE_VCPU_PER_SOCKET=1} diff --git a/templates/clusterclass/clusterclass.yaml b/templates/clusterclass/clusterclass.yaml index 2d3493cf06..cfe9dc6667 100644 --- a/templates/clusterclass/clusterclass.yaml +++ b/templates/clusterclass/clusterclass.yaml @@ -197,9 +197,7 @@ spec: - op: add path: /spec/template/spec/subnet valueFrom: - template: | - - type: name - name: {{ .controlPlaneMachineDetails.subnetName }} + variable: controlPlaneMachineDetails.subnets - name: update-control-plane-machine-template-gpus enabledIf: "{{if .controlPlaneMachineDetails.gpus}}true{{end}}" definitions: @@ -263,9 +261,7 @@ spec: - op: add path: /spec/template/spec/subnet valueFrom: - template: | - - type: name - name: {{ .controlPlaneMachineDetails.subnetName }} + variable: workerMachineDetails.subnets - name: update-worker-machine-template-gpus enabledIf: "{{if .workerMachineDetails.gpus}}true{{end}}" definitions: @@ -399,8 +395,20 @@ spec: type: string clusterName: type: string - subnetName: - type: string + subnets: + type: array + items: + type: object + properties: + name: + type: string + uuid: + type: string + type: + type: string + enum: + - name + - uuid gpus: type: array items: @@ -442,8 +450,20 @@ spec: type: string clusterName: type: string - subnetName: - type: string + subnets: + type: array + items: + type: object + properties: + name: + type: string + uuid: + type: string + type: + type: string + enum: + - name + - uuid gpus: type: array items: diff --git a/templates/template_test.go b/templates/template_test.go index 4b22f478a6..71602bc7c5 100644 --- a/templates/template_test.go +++ b/templates/template_test.go @@ -440,4 +440,43 @@ var _ = Describe("Cluster Class Template Patches Test Suite", Ordered, func() { )) }) }) + + Describe("patches for subnets", func() { + It("should have correct subnets", func() { + clusterManifest := "testdata/cluster-with-subnets.yaml" + obj, err := getClusterManifest(clusterManifest) + Expect(err).NotTo(HaveOccurred()) + + err = clnt.Create(context.Background(), obj) // Create the cluster + Expect(err).NotTo(HaveOccurred()) + + Eventually(func() (*v1beta1.NutanixMachineTemplate, error) { + return fetchControlPlaneMachineTemplate(clnt, obj.GetName()) + }).Within(time.Minute).Should(And(HaveExistingField("Spec.Template.Spec.Subnets"), + HaveField("Spec.Template.Spec.Subnets", HaveLen(2)), + HaveField("Spec.Template.Spec.Subnets", ContainElement(v1beta1.NutanixResourceIdentifier{ + Type: v1beta1.NutanixIdentifierName, + Name: ptr.To("shared-subnet"), + })), + HaveField("Spec.Template.Spec.Subnets", ContainElement(v1beta1.NutanixResourceIdentifier{ + Type: v1beta1.NutanixIdentifierName, + Name: ptr.To("controlplane-subnet"), + })))) + + Eventually(func() ([]*v1beta1.NutanixMachineTemplate, error) { + return fetchWorkerMachineTemplates(clnt, obj.GetName()) + }).Within(time.Minute).Should(And(HaveLen(1), + HaveEach(HaveExistingField("Spec.Template.Spec.Subnets")), + HaveEach(HaveField("Spec.Template.Spec.Subnets", HaveLen(2))), + HaveEach(HaveField("Spec.Template.Spec.Subnets", ContainElement(v1beta1.NutanixResourceIdentifier{ + Type: v1beta1.NutanixIdentifierName, + Name: ptr.To("shared-subnet"), + }))), + HaveEach(HaveField("Spec.Template.Spec.Subnets", ContainElement(v1beta1.NutanixResourceIdentifier{ + Type: v1beta1.NutanixIdentifierName, + Name: ptr.To("worker-subnet"), + }))), + )) + }) + }) }) diff --git a/templates/testdata/cluster-with-additional-categories.yaml b/templates/testdata/cluster-with-additional-categories.yaml index a7c3ebee1f..4e939a9273 100644 --- a/templates/testdata/cluster-with-additional-categories.yaml +++ b/templates/testdata/cluster-with-additional-categories.yaml @@ -30,7 +30,9 @@ spec: clusterName: fake-cluster imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 @@ -43,7 +45,9 @@ spec: clusterName: fake-cluster imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 diff --git a/templates/testdata/cluster-with-control-plane-endpoint.yaml b/templates/testdata/cluster-with-control-plane-endpoint.yaml index 9387de775a..886fe8735d 100644 --- a/templates/testdata/cluster-with-control-plane-endpoint.yaml +++ b/templates/testdata/cluster-with-control-plane-endpoint.yaml @@ -30,7 +30,9 @@ spec: clusterName: fake-cluster imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 @@ -40,7 +42,9 @@ spec: clusterName: fake-cluster imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 diff --git a/templates/testdata/cluster-with-failure-domain.yaml b/templates/testdata/cluster-with-failure-domain.yaml index a2e7ab2de4..9e8409590d 100644 --- a/templates/testdata/cluster-with-failure-domain.yaml +++ b/templates/testdata/cluster-with-failure-domain.yaml @@ -31,7 +31,9 @@ spec: clusterName: fake imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 @@ -41,7 +43,9 @@ spec: clusterName: fake imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 diff --git a/templates/testdata/cluster-with-gpu.yaml b/templates/testdata/cluster-with-gpu.yaml index 741dab7635..560e96d153 100644 --- a/templates/testdata/cluster-with-gpu.yaml +++ b/templates/testdata/cluster-with-gpu.yaml @@ -30,7 +30,9 @@ spec: clusterName: fake-cluster imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 @@ -43,7 +45,9 @@ spec: clusterName: fake-cluster imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 diff --git a/templates/testdata/cluster-with-project-name.yaml b/templates/testdata/cluster-with-project-name.yaml index 00049cc40a..96d8d7112f 100644 --- a/templates/testdata/cluster-with-project-name.yaml +++ b/templates/testdata/cluster-with-project-name.yaml @@ -30,7 +30,9 @@ spec: clusterName: fake-cluster imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 @@ -40,7 +42,9 @@ spec: clusterName: fake-cluster imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 diff --git a/templates/testdata/cluster-with-project-uuid.yaml b/templates/testdata/cluster-with-project-uuid.yaml index a4a22ccd83..b4d8c0119b 100644 --- a/templates/testdata/cluster-with-project-uuid.yaml +++ b/templates/testdata/cluster-with-project-uuid.yaml @@ -30,7 +30,9 @@ spec: clusterName: fake-cluster imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 @@ -40,7 +42,9 @@ spec: clusterName: fake-cluster imageName: ubuntu-2204-kube-v1.29.2.qcow2 memorySize: 4Gi - subnetName: fake-subnet + subnets: + - type: name + name: fake-subnet systemDiskSize: 40Gi vcpuSockets: 2 vcpusPerSocket: 1 diff --git a/templates/testdata/cluster-with-subnets.yaml b/templates/testdata/cluster-with-subnets.yaml new file mode 100644 index 0000000000..9f49e57729 --- /dev/null +++ b/templates/testdata/cluster-with-subnets.yaml @@ -0,0 +1,60 @@ +apiVersion: cluster.x-k8s.io/v1beta1 +kind: Cluster +metadata: + labels: + ccm: nutanix + cluster.x-k8s.io/cluster-name: cluster-with-subnets + name: cluster-with-subnets +spec: + topology: + class: nutanix-quick-start + controlPlane: + metadata: {} + replicas: 1 + variables: + - name: sshKey + value: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMe61GqA9gqeX3zDCiwuU8zEDt3ckLnfVm8ZxN7UuFyL user@host + - name: controlPlaneEndpoint + value: + IP: 1.2.3.4 + port: 6443 + - name: prismCentralEndpoint + value: + address: prismcentral.fake + credentialSecret: nutanix-quick-start-pc-creds + insecure: false + port: 9440 + - name: controlPlaneMachineDetails + value: + bootType: legacy + clusterName: fake-cluster + imageName: ubuntu-2204-kube-v1.29.2.qcow2 + memorySize: 4Gi + subnets: + - type: name + name: shared-subnet + - type: name + name: controlplane-subnet + systemDiskSize: 40Gi + vcpuSockets: 2 + vcpusPerSocket: 1 + - name: workerMachineDetails + value: + bootType: legacy + clusterName: fake-cluster + imageName: ubuntu-2204-kube-v1.29.2.qcow2 + memorySize: 4Gi + subnets: + - type: name + name: shared-subnet + - type: name + name: worker-subnet + systemDiskSize: 40Gi + vcpuSockets: 2 + vcpusPerSocket: 1 + version: v1.29.2 + workers: + machineDeployments: + - class: nutanix-quick-start-worker + name: md-0 + replicas: 2 diff --git a/templates/topology/cluster-with-topology.yaml b/templates/topology/cluster-with-topology.yaml index c8388429bc..a26d093dec 100644 --- a/templates/topology/cluster-with-topology.yaml +++ b/templates/topology/cluster-with-topology.yaml @@ -46,7 +46,9 @@ spec: systemDiskSize: "${NUTANIX_SYSTEMDISK_SIZE=40Gi}" imageName: "${NUTANIX_MACHINE_TEMPLATE_IMAGE_NAME}" clusterName: "${NUTANIX_PRISM_ELEMENT_CLUSTER_NAME}" - subnetName: "${NUTANIX_SUBNET_NAME}" + subnets: + - type: name + name: "${NUTANIX_SUBNET_NAME}" - name: workerMachineDetails value: bootType: ${NUTANIX_MACHINE_BOOT_TYPE=legacy} @@ -56,4 +58,6 @@ spec: systemDiskSize: "${NUTANIX_SYSTEMDISK_SIZE=40Gi}" imageName: "${NUTANIX_MACHINE_TEMPLATE_IMAGE_NAME}" clusterName: "${NUTANIX_PRISM_ELEMENT_CLUSTER_NAME}" - subnetName: "${NUTANIX_SUBNET_NAME}" + subnets: + - type: name + name: "${NUTANIX_SUBNET_NAME}"