@@ -148,6 +148,44 @@ jobs:
148148 kubectl auth can-i create services --namespace "${NAMESPACE}"
149149 kubectl get nodes -l "cloud.google.com/gke-nodepool=${NODE_POOL}" -o wide
150150
151+ - name : Cleanup leftover workloads from prior runs
152+ shell : bash
153+ run : |
154+ set -euo pipefail
155+
156+ LEFTOVER_JOBS=$(kubectl get jobs --namespace "${NAMESPACE}" \
157+ -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' \
158+ | grep '^gke-run-test-caces-' \
159+ | grep -v "^${WORKLOAD_NAME}$" || true)
160+
161+ if [[ -n "${LEFTOVER_JOBS}" ]]; then
162+ echo "Found leftover jobs from prior runs:"
163+ printf '%s\n' "${LEFTOVER_JOBS}"
164+ while IFS= read -r job; do
165+ [[ -z "${job}" ]] && continue
166+ kubectl delete job "${job}" --namespace "${NAMESPACE}" \
167+ --ignore-not-found=true --wait=true --timeout=5m
168+ done <<< "${LEFTOVER_JOBS}"
169+ else
170+ echo "No leftover jobs from prior runs."
171+ fi
172+
173+ LEFTOVER_SVCS=$(kubectl get services --namespace "${NAMESPACE}" \
174+ -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' \
175+ | grep '^gke-run-test-caces-.*-headless$' \
176+ | grep -v "^${WORKLOAD_NAME}-headless$" || true)
177+
178+ if [[ -n "${LEFTOVER_SVCS}" ]]; then
179+ echo "Found leftover headless services from prior runs:"
180+ printf '%s\n' "${LEFTOVER_SVCS}"
181+ while IFS= read -r svc; do
182+ [[ -z "${svc}" ]] && continue
183+ kubectl delete service "${svc}" --namespace "${NAMESPACE}" --ignore-not-found=true
184+ done <<< "${LEFTOVER_SVCS}"
185+ else
186+ echo "No leftover headless services from prior runs."
187+ fi
188+
151189 - name : Run multi-host test cases
152190 shell : bash
153191 run : |
0 commit comments