diff --git a/templates/cluster-template-clusterclass.yaml b/templates/cluster-template-clusterclass.yaml index d0aadd191f..e1c70cbb24 100644 --- a/templates/cluster-template-clusterclass.yaml +++ b/templates/cluster-template-clusterclass.yaml @@ -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: @@ -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 diff --git a/templates/clusterclass/clusterclass.yaml b/templates/clusterclass/clusterclass.yaml index 08d8029f62..72d6167219 100644 --- a/templates/clusterclass/clusterclass.yaml +++ b/templates/clusterclass/clusterclass.yaml @@ -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: diff --git a/templates/clusterclass/kcpt.yaml b/templates/clusterclass/kcpt.yaml index 46c9bd50b7..e67a2a9910 100644 --- a/templates/clusterclass/kcpt.yaml +++ b/templates/clusterclass/kcpt.yaml @@ -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 diff --git a/templates/template_test.go b/templates/template_test.go index 4c71417269..7d1c66f604 100644 --- a/templates/template_test.go +++ b/templates/template_test.go @@ -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", + )) + }) + }) }) diff --git a/templates/testdata/cluster-with-control-plane-endpoint.yaml b/templates/testdata/cluster-with-control-plane-endpoint.yaml new file mode 100644 index 0000000000..9387de775a --- /dev/null +++ b/templates/testdata/cluster-with-control-plane-endpoint.yaml @@ -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