#!/bin/bash # GENERATED — component={{COMPONENT}} bundle={{BUNDLE_ID}} op=purge # DESTRUCTIVE: deletes workload + pvc + secret for this component. Requires --confirm. # Does NOT delete the namespace (may host other components). set -euo pipefail BUNDLE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" LOG="${BUNDLE_DIR}/purge.log" NAMESPACE="{{NAMESPACE}}" COMPONENT="{{COMPONENT}}" STEP="init" exec > >(tee -a "$LOG") 2>&1 _kubectl() { if command -v kubectl >/dev/null 2>&1; then command kubectl "$@" elif command -v k0s >/dev/null 2>&1; then k0s kubectl "$@" else echo "ERROR: no kubectl or k0s binary found on host" >&2 exit 127 fi } _fail() { local rc=$? echo "FAILED step=${STEP} line=${BASH_LINENO[0]} rc=${rc}" >&2 exit "${rc}" } trap _fail ERR if [ "${1:-}" != "--confirm" ]; then echo "purge.sh requires --confirm. Will delete all ${COMPONENT} resources incl. PVCs in ${NAMESPACE}." >&2 exit 3 fi echo "[purge] component=${COMPONENT} bundle={{BUNDLE_ID}} namespace=${NAMESPACE} started=$(date -Iseconds)" STEP="delete-workload" _kubectl delete statefulset,deployment,service,configmap,pvc \ --namespace "${NAMESPACE}" \ --selector "app.kubernetes.io/name=${COMPONENT}" \ --ignore-not-found \ --timeout=120s STEP="delete-secret" _kubectl delete secret "${COMPONENT}-credentials" \ --namespace "${NAMESPACE}" \ --ignore-not-found STEP="done" echo "[purge] OK finished=$(date -Iseconds). Namespace ${NAMESPACE} NOT deleted."