## What this PR does Fixes migration scripts for v0.40 release to ensure smooth upgrade process. Changes: - **Migration 20**: Replace `helm upgrade --install` with `cozyhr apply` for cozystack-controller and lineage-controller-webhook - **Migration 21**: Improve Flux instance removal process: - Disable reconciliation on FluxInstance before deletion - Delete Flux deployments before HelmReleases - Add `--wait=false` flags to prevent hanging - Fix CRD grep pattern to properly match `fluxcd.io` domains - **Migration 22**: Add new migration tasks: - Migrate Victoria Metrics Operator CRDs to prometheus-operator-crds Helm release - Remove CozyStack Resource Definitions HelmRelease - Add default version v17 to PostgreSQL HelmReleases without explicit version ### Release note ```release-note [platform] Fix migration scripts for v0.40 release: improve Flux removal, add VictoriaMetrics CRD migration, set default PostgreSQL version ```
67 lines
3 KiB
Bash
Executable file
67 lines
3 KiB
Bash
Executable file
#!/bin/sh
|
|
# Migration 20 --> 21
|
|
|
|
set -euo pipefail
|
|
|
|
kubectl -n cozy-system delete helmrelease cozystack-api \
|
|
|| kubectl -n cozy-system delete deployment cozystack-api --ignore-not-found # fallback to help migration progress if it failed first time
|
|
while [ $( kubectl -n cozy-system get po -l app=cozystack-api --no-headers | wc -l ) != 0 ] ;
|
|
do
|
|
echo "Waiting for Cozystack API pods to be deleted";
|
|
sleep 1
|
|
done
|
|
|
|
kubectl -n cozy-system delete helmrelease cozystack-controller \
|
|
|| kubectl -n cozy-system delete deployment cozystack-controller --ignore-not-found # same fallback
|
|
kubectl delete customresourcedefinitions.apiextensions.k8s.io cozystackresourcedefinitions.cozystack.io --ignore-not-found
|
|
while [ $( kubectl -n cozy-system get po -l app=cozystack-controller --no-headers | wc -l ) != 0 ] ;
|
|
do
|
|
echo "Waiting for Cozystack controller pods to be deleted";
|
|
sleep 1
|
|
done
|
|
|
|
kubectl delete helmrelease -n cozy-dashboard dashboard --ignore-not-found
|
|
sleep 5
|
|
cozyhr -n cozy-system -C packages/system/cozystack-resource-definition-crd apply cozystack-resource-definition-crd --plain
|
|
cozyhr -n cozy-system -C packages/system/cozystack-resource-definitions apply cozystack-resource-definitions --plain
|
|
cozyhr -n cozy-system -C packages/system/cozystack-api apply cozystack-api --plain
|
|
if kubectl get ds cozystack-api -n cozy-system >/dev/null 2>&1; then
|
|
echo "Waiting for cozystack-api daemonset"
|
|
kubectl rollout status ds/cozystack-api -n cozy-system --timeout=5m || exit 1
|
|
else
|
|
echo "Waiting for cozystack-api deployment"
|
|
kubectl rollout status deploy/cozystack-api -n cozy-system --timeout=5m || exit 1
|
|
fi
|
|
|
|
cozyhr -n cozy-system -C ./packages/system/cozystack-controller apply cozystack-controller --take-ownership
|
|
echo "Waiting for cozystack-controller"
|
|
kubectl rollout status deploy/cozystack-controller -n cozy-system --timeout=5m || exit 1
|
|
|
|
cozyhr -n cozy-system -C ./packages/system/lineage-controller-webhook/ apply lineage-controller-webhook --take-ownership
|
|
echo "Waiting for lineage-webhook"
|
|
kubectl rollout status ds/lineage-controller-webhook -n cozy-system --timeout=5m || exit 1
|
|
|
|
sleep 5
|
|
echo "Running lineage-webhook test"
|
|
kubectl delete ns cozy-lineage-webhook-test --ignore-not-found && kubectl create ns cozy-lineage-webhook-test
|
|
cleanup_test_ns() {
|
|
kubectl delete ns cozy-lineage-webhook-test --ignore-not-found
|
|
}
|
|
trap cleanup_test_ns ERR
|
|
timeout 60 sh -c 'until kubectl -n cozy-lineage-webhook-test create service clusterip lineage-webhook-test --clusterip="None" --dry-run=server; do sleep 1; done'
|
|
cleanup_test_ns
|
|
|
|
timestamp=$(date --rfc-3339=ns || date)
|
|
kubectl get namespace -o custom-columns=NAME:.metadata.name --no-headers |
|
|
grep '^tenant-' |
|
|
while read namespace ; do
|
|
(set -x; \
|
|
kubectl annotate \
|
|
pods,services,pvc,secrets,ingresses.networking.k8s.io,workloadmonitors.cozystack.io \
|
|
-n "$namespace" --all \
|
|
migration.cozystack.io="$timestamp" --overwrite || true)
|
|
done
|
|
|
|
# Stamp version
|
|
kubectl create configmap -n cozy-system cozystack-version \
|
|
--from-literal=version=21 --dry-run=client -o yaml | kubectl apply -f-
|