Skip to content

Commit

Permalink
Fix the cardinality of subnet and source of subnet data (#405)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thunderboltsid authored Apr 5, 2024
1 parent 5c2df1b commit 767aef4
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 36 deletions.
40 changes: 30 additions & 10 deletions templates/cluster-template-clusterclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions templates/cluster-template-topology.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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}
Expand Down
40 changes: 30 additions & 10 deletions templates/clusterclass/clusterclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
39 changes: 39 additions & 0 deletions templates/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}))),
))
})
})
})
8 changes: 6 additions & 2 deletions templates/testdata/cluster-with-additional-categories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions templates/testdata/cluster-with-control-plane-endpoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions templates/testdata/cluster-with-failure-domain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions templates/testdata/cluster-with-gpu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions templates/testdata/cluster-with-project-name.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions templates/testdata/cluster-with-project-uuid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
60 changes: 60 additions & 0 deletions templates/testdata/cluster-with-subnets.yaml
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 767aef4

Please sign in to comment.