cka-sim/teardown.sh

48 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Deletes kind cluster(s) and the local state of the tracks that ran on them (history is kept).
# ./teardown.sh every cka-sim cluster (cka-sim-135, cka-sim-137, any older minor's, and the
# old single cka-sim) + all state
# ./teardown.sh cka|cks the v1.35 cluster - CKA and CKS share it, so both their sessions go
# ./teardown.sh ckad the v1.37 cluster and the CKAD session
# ./teardown.sh legacy only the old single cluster 'cka-sim' from before per-version clusters
set -euo pipefail
cd "$(dirname "$0")"
RT="${CONTAINER_RUNTIME:-$(cat .state/runtime 2>/dev/null || echo podman)}"
[ "$RT" = podman ] && export KIND_EXPERIMENTAL_PROVIDER=podman
# cluster of a track, or stop here: an empty name would make kind delete its default cluster "kind"
cluster_of() {
local c
c=$(./exam --track "$1" cluster-env | sed -n 's/^CLUSTER=//p') || exit 1
[ -n "$c" ] || { echo "ERROR: ./exam cluster-env gave no cluster for track $1" >&2; exit 1; }
echo "$c"
}
what="${1:-all}"
case "$what" in
all)
# every cka-sim cluster - also one left behind when an exam moved to a new minor - and nothing else
for c in $(kind get clusters 2>/dev/null | grep -E '^cka-sim(-[0-9]+)?$'); do
kind delete cluster --name "$c"
done
# Safe to wipe wholesale: everything under workspace/ is generated by task setup scripts and
# nothing there is tracked (see .gitignore). Anything you want to keep, copy out first.
rm -rf .state workspace
echo "All cka-sim clusters and local state removed (history kept)."
;;
legacy)
kind delete cluster --name cka-sim || true
echo "Old cluster 'cka-sim' removed."
;;
cka|ckad|cks)
cluster=$(cluster_of "$what")
kind delete cluster --name "$cluster" || true
# sessions seeded on that cluster are gone with it; other tracks' sessions and files stay
for t in cka ckad cks; do
[ "$(cluster_of "$t")" = "$cluster" ] && rm -f ".state/state-$t.json"
done
echo "Cluster '$cluster' and the state of the tracks on it removed (history kept)."
;;
*) echo "usage: ./teardown.sh [all|cka|ckad|cks|legacy]"; exit 1 ;;
esac