-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathtest-cleanup
executable file
·57 lines (42 loc) · 2.59 KB
/
test-cleanup
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
#!/bin/bash
set -eu
k8s_context=${1:-""}
echo "cleaning up control-plane namespaces in k8s-context [${k8s_context}]"
if [ -z "${namespaces_controlplane=$(kubectl --context=$k8s_context get ns -oname -l linkerd.io/is-control-plane)}" ]; then
echo "no control-plane namespaces found" >&2
fi
echo "cleaning up data-plane namespaces in k8s-context [${k8s_context}]"
if [ -z "${namespaces_dataplane=$(kubectl --context=$k8s_context get ns -oname -l linkerd.io/is-test-data-plane)}" ]; then
echo "no data-plane namespaces found" >&2
fi
if [ -z "${clusterrolebindings=$(kubectl --context=$k8s_context get clusterrolebindings -oname -l linkerd.io/control-plane-ns)}" ]; then
echo "no clusterrolebindings found" >&2
fi
if [ -z "${clusterroles=$(kubectl --context=$k8s_context get clusterroles -oname -l linkerd.io/control-plane-ns)}" ]; then
echo "no clusterroles found" >&2
fi
if [ -z "${webhookconfigs=$(kubectl --context=$k8s_context get mutatingwebhookconfigurations -oname -l linkerd.io/control-plane-ns)}" ]; then
echo "no mutatingwebhookconfigurations found" >&2
fi
if [ -z "${validatingconfigs=$(kubectl --context=$k8s_context get validatingwebhookconfigurations -oname -l linkerd.io/control-plane-ns)}" ]; then
echo "no validatingwebhookconfigurations found" >&2
fi
if [ -z "${podsecuritypolicies=$(kubectl --context=$k8s_context get podsecuritypolicies -oname -l linkerd.io/control-plane-ns)}" ]; then
echo "no podsecuritypolicies found" >&2
fi
if [ -z "${customresourcedefinitions=$(kubectl --context=$k8s_context get customresourcedefinitions -l linkerd.io/control-plane-ns -oname)}" ]; then
echo "no customresourcedefinitions found" >&2
fi
if [ -z "${apiservices=$(kubectl --context=$k8s_context get apiservices -l linkerd.io/control-plane-ns -oname)}" ]; then
echo "no apiservices found" >&2
fi
if [[ $namespaces_controlplane || $namespaces_dataplane || $clusterrolebindings || $clusterroles || $webhookconfigs || $validatingconfigs || $podsecuritypolicies || $customresourcedefinitions || $apiservices ]]; then
kubectl --context=$k8s_context delete $namespaces_controlplane $namespaces_dataplane $clusterrolebindings $clusterroles $webhookconfigs $validatingconfigs $podsecuritypolicies $customresourcedefinitions $apiservices
fi
echo "cleaning up rolebindings in kube-system namespace in k8s-context [${k8s_context}]"
if ! rolebindings=$(kubectl --context=$k8s_context -n kube-system get rolebindings -l linkerd.io/control-plane-ns -oname); then
echo "no rolebindings found in the kube-system namespace" >&2
fi
if [[ $rolebindings ]]; then
kubectl --context=$k8s_context delete $rolebindings -n kube-system
fi