Repository navigation
Expand file tree
/
Copy pathhelm_teardown_test.sh
More file actions
executable file
·76 lines (69 loc) · 4.32 KB
/
Copy pathhelm_teardown_test.sh
File metadata and controls
executable file
·76 lines (69 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
# SPEC-010 (issue #53 / cloud-storage#472) — teardown scenario: dataRetentionPolicy=delete,
# single-node stub.
#
# Requires a real cluster — NOT runnable in CI sandboxes without one:
# a Kubernetes cluster (kind/k3s), kubectl, helm, an external PostgreSQL, a Lightstack
# image, and a kubectl image.
#
# Validates:
# US1 SC-001/003/006 — the blocking purge runs and leaves zero release residue
# (workloads, PVCs, hook Jobs). Real-mode HOST residue
# (libvirt domains, light-ns-*/qrouter- namespaces, br-*
# bridges, SNAT/FIP/SG/metadata iptables, and the
# /var/lib/lightstack trees) is verified by the real-mode host
# runbook, not by this stub-cluster scenario.
# US2 SC-002 — an immediate redeploy comes up healthy. Resource-level
# pristineness requires a CLEAN database: the DB is
# operator-owned and is NOT reset by teardown.
# US3 SC-004 — the default `retain` runs NO teardown hooks (no regression).
# SC-005 idempotency is unit-tested in internal/teardown.
#
# LIGHTSTACK_IMAGE_REPO=ghcr.io/you/lightstack KUBECTL_IMAGE=rancher/kubectl:v1.31 \
# LIGHTSTACK_DB_URL='postgres://lightstack:pw@host:5432/lightstack?sslmode=disable' ./test/helm_teardown_test.sh
set -euo pipefail
REL="${REL:-lightstack-teardown}"; NS="${NS:-lightstack-teardown}"
CHART="$(cd "$(dirname "$0")/.." && pwd)/charts/lightstack"
COMMON=(
--set image.repository="${LIGHTSTACK_IMAGE_REPO:?set LIGHTSTACK_IMAGE_REPO}"
--set image.tag="${LIGHTSTACK_IMAGE_TAG:-latest}"
--set secrets.jwtSecret="$(openssl rand -hex 16)"
--set secrets.adminPassword="Teardown-Admin-1"
--set database.url="${LIGHTSTACK_DB_URL:?set LIGHTSTACK_DB_URL}"
)
DELETE=(--set dataRetentionPolicy=delete --set teardown.kubectlImage="${KUBECTL_IMAGE:?set KUBECTL_IMAGE}")
# ---------------------------------------------------------------------------
# US1 — install in delete mode, then tear down: blocking purge + zero residue.
# ---------------------------------------------------------------------------
helm install "$REL" "$CHART" -n "$NS" --create-namespace "${COMMON[@]}" "${DELETE[@]}"
kubectl -n "$NS" rollout status "deploy/${REL}-lightstack" --timeout=300s
helm test "$REL" -n "$NS"
# helm uninstall returns only once the blocking pre-delete hooks succeed (SC-003).
helm uninstall "$REL" -n "$NS"
sleep 3
LEFT="$(kubectl -n "$NS" get deploy,svc,secret,pvc,job,sa,role,rolebinding -l "app.kubernetes.io/instance=${REL}" -o name 2>/dev/null || true)"
[ -z "$LEFT" ] && echo "PASS: no release residue after delete teardown (SC-001/006)" \
|| { echo "FAIL: residue remains: $LEFT"; exit 1; }
# NOTE: the operator-owned DATABASE is intentionally NOT reset by teardown. Real-mode
# host residue (domains, namespaces, bridges, iptables, /var/lib/lightstack/{instances,volumes,
# images,cloud-init,dhcp}) is checked by the real-mode host runbook, not this scenario.
# ---------------------------------------------------------------------------
# US2 — an immediate redeploy comes up healthy (SC-002). A truly pristine resource
# view requires a clean DB (operator-owned, not reset); here we assert health only.
# ---------------------------------------------------------------------------
helm install "$REL" "$CHART" -n "$NS" "${COMMON[@]}" "${DELETE[@]}"
kubectl -n "$NS" rollout status "deploy/${REL}-lightstack" --timeout=300s
helm test "$REL" -n "$NS" && echo "PASS: immediate redeploy healthy, no collisions (SC-002)"
helm uninstall "$REL" -n "$NS"
# ---------------------------------------------------------------------------
# US3 — the default `retain` removes workloads but runs NO teardown hooks (SC-004).
# ---------------------------------------------------------------------------
RET="${REL}-retain"
helm install "$RET" "$CHART" -n "$NS" "${COMMON[@]}" # retain is the default
kubectl -n "$NS" rollout status "deploy/${RET}-lightstack" --timeout=300s
helm uninstall "$RET" -n "$NS"
sleep 3
JOBS="$(kubectl -n "$NS" get jobs -o name 2>/dev/null | grep teardown || true)"
[ -z "$JOBS" ] && echo "PASS: retain ran no teardown hooks (SC-004 — no regression)" \
|| { echo "FAIL: teardown jobs appeared under retain: $JOBS"; exit 1; }
echo "TEARDOWN SCENARIO PASS"