62 lines
1.5 KiB
Bash
Executable File
62 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SSH_ARGS=(
|
|
-i ~/.ssh/naeel_vm_id_ed25519
|
|
-o StrictHostKeyChecking=no
|
|
-o ConnectTimeout=10
|
|
naeel@5.172.178.213
|
|
)
|
|
|
|
kube_exec() {
|
|
if [ "${KUBECTL_DIRECT:-0}" = "1" ]; then
|
|
kubectl "$@"
|
|
else
|
|
ssh "${SSH_ARGS[@]}" "kubectl $*"
|
|
fi
|
|
}
|
|
|
|
namespace_for_sub() {
|
|
printf '%s' "$1" | sha256sum | awk '{print "fission-" substr($1, 1, 16)}'
|
|
}
|
|
|
|
delete_ns() {
|
|
local ns="$1"
|
|
[ -n "$ns" ] || return 0
|
|
if [ "${KUBECTL_DIRECT:-0}" = "1" ]; then
|
|
kubectl delete namespace "$ns" --wait=false >/dev/null 2>&1 || true
|
|
else
|
|
ssh "${SSH_ARGS[@]}" "kubectl delete namespace ${ns} --wait=false >/dev/null 2>&1 || true"
|
|
fi
|
|
echo "cleanup namespace: ${ns}"
|
|
}
|
|
|
|
delete_all_console_managed() {
|
|
local ns_list
|
|
if [ "${KUBECTL_DIRECT:-0}" = "1" ]; then
|
|
ns_list=$(kubectl get ns -l managed-by=fission-console -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' 2>/dev/null || true)
|
|
else
|
|
ns_list=$(ssh "${SSH_ARGS[@]}" '
|
|
set -e
|
|
kubectl get ns -l managed-by=fission-console -o jsonpath="{range .items[*]}{.metadata.name}{"\n"}{end}" 2>/dev/null || true
|
|
' )
|
|
fi
|
|
printf '%s\n' "$ns_list" | while IFS= read -r ns; do
|
|
[ -n "$ns" ] || continue
|
|
delete_ns "$ns"
|
|
done
|
|
}
|
|
|
|
if [ "$#" -eq 0 ]; then
|
|
echo "usage: $0 SUB [SUB ...] | --all-console-managed" >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$1" = "--all-console-managed" ]; then
|
|
delete_all_console_managed
|
|
exit 0
|
|
fi
|
|
|
|
printf '%s\n' "$@" | awk 'NF && !seen[$0]++' | while IFS= read -r sub; do
|
|
delete_ns "$(namespace_for_sub "$sub")"
|
|
done |