#!/usr/bin/env bash set -euo pipefail export KUBECONFIG=/Users/chrisfu/dev/knoe/knoe-k3s.kubeconfig cd /Users/chrisfu/dev/knoe echo "==> Cleaning leftover gitea namespace..." && \ kubectl get namespace gitea -o json 2>/dev/null \ | python3 -c "import sys,json; d=json.load(sys.stdin); d['spec']['finalizers']=[]; print(json.dumps(d))" \ | kubectl replace --raw /api/v1/namespaces/gitea/finalize -f - 2>/dev/null || true && \ kubectl delete namespace gitea --ignore-not-found --timeout=30s 2>/dev/null || true echo "==> Releasing/deleting old PVs..." && \ for pv in gitlab-gitaly-synology gitlab-minio-synology; do kubectl patch pv "$pv" -p '{"metadata":{"finalizers":[]}}' --type=merge 2>/dev/null || true kubectl delete pv "$pv" --ignore-not-found 2>/dev/null || true done echo "==> Wiping synology gitlab dirs for 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":"w","image":"alpine:latest","command":["sh","-c","rm -rf /s/gitlab && echo wiped"],"volumeMounts":[{"name":"s","mountPath":"/s"}]}]}}' 2>&1 || true echo "==> Cleaning leftover ClusterRoles from old installs..." && \ kubectl get clusterrole,clusterrolebinding -o name 2>/dev/null \ | grep -i gitlab | xargs kubectl delete --ignore-not-found 2>&1 || true echo "==> jemalloc already built on all nodes (reusing)..." && \ ls /opt/gitlab-jemalloc/ 2>/dev/null || true echo "==> Removing stale PID lock..." && \ rm -f /Users/chrisfu/dev/knoe/install.pid echo "==> Cluster node status:" && \ kubectl get nodes echo "==> Launching install.sh pipeline (gitlab namespace, gandalf storage)..." && \ mkdir -p logs && \ nohup bash install.sh --silent -c conf/service/knoe.cfg \ > logs/install_final.log 2>&1 & disown && \ echo "Installer started — tail logs/install_final.log to monitor"