prole/tmp/clean_slate.sh

37 lines
1.5 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
export KUBECONFIG=/Users/chrisfu/dev/knoe/knoe-k3s.kubeconfig
echo "==> Deleting GitLab CR (lets operator clean up managed resources)..."
kubectl -n gitlab delete gitlab gitlab --ignore-not-found --timeout=60s 2>&1 || true
echo "==> Waiting 20s for operator cleanup..."
sleep 20
echo "==> Deleting gitlab namespace (all remaining resources)..."
kubectl delete namespace gitlab --ignore-not-found --timeout=120s 2>&1 || true
echo "==> Deleting jemalloc-builder (if in different ns)..."
kubectl delete daemonset jemalloc-builder -n gitlab --ignore-not-found 2>/dev/null || true
echo "==> Releasing bound/retained PVs for gitlab..."
for pv in gitlab-gitaly-synology gitlab-minio-synology; do
kubectl patch pv "$pv" -p '{"spec":{"claimRef":null}}' 2>/dev/null || true
kubectl delete pv "$pv" --ignore-not-found 2>/dev/null || true
done
echo "==> Wiping synology data dirs on gandalf (fresh start)..."
kubectl -n knoe-system run gitlab-wipe \
--image=alpine:latest --restart=Never --rm --attach \
--overrides='{
"spec":{"nodeName":"gandalf.knoe.org","tolerations":[{"operator":"Exists"}],
"volumes":[{"name":"s","hostPath":{"path":"/synology/d005","type":"Directory"}}],
"containers":[{"name":"gitlab-wipe","image":"alpine:latest",
"command":["sh","-c","rm -rf /s/gitlab && echo wiped"],
"volumeMounts":[{"name":"s","mountPath":"/s"}]}]}}' 2>&1 || true
echo "==> Verifying gitlab namespace is gone..."
kubectl get ns gitlab 2>&1 || echo "namespace deleted OK"
echo "==> Clean slate complete."