File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ THRESHOLD_KB=5120 # 5 MB growth limit
1717NODE_COUNT=100
1818TEST_NAMESPACE=" ${TEST_NAMESPACE:- soak-test} "
1919RESULTS_FILE=" ${RESULTS_FILE:-/ tmp/ soak-memory.log} "
20+ CLEANUP_DONE=false
2021
2122# ── Helpers ──────────────────────────────────────────────────────────────────
2223
@@ -66,6 +67,46 @@ delete_nodes() {
6667 --timeout=120s 2> /dev/null || true
6768}
6869
70+ cleanup_resources () {
71+ local reason=" ${1:- exit} "
72+ if [[ " $CLEANUP_DONE " == " true" ]]; then
73+ echo " [cleanup] Already completed (reason: ${reason} )"
74+ return
75+ fi
76+ CLEANUP_DONE=true
77+
78+ echo " [cleanup] Starting cleanup (reason: ${reason} )..."
79+ delete_nodes || true
80+ kubectl delete namespace " $TEST_NAMESPACE " --ignore-not-found --wait=false > /dev/null 2>&1 || true
81+ echo " [cleanup] Cleanup finished for namespace: ${TEST_NAMESPACE} "
82+ }
83+
84+ handle_exit () {
85+ local exit_code=$?
86+ cleanup_resources " exit"
87+ if [[ $exit_code -ne 0 ]]; then
88+ echo " [cleanup] Exiting with failure code: ${exit_code} "
89+ else
90+ echo " [cleanup] Exiting successfully"
91+ fi
92+ exit " $exit_code "
93+ }
94+
95+ handle_signal () {
96+ local signal_name=" $1 "
97+ local signal_code=1
98+ case " $signal_name " in
99+ INT) signal_code=130 ;;
100+ TERM) signal_code=143 ;;
101+ esac
102+ echo " [cleanup] Received ${signal_name} ; requesting graceful shutdown..."
103+ exit " $signal_code "
104+ }
105+
106+ trap ' handle_signal INT' INT
107+ trap ' handle_signal TERM' TERM
108+ trap ' handle_exit' EXIT
109+
69110# ── Setup ─────────────────────────────────────────────────────────────────────
70111
71112kubectl create namespace " $TEST_NAMESPACE " --dry-run=client -o yaml | kubectl apply -f -
You can’t perform that action at this time.
0 commit comments