forked from stolostron/deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclean-clusters.sh
executable file
·57 lines (47 loc) · 1.82 KB
/
clean-clusters.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
#!/bin/bash
# Copyright 2020 Red Hat Inc.
# Parameters
# -t Runs a test, but does not perform andy actions
CLEAN_RESOURCES=0
if [ "$?" == "-t" ]; then
echo "Test run ONLY."
CLEAN_RESOURCES=1
fi
echo "Continuing to execute this script will destroy the following \"managed\" Openshift clusters:"
oc get clusterDeployments --all-namespaces
echo
echo "If you would like to proceed with cleanup, type: DESTROY"
read -r DESTROY_YES
if [ "${DESTROY_YES}" != "DESTROY" ]; then
echo "You must type DESTROY to clean up the Hive deployed clusters"
exit 1
fi
for clusterName in `oc get clusterDeployments --all-namespaces --ignore-not-found | grep -v "NAMESPACE" | awk '{ print $1 }'`; do
echo "Destroying ${clusterName}"
if [ $CLEAN_RESOURCES ]; then
oc -n ${clusterName} delete clusterDeployment ${clusterName} --wait=false
sleep 10
podName=`oc -n ${clusterName} get pods | grep uninstall | awk '{ print $1 }'`
oc -n ${clusterName} logs ${podName} -f
fi
done
echo "Detaching imported clusters"
for clusterName in `oc get clusters --all-namespaces --ignore-not-found | grep -v "NAMESPACE" | awk '{ print $1 }'`; do
printf " Detaching cluster ${clusterName}\n "
if [ $CLEAN_RESOURCES ]; then
oc -n ${clusterName} delete cluster ${clusterName}
printf " " #Spacing
oc delete namespace ${clusterName} --wait=false
fi
done
# Stage2, 2nd pass
echo "Second pass cleaning, by endpointConfig"
for clusterName in `oc get endpointconfig --all-namespaces --ignore-not-found | grep -v "NAMESPACE" | awk '{ print $1 }'`; do
printf " Detaching cluster ${clusterName}\n "
if [ $CLEAN_RESOURCES ]; then
oc -n ${clusterName} delete cluster ${clusterName}
printf " " #Spacing
oc delete namespace ${clusterName} --wait=false
fi
done
echo "Done!"