From bc7de9951c6377713594004667784a5271ebfe4f Mon Sep 17 00:00:00 2001 From: Alexandr Demicev Date: Tue, 19 Mar 2024 14:05:18 +0100 Subject: [PATCH] Install RKE2 by default Signed-off-by: Alexandr Demicev --- .github/workflows/test_chart.yaml | 10 ++++- charts/rancher-turtles/questions.yml | 5 +++ .../templates/post-delete-job.yaml | 24 ++++++++++- .../templates/rke2-bootstrap.yaml | 43 +++++++++++++++++++ .../templates/rke2-controlplane.yaml | 43 +++++++++++++++++++ charts/rancher-turtles/values.yaml | 13 ++++++ test/testenv/turtles.go | 18 ++++++++ 7 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 charts/rancher-turtles/templates/rke2-bootstrap.yaml create mode 100644 charts/rancher-turtles/templates/rke2-controlplane.yaml diff --git a/.github/workflows/test_chart.yaml b/.github/workflows/test_chart.yaml index 3e76608d..be82ca77 100644 --- a/.github/workflows/test_chart.yaml +++ b/.github/workflows/test_chart.yaml @@ -26,7 +26,7 @@ jobs: - name: Set up Helm uses: azure/setup-helm@v4 with: - version: v3.12.1 + version: v3.14.3 - uses: actions/setup-python@v5 with: @@ -82,8 +82,14 @@ jobs: - name: Wait for core provider rollout run: sleep 30 && kubectl rollout status deployment capi-controller-manager -n capi-system --timeout=180s + - name: Wait for RKE2 bootstrap provider rollout + run: sleep 30 && kubectl rollout status deployment rke2-bootstrap-controller-manager -n rke2-bootstrap-system --timeout=180s + + - name: Wait for RKE2 control plane provider rollout + run: sleep 30 && kubectl rollout status deployment rke2-control-plane-controller-manager -n rke2-control-plane-system --timeout=180s + - name: Run chart-testing (un-install) - run: helm uninstall rancher-turtles -n rancher-turtles-system --cascade foreground --wait --debug + run: helm uninstall rancher-turtles -n rancher-turtles-system --cascade foreground --wait --debug --timeout=10m - name: Run chart re-install run: helm install rancher-turtles out/charts/rancher-turtles/ -n rancher-turtles-system --create-namespace --wait --debug diff --git a/charts/rancher-turtles/questions.yml b/charts/rancher-turtles/questions.yml index fe10b448..c9996f17 100644 --- a/charts/rancher-turtles/questions.yml +++ b/charts/rancher-turtles/questions.yml @@ -58,3 +58,8 @@ questions: type: boolean label: Use management v3 cluster manifest group: "Rancher Turtles Features Settings" + - variable: cluster-api-operator.cluster-api.rke2.enabled + default: "true" + description: "Flag to enable or disable installation of the RKE2 provider for Cluster API. By default this is enabled." + label: "Enable RKE2 Provider" + type: boolean diff --git a/charts/rancher-turtles/templates/post-delete-job.yaml b/charts/rancher-turtles/templates/post-delete-job.yaml index bbc0e8ea..c9282f83 100644 --- a/charts/rancher-turtles/templates/post-delete-job.yaml +++ b/charts/rancher-turtles/templates/post-delete-job.yaml @@ -71,6 +71,8 @@ spec: - capi-mutating-webhook-configuration - capi-kubeadm-bootstrap-mutating-webhook-configuration - capi-kubeadm-control-plane-mutating-webhook-configuration + - rke2-bootstrap-mutating-webhook-configuration + - rke2-control-plane-mutating-webhook-configuration - --ignore-not-found=true restartPolicy: Never --- @@ -98,6 +100,8 @@ spec: - capi-validating-webhook-configuration - capi-kubeadm-bootstrap-validating-webhook-configuration - capi-kubeadm-control-plane-validating-webhook-configuration + - rke2-bootstrap-validating-webhook-configuration + - rke2-control-plane-validating-webhook-configuration - --ignore-not-found=true restartPolicy: Never --- @@ -124,7 +128,7 @@ spec: - delete - deployments.apps/capi-controller-manager - -n - - capi-system + - {{ index .Values "cluster-api-operator" "cluster-api" "core" "namespace" }} - --ignore-not-found=true - name: delete-capi-kubeadm-bootstrap-controller-manager image: {{ index .Values "rancherTurtles" "features" "cluster-api-operator" "kubectlImage" }} @@ -144,4 +148,22 @@ spec: - -n - capi-kubeadm-control-plane-system - --ignore-not-found=true + - name: delete-rke2-kubeadm-bootstrap-controller-manager + image: {{ index .Values "rancherTurtles" "features" "cluster-api-operator" "kubectlImage" }} + command: ["kubectl"] + args: + - delete + - deployments.apps/rke2-bootstrap-controller-manager + - -n + - {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "bootstrap" "namespace" }} + - --ignore-not-found=true + - name: delete-rke2-control-plane-controller-manager + image: {{ index .Values "rancherTurtles" "features" "cluster-api-operator" "kubectlImage" }} + command: ["kubectl"] + args: + - delete + - deployments.apps/rke2-control-plane-controller-manager + - -n + - {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "controlPlane" "namespace" }} + - --ignore-not-found=true {{- end }} diff --git a/charts/rancher-turtles/templates/rke2-bootstrap.yaml b/charts/rancher-turtles/templates/rke2-bootstrap.yaml new file mode 100644 index 00000000..637b38e4 --- /dev/null +++ b/charts/rancher-turtles/templates/rke2-bootstrap.yaml @@ -0,0 +1,43 @@ +{{- if and (index .Values "cluster-api-operator" "cluster-api" "enabled") (index .Values "cluster-api-operator" "cluster-api" "rke2" "enabled") }} +{{- $namespace := index .Values "cluster-api-operator" "cluster-api" "rke2" "bootstrap" "namespace" }} +{{- if not (lookup "v1" "Namespace" "" $namespace) }} +--- +apiVersion: v1 +kind: Namespace +metadata: + annotations: + "helm.sh/hook": "post-install, post-upgrade" + "helm.sh/hook-weight": "1" + name: {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "bootstrap" "namespace" }} +{{- end }} +--- +apiVersion: turtles-capi.cattle.io/v1alpha1 +kind: CAPIProvider +metadata: + name: rke2-bootstrap + namespace: {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "bootstrap" "namespace" }} + annotations: + "helm.sh/hook": "post-install, post-upgrade, pre-delete" + "helm.sh/hook-weight": "2" +spec: + name: rke2 + type: bootstrap +{{- if index .Values "cluster-api-operator" "cluster-api" "rke2" "version" }} + version: {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "version" }} +{{- end }} + configSecret: +{{- if index .Values "cluster-api-operator" "cluster-api" "configSecret" "name" }} + name: {{ index .Values "cluster-api-operator" "cluster-api" "configSecret" "name" }} +{{ else }} + name: {{ index .Values "cluster-api-operator" "cluster-api" "configSecret" "defaultName" }} +{{- end }} +{{- if or (index .Values "cluster-api-operator" "cluster-api" "rke2" "bootstrap" "fetchConfig" "url") (index .Values "cluster-api-operator" "cluster-api" "rke2" "bootstrap" "fetchConfig" "selector") }} + fetchConfig: + {{- if index .Values "cluster-api-operator" "cluster-api" "rke2" "bootstrap" "fetchConfig" "url" }} + url: {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "bootstrap" "fetchConfig" "url" }} + {{- end }} + {{- if index .Values "cluster-api-operator" "cluster-api" "rke2" "bootstrap" "fetchConfig" "selector" }} + selector: {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "bootstrap" "fetchConfig" "selector" }} + {{- end }} +{{- end }} +{{- end }} diff --git a/charts/rancher-turtles/templates/rke2-controlplane.yaml b/charts/rancher-turtles/templates/rke2-controlplane.yaml new file mode 100644 index 00000000..a92a8c35 --- /dev/null +++ b/charts/rancher-turtles/templates/rke2-controlplane.yaml @@ -0,0 +1,43 @@ +{{- if and (index .Values "cluster-api-operator" "cluster-api" "enabled") (index .Values "cluster-api-operator" "cluster-api" "rke2" "enabled") }} +{{- $namespace := index .Values "cluster-api-operator" "cluster-api" "rke2" "controlPlane" "namespace" }} +{{- if not (lookup "v1" "Namespace" "" $namespace) }} +--- +apiVersion: v1 +kind: Namespace +metadata: + annotations: + "helm.sh/hook": "post-install, post-upgrade" + "helm.sh/hook-weight": "1" + name: {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "controlPlane" "namespace" }} +{{- end }} +--- +apiVersion: turtles-capi.cattle.io/v1alpha1 +kind: CAPIProvider +metadata: + name: rke2-control-plane + namespace: {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "controlPlane" "namespace" }} + annotations: + "helm.sh/hook": "post-install, post-upgrade, pre-delete" + "helm.sh/hook-weight": "2" +spec: + name: rke2 + type: controlPlane +{{- if index .Values "cluster-api-operator" "cluster-api" "rke2" "version" }} + version: {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "version" }} +{{- end }} + configSecret: +{{- if index .Values "cluster-api-operator" "cluster-api" "configSecret" "name" }} + name: {{ index .Values "cluster-api-operator" "cluster-api" "configSecret" "name" }} +{{ else }} + name: {{ index .Values "cluster-api-operator" "cluster-api" "configSecret" "defaultName" }} +{{- end }} +{{- if or (index .Values "cluster-api-operator" "cluster-api" "rke2" "controlPlane" "fetchConfig" "url") (index .Values "cluster-api-operator" "cluster-api" "rke2" "controlPlane" "fetchConfig" "selector") }} + fetchConfig: + {{- if index .Values "cluster-api-operator" "cluster-api" "rke2" "controlPlane" "fetchConfig" "url" }} + url: {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "controlPlane" "fetchConfig" "url" }} + {{- end }} + {{- if index .Values "cluster-api-operator" "cluster-api" "rke2" "controlPlane" "fetchConfig" "selector" }} + selector: {{ index .Values "cluster-api-operator" "cluster-api" "rke2" "controlPlane" "fetchConfig" "selector" }} + {{- end }} +{{- end }} +{{- end }} diff --git a/charts/rancher-turtles/values.yaml b/charts/rancher-turtles/values.yaml index 9c55d31e..e30cb310 100644 --- a/charts/rancher-turtles/values.yaml +++ b/charts/rancher-turtles/values.yaml @@ -48,3 +48,16 @@ cluster-api-operator: fetchConfig: url: "" selector: "" + rke2: + enabled: true + version: "" + bootstrap: + namespace: rke2-bootstrap-system + fetchConfig: + url: "" + selector: "" + controlPlane: + namespace: rke2-control-plane-system + fetchConfig: + url: "" + selector: "" diff --git a/test/testenv/turtles.go b/test/testenv/turtles.go index f53ea348..74153b2a 100644 --- a/test/testenv/turtles.go +++ b/test/testenv/turtles.go @@ -132,4 +132,22 @@ func DeployRancherTurtles(ctx context.Context, input DeployRancherTurtlesInput) Namespace: "capd-system", }}, }, input.WaitDeploymentsReadyInterval...) + + By("Waiting for CAPI RKE2 bootstrap deployment to be available") + framework.WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{ + Getter: input.BootstrapClusterProxy.GetClient(), + Deployment: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ + Name: "rke2-bootstrap-controller-manager", + Namespace: "rke2-bootstrap-system", + }}, + }, input.WaitDeploymentsReadyInterval...) + + By("Waiting for CAPI RKE2 control plane deployment to be available") + framework.WaitForDeploymentsAvailable(ctx, framework.WaitForDeploymentsAvailableInput{ + Getter: input.BootstrapClusterProxy.GetClient(), + Deployment: &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{ + Name: "rke2-control-plane-controller-manager", + Namespace: "rke2-control-plane-system", + }}, + }, input.WaitDeploymentsReadyInterval...) }