forked from gardener/gardener
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gardener-extensions-down.sh
executable file
·61 lines (52 loc) · 2.97 KB
/
gardener-extensions-down.sh
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
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0
set -o errexit
set -o nounset
set -o pipefail
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
SEED_NAME=""
PATH_SEED_KUBECONFIG=""
PATH_GARDEN_KUBECONFIG=""
parse_flags() {
while test $# -gt 0; do
case "$1" in
--seed-name)
shift; SEED_NAME="$1"
;;
--path-seed-kubeconfig)
shift; PATH_SEED_KUBECONFIG="$1"
;;
--path-garden-kubeconfig)
shift; PATH_GARDEN_KUBECONFIG="$1"
;;
esac
shift
done
}
parse_flags "$@"
# Delete stuff gradually in the right order, otherwise several dependencies will prevent the cleanup from succeeding.
# Deleting seed will fail as long as there are shoots scheduled on it. This is desired to ensure that there are no orphan infrastructure elements left.
echo "Deleting $SEED_NAME seed"
kubectl --kubeconfig="$PATH_GARDEN_KUBECONFIG" delete seed "$SEED_NAME" --wait --ignore-not-found
skaffold --kubeconfig="$PATH_SEED_KUBECONFIG" delete -m gardenlet -p extensions
kubectl --kubeconfig="$PATH_GARDEN_KUBECONFIG" delete ns "relay-$SEED_NAME" --ignore-not-found
kubectl --kubeconfig "$PATH_SEED_KUBECONFIG" delete ns garden registry relay --ignore-not-found
kubectl --kubeconfig "$PATH_SEED_KUBECONFIG" delete -k "$SCRIPT_DIR"/../example/provider-extensions/kyverno --ignore-not-found
kubectl --kubeconfig "$PATH_SEED_KUBECONFIG" delete mutatingwebhookconfigurations kyverno-policy-mutating-webhook-cfg kyverno-resource-mutating-webhook-cfg kyverno-verify-mutating-webhook-cfg --ignore-not-found
kubectl --kubeconfig "$PATH_SEED_KUBECONFIG" delete validatingwebhookconfigurations kyverno-policy-validating-webhook-cfg kyverno-resource-validating-webhook-cfg --ignore-not-found
remaining_seeds=$(kubectl --kubeconfig="$PATH_GARDEN_KUBECONFIG" get seed --no-headers -o custom-columns=":metadata.name")
if [[ "$remaining_seeds" != "" ]]; then
echo "No clean up of kind cluster because of remaining seeds: ${remaining_seeds//$'\n'/,}"
else
echo "Cleaning up admission controllers"
"$SCRIPT_DIR"/../example/provider-extensions/garden/configure-admission.sh "$PATH_GARDEN_KUBECONFIG" delete --ignore-not-found
echo "Cleaning up kind cluster"
kubectl --kubeconfig="$PATH_GARDEN_KUBECONFIG" delete validatingwebhookconfiguration/gardener-admission-controller --ignore-not-found
kubectl --kubeconfig="$PATH_GARDEN_KUBECONFIG" annotate project garden confirmation.gardener.cloud/deletion=true
kubectl --kubeconfig="$PATH_GARDEN_KUBECONFIG" annotate -f "$SCRIPT_DIR"/../example/provider-extensions/garden/project/project.yaml confirmation.gardener.cloud/deletion=true
skaffold --kubeconfig="$PATH_GARDEN_KUBECONFIG" delete -m extensions-env -p extensions
skaffold --kubeconfig="$PATH_GARDEN_KUBECONFIG" delete -m etcd,controlplane -p extensions
kubectl --kubeconfig="$PATH_GARDEN_KUBECONFIG" delete ns garden gardener-system-seed-lease --ignore-not-found
fi