Files
fission-console/scripts/pre_cleanup.sh
T

39 lines
1.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# pre_cleanup.sh — удаляет ВСЕ тест-namespace-ы fission от прошлых прогонов.
# Паттерны: fission-<hex16> для namespace-ов созданных тест-субами вида
# crud-*/ttl-*/invoke-*/update-*/isolation-*/stress-*/alice-*/bob-*/
# linter-*@test.local
# Вызывается из run_all.sh с KUBECTL_DIRECT=1.
set -uo pipefail
if [ "${KUBECTL_DIRECT:-0}" != "1" ]; then
echo "pre_cleanup.sh: нужен KUBECTL_DIRECT=1 (должен запускаться на VM)" >&2
exit 1
fi
CLEANUP="${BASH_SOURCE%/*}/cleanup_test_namespaces.sh"
if [ ! -x "$CLEANUP" ]; then
echo "pre_cleanup.sh: cleanup_test_namespaces.sh не найден" >&2
exit 1
fi
# Список тест-субов создаёт namespace с именем fission-<hex16>.
# Получить все fission-namespace-ы кроме системного fission:
NS_LIST=$(kubectl get ns -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null | \
grep -E '^fission-[0-9a-f]{16}$' || true)
if [ -z "$NS_LIST" ]; then
echo "pre_cleanup.sh: тест-namespace-ы не найдены, пропускаем."
exit 0
fi
COUNT=$(echo "$NS_LIST" | wc -l)
echo "pre_cleanup.sh: найдено $COUNT тест-namespace-ов, удаляем..."
# cleanup_test_namespaces.sh принимает email-субы, а не namespace-ы.
# Но мы можем вызвать kubectl delete напрямую для namespace-ов.
echo "$NS_LIST" | xargs -r kubectl delete namespace --ignore-not-found 2>&1 | \
grep -v "^$" || true
echo "pre_cleanup.sh: очистка завершена."