fix CSI label for tenant Kubernetes clusters (#291)

This commit is contained in:
Andrei Kvapil
2024-08-19 10:12:12 +02:00
committed by GitHub
parent 4471b4ba2a
commit b3d4c9c6a2
3 changed files with 17 additions and 2 deletions

View File

@@ -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=4
VERSION=5
run_migrations() {
if ! kubectl get configmap -n cozy-system cozystack-version; then

15
scripts/migrations/4 Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
# Migration 4 --> 5
# 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")
done
rm -f "$config"
done
# Write version to cozystack-version config
kubectl create configmap -n cozy-system cozystack-version --from-literal=version=5 --dry-run=client -o yaml | kubectl apply -f-