-
Notifications
You must be signed in to change notification settings - Fork 299
/
teardown
executable file
·61 lines (45 loc) · 2.08 KB
/
teardown
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
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
GREEN_PS3=$'\e[0;32m'
ORANGE_PS3=$'\e[0;33m'
WHITE='\033[0;37m'
if [ -z "${KUBECONFIG}" ]; then
export KUBECONFIG=~/.kube/config
fi
#Namespace
NAMESPACE=$(kubectl get sts --all-namespaces | grep prometheus-k8s | cut -d " " -f1)
kctl() {
kubectl --namespace "$NAMESPACE" "$@"
}
#Set namespace in various resources
for n in $(egrep -lir --include=*.{yaml,sh} "CUSTOM_NAMESPACE" .); do
sed -i -e 's,CUSTOM_NAMESPACE,'"$NAMESPACE"',g' $n
done
kctl delete -f manifests/node-exporter
kctl delete -f manifests/kube-state-metrics
find manifests/grafana -type f ! -name grafana.pvc.yaml -exec kubectl --namespace "$NAMESPACE" delete -f {} \;
find manifests/prometheus -type f ! -name prometheus-k8s-rbac.yaml -exec kubectl --namespace "$NAMESPACE" delete -f {} \;
kubectl delete -f manifests/prometheus/prometheus-k8s-rbac.yaml
kctl delete -f manifests/alertmanager
kubectl delete -f manifests/k8s/self-hosted
# Hack: wait a bit to let the controller delete the deployed Prometheus server.
sleep 5
find manifests/prometheus-operator -type f ! -name prometheus-operator-cluster-role-binding.yaml -exec kubectl --namespace "$NAMESPACE" delete -f {} \;
kubectl delete -f manifests/prometheus-operator/prometheus-operator-cluster-role-binding.yaml
kctl delete secret grafana-credentials
kctl delete svc alertmanager-operated
kctl delete svc prometheus-operated
kubectl delete clusterrolebinding admin-binding
#delete created custom resource definitions
kubectl get crd -o 'jsonpath={.items[*].metadata.name}' | xargs -n 1 | fgrep coreos.com | xargs kubectl delete crd
#manually remove persistent volumes instructions
echo -e "${GREEN}The persistent volumes for Grafana and Prometeus were not removed!"
echo -e "${GREEN}To remove them, please run te following command:"
echo -e "${WHITE}kubectl get pvc -n ${NAMESPACE} | grep 'grafana\|prometheus' | cut -d '" "' -f 1 | xargs -n 1 kubectl delete pvc -n ${NAMESPACE}"
#clean sed generated files
find . -name "*.yaml-e" -exec rm -rf {} \;
git checkout -- .