Skip to content

Commit

Permalink
Add variable for setting the project on cluster resource
Browse files Browse the repository at this point in the history
The diff also includes a patch to set the project property on
nutanixmachinetemplate resources for control plane and worker
machine deployments.
  • Loading branch information
thunderboltsid committed Mar 20, 2024
1 parent eb1611a commit e679011
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
35 changes: 35 additions & 0 deletions templates/cluster-template-clusterclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,35 @@ spec:
controlPlane: true
enabledIf: '{{if .failureDomains}}true{{end}}'
name: add-failure-domains
- definitions:
- jsonPatches:
- op: add
path: /spec/template/spec/project
valueFrom:
template: |
type: name
name: {{ .projectName }}
selector:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixMachineTemplate
matchResources:
controlPlane: true
- jsonPatches:
- op: add
path: /spec/template/spec/project
valueFrom:
template: |
type: name
name: {{ .projectName }}
selector:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixMachineTemplate
matchResources:
machineDeploymentClass:
names:
- nutanix-quick-start-worker
enabledIf: '{{if .projectName}}true{{end}}'
name: add-project
variables:
- name: sshKey
required: true
Expand Down Expand Up @@ -360,6 +389,12 @@ spec:
type: array
type: object
type: array
- name: projectName
required: false
schema:
openAPIV3Schema:
description: Prism Central project name to deploy the cluster resources into.
type: string
workers:
machineDeployments:
- class: nutanix-quick-start-worker
Expand Down
35 changes: 35 additions & 0 deletions templates/clusterclass/clusterclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,35 @@ spec:
path: /spec/template/spec/cluster
- op: remove
path: /spec/template/spec/subnet
- name: add-project
enabledIf: "{{if .projectName}}true{{end}}"
definitions:
- selector:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixMachineTemplate
matchResources:
controlPlane: true
jsonPatches:
- op: add
path: /spec/template/spec/project
valueFrom:
template: |
type: name
name: {{ .projectName }}
- selector:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixMachineTemplate
matchResources:
machineDeploymentClass:
names:
- nutanix-quick-start-worker
jsonPatches:
- op: add
path: /spec/template/spec/project
valueFrom:
template: |
type: name
name: {{ .projectName }}
variables:
- name: sshKey
required: true
Expand Down Expand Up @@ -376,3 +405,9 @@ spec:
enum:
- name
- uuid
- name: projectName
required: false
schema:
openAPIV3Schema:
description: Prism Central project name to deploy the cluster resources into.
type: string
25 changes: 25 additions & 0 deletions templates/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/format"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/util/yaml"
Expand All @@ -36,6 +37,7 @@ const (
)

func init() {
format.MaxLength = 100000
// Add NutanixCluster and NutanixMachine to the scheme
_ = v1beta1.AddToScheme(scheme.Scheme)
_ = capiv1.AddToScheme(scheme.Scheme)
Expand Down Expand Up @@ -313,4 +315,27 @@ var _ = Describe("Cluster Class Template Patches Test Suite", Ordered, func() {
))
})
})

Describe("patches for project", func() {
It("should have correct project", func() {
clusterManifest := "testdata/cluster-with-project.yaml"
obj, err := getClusterManifest(clusterManifest)
Expect(err).NotTo(HaveOccurred())

err = clnt.Create(context.Background(), obj) // Create the cluster
Expect(err).NotTo(HaveOccurred())

Eventually(func() error {
_, err = fetchNutanixCluster(clnt, obj.GetName())
return err
}).Within(time.Minute).Should(Succeed())

Eventually(func() ([]*v1beta1.NutanixMachineTemplate, error) {
return fetchMachineTemplates(clnt, obj.GetName())
}).Within(time.Minute).Should(And(HaveLen(2),
HaveEach(HaveExistingField("Spec.Template.Spec.Project")),
HaveEach(HaveField("Spec.Template.Spec.Project.Type", Equal(v1beta1.NutanixIdentifierName))),
HaveEach(HaveField("Spec.Template.Spec.Project.Name", HaveValue(Equal("fake-project"))))))
})
})
})
54 changes: 54 additions & 0 deletions templates/testdata/cluster-with-project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
labels:
ccm: nutanix
cluster.x-k8s.io/cluster-name: cluster-with-project
name: cluster-with-project
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
subnetName: fake-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
subnetName: fake-subnet
systemDiskSize: 40Gi
vcpuSockets: 2
vcpusPerSocket: 1
- name: projectName
value: fake-project
version: v1.29.2
workers:
machineDeployments:
- class: nutanix-quick-start-worker
name: md-0
replicas: 2

0 comments on commit e679011

Please sign in to comment.