Skip to content

Commit

Permalink
Prepend sed command on KCPT prekubadm commands
Browse files Browse the repository at this point in the history
sed commands mutate the kube-vip template with variables to configure
kube-vip.
  • Loading branch information
thunderboltsid authored and deepakm-ntnx committed Mar 28, 2024
1 parent bd8098a commit 93240be
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 4 deletions.
20 changes: 18 additions & 2 deletions templates/cluster-template-clusterclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ spec:
kind: NutanixClusterTemplate
matchResources:
infrastructureCluster: true
- jsonPatches:
- op: add
path: /spec/template/spec/kubeadmConfigSpec/preKubeadmCommands/-
valueFrom:
template: |
sed -i 's/control_plane_endpoint_ip/{{ .controlPlaneEndpoint.IP }}/g' /etc/kubernetes/manifests/kube-vip.yaml
- op: add
path: /spec/template/spec/kubeadmConfigSpec/preKubeadmCommands/-
valueFrom:
template: |
sed -i 's/control_plane_endpoint_port/{{ .controlPlaneEndpoint.port }}/g' /etc/kubernetes/manifests/kube-vip.yaml
selector:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlaneTemplate
matchResources:
controlPlane: true
name: update-control-plane-endpoint
- definitions:
- jsonPatches:
Expand Down Expand Up @@ -425,9 +441,9 @@ spec:
- name: vip_arp
value: "true"
- name: address
value: "${CONTROL_PLANE_ENDPOINT_IP}"
value: "control_plane_endpoint_ip"
- name: port
value: "${CONTROL_PLANE_ENDPOINT_PORT=6443}"
value: "control_plane_endpoint_port"
- name: vip_cidr
value: "32"
- name: cp_enable
Expand Down
16 changes: 16 additions & 0 deletions templates/clusterclass/clusterclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ spec:
template: |
host: '{{ .controlPlaneEndpoint.IP }}'
port: {{ .controlPlaneEndpoint.port }}
- selector:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlaneTemplate
matchResources:
controlPlane: true
jsonPatches:
- op: "add"
path: "/spec/template/spec/kubeadmConfigSpec/preKubeadmCommands/-"
valueFrom:
template: |
sed -i 's/control_plane_endpoint_ip/{{ .controlPlaneEndpoint.IP }}/g' /etc/kubernetes/manifests/kube-vip.yaml
- op: "add"
path: "/spec/template/spec/kubeadmConfigSpec/preKubeadmCommands/-"
valueFrom:
template: |
sed -i 's/control_plane_endpoint_port/{{ .controlPlaneEndpoint.port }}/g' /etc/kubernetes/manifests/kube-vip.yaml
- name: add-pc-endpoint-and-creds
definitions:
- selector:
Expand Down
4 changes: 2 additions & 2 deletions templates/clusterclass/kcpt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ spec:
- name: vip_arp
value: "true"
- name: address
value: "${CONTROL_PLANE_ENDPOINT_IP}"
value: "control_plane_endpoint_ip"
- name: port
value: "${CONTROL_PLANE_ENDPOINT_PORT=6443}"
value: "control_plane_endpoint_port"
- name: vip_cidr
value: "32"
- name: cp_enable
Expand Down
32 changes: 32 additions & 0 deletions templates/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,4 +294,36 @@ var _ = Describe("Cluster Class Template Patches Test Suite", Ordered, func() {
Expect(clnt.Delete(context.Background(), obj)).NotTo(HaveOccurred())
})
})

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

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

var nutanixCluster *v1beta1.NutanixCluster
Eventually(func() error {
nutanixCluster, err = fetchNutanixCluster(clnt, obj.GetName())
return err
}).Within(time.Minute).Should(Succeed())

Expect(nutanixCluster.Spec.ControlPlaneEndpoint).NotTo(BeNil())
Expect(nutanixCluster.Spec.ControlPlaneEndpoint.Host).To(Equal("1.2.3.4"))
Expect(nutanixCluster.Spec.ControlPlaneEndpoint.Port).To(Equal(int32(6443)))

var kubeadmcontrolplane *controlplanev1.KubeadmControlPlane
Eventually(func() error {
kcp, err := fetchKubeadmControlPlane(clnt, obj.GetName())
kubeadmcontrolplane = kcp
return err
}).Within(time.Minute).Should(Succeed())
Expect(kubeadmcontrolplane.Spec.KubeadmConfigSpec.PreKubeadmCommands).To(ContainElements(
"sed -i 's/control_plane_endpoint_ip/1.2.3.4/g' /etc/kubernetes/manifests/kube-vip.yaml",
"sed -i 's/control_plane_endpoint_port/6443/g' /etc/kubernetes/manifests/kube-vip.yaml",
))
})
})
})
52 changes: 52 additions & 0 deletions templates/testdata/cluster-with-control-plane-endpoint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
labels:
ccm: nutanix
cluster.x-k8s.io/cluster-name: cluster-with-control-plane-endpoint
name: cluster-with-control-plane-endpoint
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
version: v1.29.2
workers:
machineDeployments:
- class: nutanix-quick-start-worker
name: md-0
replicas: 2

0 comments on commit 93240be

Please sign in to comment.