Skip to content

Commit

Permalink
🌱 Cleanup v1 cluster before creating v3 clusters on upgrade (#576)
Browse files Browse the repository at this point in the history
* Cleanup v1 cluster before creating v3 clusters on upgrade

Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>

* Cover provisioning to management v3 migration

- Add e2e tests, verifying the added migration functionality

Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>

* Clean up space for short e2e run

Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>

---------

Signed-off-by: Danil-Grigorev <danil.grigorev@suse.com>
  • Loading branch information
Danil-Grigorev committed Jun 24, 2024
1 parent e9aa608 commit 80e434b
Show file tree
Hide file tree
Showing 6 changed files with 542 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/e2e-short.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ jobs:
e2e:
runs-on: ubuntu-latest
steps:
- name: Cleanup space
run: |
sudo apt-get remove -y '^aspnetcore-.*' || echo "::warning::The command [sudo apt-get remove -y '^aspnetcore-.*'] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^dotnet-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^dotnet-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^llvm-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^llvm-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y 'php.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y 'php.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^mongodb-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^mongodb-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y '^mysql-.*' --fix-missing || echo "::warning::The command [sudo apt-get remove -y '^mysql-.*' --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri --fix-missing || echo "::warning::The command [sudo apt-get remove -y azure-cli google-chrome-stable firefox powershell mono-devel libgl1-mesa-dri --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y google-cloud-sdk --fix-missing || echo "::debug::The command [sudo apt-get remove -y google-cloud-sdk --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get remove -y google-cloud-cli --fix-missing || echo "::debug::The command [sudo apt-get remove -y google-cloud-cli --fix-missing] failed to complete successfully. Proceeding..."
sudo apt-get autoremove -y || echo "::warning::The command [sudo apt-get autoremove -y] failed to complete successfully. Proceeding..."
sudo apt-get clean || echo "::warning::The command [sudo apt-get clean] failed to complete successfully. Proceeding..."
sudo docker image prune --all --force || true
sudo swapoff -a || true
sudo rm -f /mnt/swapfile || true
free -h
- name: Checkout
uses: actions/checkout@v4.1.3
with:
Expand Down
6 changes: 6 additions & 0 deletions charts/rancher-turtles/questions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ questions:
type: boolean
label: Use management v3 cluster manifest
group: "Rancher Turtles Features Settings"
- variable: rancherTurtles.features.managementv3-cluster-migration.enabled
default: false
description: "(Experimental) Automatically migrate provisioning clusters to management clusters on upgrade"
type: boolean
label: Use newly provisioned management cluster manifest, replacing provisioning 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."
Expand Down
67 changes: 67 additions & 0 deletions charts/rancher-turtles/templates/post-upgrade-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{{- if and (index .Values "rancherTurtles" "features" "managementv3-cluster" "enabled") (index .Values "rancherTurtles" "features" "managementv3-cluster-migration" "enabled") }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: post-upgrade-job
namespace: rancher-turtles-system
annotations:
"helm.sh/hook": post-upgrade
"helm.sh/hook-weight": "1"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: post-upgrade-job-delete-clusters
annotations:
"helm.sh/hook": post-upgrade
"helm.sh/hook-weight": "1"
rules:
- apiGroups:
- provisioning.cattle.io
resources:
- clusters
verbs:
- list
- delete
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: post-upgrade-job-delete-clusters
annotations:
"helm.sh/hook": post-upgrade
"helm.sh/hook-weight": "1"
subjects:
- kind: ServiceAccount
name: post-upgrade-job
namespace: rancher-turtles-system
roleRef:
kind: ClusterRole
name: post-upgrade-job-delete-clusters
apiGroup: rbac.authorization.k8s.io
---
apiVersion: batch/v1
kind: Job
metadata:
name: post-upgrade-delete-clusters
annotations:
"helm.sh/hook": post-upgrade
"helm.sh/hook-weight": "2"
spec:
ttlSecondsAfterFinished: 300
template:
spec:
serviceAccountName: post-upgrade-job
containers:
- name: post-upgrade-delete-clusters
image: {{ index .Values "rancherTurtles" "features" "rancher-webhook" "kubectlImage" }}
args:
- delete
- clusters.provisioning.cattle.io
- --selector=cluster-api.cattle.io/owned
- -A
- --ignore-not-found=true
- --wait
restartPolicy: OnFailure
{{- end }}
2 changes: 2 additions & 0 deletions charts/rancher-turtles/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ rancherTurtles:
label: true
managementv3-cluster:
enabled: false
managementv3-cluster-migration:
enabled: false
propagate-labels:
enabled: false
etcd-snapshot-restore:
Expand Down
Loading

0 comments on commit 80e434b

Please sign in to comment.