gitdataai/uninstall.sh
ZhenYi fc013b174f fix(ops): preserve resources on deploy failure and protect ConfigMap/PVC from deletion
- deploy.sh: keep failed release for debugging instead of auto-uninstall,
  add helm.sh/resource-policy=keep annotation on ConfigMap and PVC
- uninstall.sh: interactive confirmation with protected resource list,
  post-uninstall verification that namespace/ConfigMap/PVC still exist
2026-05-11 00:17:43 +08:00

57 lines
2.4 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
# ── helpers ──────────────────────────────────────────────────────────
RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
log() { echo -e "${GREEN}[OK]${NC} $*"; }
warn() { echo -e "${YELLOW}[WARN]${NC} $*"; }
# ── defaults ─────────────────────────────────────────────────────────
NAMESPACE="${NAMESPACE:-app}"
RELEASE="${RELEASE:-deploy}"
CONFIG_MAP="${CONFIG_MAP:-app-env}"
PVC_NAME="${PVC_NAME:-shared-data}"
# ── safety check ─────────────────────────────────────────────────────
echo ""
warn "This will remove Helm release '$RELEASE' from namespace '$NAMESPACE'."
warn "The following resources are PROTECTED and will NOT be deleted:"
warn " - Namespace: $NAMESPACE"
warn " - ConfigMap: $CONFIG_MAP"
warn " - PVC: $PVC_NAME"
echo ""
read -rp "Continue? [y/N] " confirm
if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then
log "Cancelled"
exit 0
fi
# ── uninstall ────────────────────────────────────────────────────────
log "Uninstalling Helm release $RELEASE..."
helm uninstall "$RELEASE" --namespace "$NAMESPACE"
log "Helm release uninstalled"
# ── verify protected resources ───────────────────────────────────────
log "Verifying protected resources still exist..."
if kubectl get namespace "$NAMESPACE" &>/dev/null; then
log "Namespace '$NAMESPACE' preserved"
else
echo -e "${RED}[ERR]${NC} Namespace '$NAMESPACE' was deleted!"
fi
if kubectl get configmap "$CONFIG_MAP" -n "$NAMESPACE" &>/dev/null; then
log "ConfigMap '$CONFIG_MAP' preserved"
else
echo -e "${RED}[ERR]${NC} ConfigMap '$CONFIG_MAP' was deleted!"
fi
if kubectl get pvc "$PVC_NAME" -n "$NAMESPACE" &>/dev/null; then
log "PVC '$PVC_NAME' preserved"
else
echo -e "${RED}[ERR]${NC} PVC '$PVC_NAME' was deleted!"
fi
log "Uninstall complete — remaining resources in namespace $NAMESPACE:"
kubectl get all,pvc,configmap,ingress -n "$NAMESPACE"