From 0ae7db654c86f9242a97283d3f48b9dbb2be5fc8 Mon Sep 17 00:00:00 2001 From: klinch0 <68821526+klinch0@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:44:19 +0300 Subject: [PATCH] add migration for dv (#455) ## Summary by CodeRabbit - **New Features** - Updated versioning logic to support migration from version 5 to version 6. - Introduced a migration script for managing Persistent Volume Claims (PVCs) and updating configurations. - **Bug Fixes** - Ensured error handling and waiting mechanisms for Kubernetes resources are preserved during migrations. --- scripts/installer.sh | 2 +- scripts/migrations/5 | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 scripts/migrations/5 diff --git a/scripts/installer.sh b/scripts/installer.sh index 69226a64..b3b57bc7 100755 --- a/scripts/installer.sh +++ b/scripts/installer.sh @@ -3,7 +3,7 @@ set -o pipefail set -e BUNDLE=$(set -x; kubectl get configmap -n cozy-system cozystack -o 'go-template={{index .data "bundle-name"}}') -VERSION=5 +VERSION=6 run_migrations() { if ! kubectl get configmap -n cozy-system cozystack-version; then diff --git a/scripts/migrations/5 b/scripts/migrations/5 new file mode 100644 index 00000000..d1abc6ea --- /dev/null +++ b/scripts/migrations/5 @@ -0,0 +1,15 @@ +#!/bin/sh +# Migration 5 --> 6 + +# Fix tenant-kubernetes PVCs +kubectl get secret -l kamaji.clastix.io/project=kamaji,kamaji.clastix.io/component=admin-kubeconfig -A --output=go-template='{{ range .items }}{{ printf "%s %s %s %s\n" .metadata.namespace .metadata.name (index .metadata.labels "kamaji.clastix.io/name") (index .data "super-admin.conf") }}{{ end }}' | while read NAMESPACE NAME CLUSTER CONFIGB64; do + config=$(mktemp) + echo "$CONFIGB64" | base64 -d > "$config" + kubectl get pv --kubeconfig="$config" --output=go-template='{{ range .items }}{{ printf "%s\n" .metadata.name }}{{ end }}' | while read PVC; do + (set -x; kubectl label pvc --overwrite -n "$NAMESPACE" "$PVC" "cluster.x-k8s.io/cluster-name=$CLUSTER") + (set -x; kubectl label dv --overwrite -n "$NAMESPACE" "$PVC" "cluster.x-k8s.io/cluster-name=$CLUSTER") + done + rm -f "$config" +done + +kubectl create configmap -n cozy-system cozystack-version --from-literal=version=6 --dry-run=client -o yaml | kubectl apply -f-