-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathdestroy_kube.sh
executable file
·126 lines (108 loc) · 4.52 KB
/
destroy_kube.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
set -o errexit # abort on nonzero exit status
set -o nounset # abort on unbound variable
set -o pipefail # don't hide errors within pipes
# Don't pollute console output with upgrade notifications
export PULUMI_SKIP_UPDATE_CHECK=true
# Run Pulumi non-interactively
export PULUMI_SKIP_CONFIRMATIONS=true
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
if ! command -v pulumi >/dev/null; then
if [ -x "${script_dir}/venv/bin/pulumi" ]; then
echo "Adding to [${script_dir}/venv/bin] to PATH"
export PATH="${script_dir}/venv/bin:$PATH"
if ! command -v pulumi >/dev/null; then
echo >&2 "Pulumi must be installed to continue"
exit 1
fi
else
echo >&2 "Pulumi must be installed to continue"
exit 1
fi
fi
if ! command -v python3 >/dev/null; then
echo >&2 "Python 3 must be installed to continue"
exit 1
fi
if ! command -v node >/dev/null; then
if [ -x "${script_dir}/venv/bin/pulumi" ]; then
echo "Adding to [${script_dir}/venv/bin] to PATH"
export PATH="${script_dir}/venv/bin:$PATH"
if ! command -v node >/dev/null; then
echo >&2 "NodeJS must be installed to continue"
exit 1
fi
else
echo >&2 "NodeJS must be installed to continue"
exit 1
fi
fi
# Check to see if the user is logged into Pulumi
if ! pulumi whoami --non-interactive >/dev/null 2>&1; then
pulumi login
if ! pulumi whoami --non-interactive >/dev/null 2>&1; then
echo >&2 "Unable to login to Pulumi - exiting"
exit 2
fi
fi
source "${script_dir}/../config/pulumi/environment"
echo "Configuring all Pulumi projects to use the stack: ${PULUMI_STACK}"
APPLICATIONS=(sirius)
KUBERNETES=(secrets observability logagent logstore certmgr prometheus)
NGINX=(kubernetes/nginx/ingress-controller-repo-only)
INFRA=(kubeconfig digitalocean/domk8s)
#
# This is a temporary process until we complete the directory reorg and move the start/stop
# process into more solid code.
#
# Destroy the application(s)
for project_dir in "${APPLICATIONS[@]}"; do
echo "$project_dir"
if [ -f "${script_dir}/../pulumi/python/kubernetes/applications/${project_dir}/Pulumi.yaml" ]; then
pulumi_args="--cwd ${script_dir}/../pulumi/python/kubernetes/applications/${project_dir} --emoji --stack ${PULUMI_STACK}"
pulumi $pulumi_args destroy
else
echo >&2 "Not destroying - Pulumi.yaml not found in directory: ${script_dir}/../pulumi/python/kubernetes/applications/${project_dir}"
fi
done
# Destroy other K8 resources
for project_dir in "${KUBERNETES[@]}"; do
echo "$project_dir"
if [ -f "${script_dir}/../pulumi/python/kubernetes/${project_dir}/Pulumi.yaml" ]; then
pulumi_args="--cwd ${script_dir}/../pulumi/python/kubernetes/${project_dir} --emoji --stack ${PULUMI_STACK}"
pulumi $pulumi_args destroy
else
echo >&2 "Not destroying - Pulumi.yaml not found in directory: ${script_dir}/../pulumi/python/kubernetes/${project_dir}"
fi
done
# TODO: figure out a more elegant way to do the CRD removal for prometheus #83
# This is a hack for now to remove the CRD's for prometheus-kube-stack
# See https://github.com/prometheus-community/helm-charts/blob/main/charts/kube-prometheus-stack/README.md#uninstall-chart
kubectl delete crd alertmanagerconfigs.monitoring.coreos.com >/dev/null 2>&1
kubectl delete crd alertmanagers.monitoring.coreos.com >/dev/null 2>&1
kubectl delete crd podmonitors.monitoring.coreos.com >/dev/null 2>&1
kubectl delete crd probes.monitoring.coreos.com >/dev/null 2>&1
kubectl delete crd prometheuses.monitoring.coreos.com >/dev/null 2>&1
kubectl delete crd prometheusrules.monitoring.coreos.com >/dev/null 2>&1
kubectl delete crd servicemonitors.monitoring.coreos.com >/dev/null 2>&1
kubectl delete crd thanosrulers.monitoring.coreos.com >/dev/null 2>&1
# Destroy NGINX components
for project_dir in "${NGINX[@]}"; do
echo "$project_dir"
if [ -f "${script_dir}/../pulumi/python/${project_dir}/Pulumi.yaml" ]; then
pulumi_args="--cwd ${script_dir}/../pulumi/python/${project_dir} --emoji --stack ${PULUMI_STACK}"
pulumi $pulumi_args destroy
else
echo >&2 "Not destroying - Pulumi.yaml not found in directory: ${script_dir}/../pulumi/python/${project_dir}"
fi
done
# Clean up the kubeconfig project
for project_dir in "${INFRA[@]}"; do
echo "$project_dir"
if [ -f "${script_dir}/../pulumi/python/infrastructure/${project_dir}/Pulumi.yaml" ]; then
pulumi_args="--cwd ${script_dir}/../pulumi/python/infrastructure/${project_dir} --emoji --stack ${PULUMI_STACK}"
pulumi $pulumi_args destroy
else
echo >&2 "Not destroying - Pulumi.yaml not found in directory: ${script_dir}/../pulumi/python/infrastructure/${project_dir}"
fi
done