forked from stolostron/bootstrap-ks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdestroy.sh
executable file
·62 lines (50 loc) · 1.52 KB
/
destroy.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
#!/bin/bash
# Color codes for bash output
BLUE='\e[36m'
GREEN='\e[32m'
RED='\e[31m'
YELLOW='\e[33m'
CLEAR='\e[39m'
#----LOAD ENV VARS FROM INPUT FILE----#
if [ -z "$1" ]; then
printf "Usage: ./destroy.sh <path-to-json-file>\n"
exit 1
fi
if [ ! -f "$1" ]; then
printf "$1 does not exist, exiting\n"
exit 1
fi
CLUSTER_NAME=$(cat $1 | jq -r '.CLUSTER_NAME')
REGION=$(cat $1 | jq -r '.REGION')
RESOURCE_NAME=$(cat $1 | jq -r '.RESOURCE_NAME')
#----VALIDATE ENV VARS----#
# Validate that we have all required env vars and exit with a failure if any are missing
missing=0
if [ -z "$IBMCLOUD_APIKEY" ]; then
printf "${RED}IBMCLOUD_APIKEY env var not set. flagging for exit.${CLEAR}\n"
missing=1
fi
if [ "$missing" -ne 0 ]; then
exit $missing
fi
#----LOG IN----#
# Log in and optionally choose a specific subscription
ibmcloud login --apikey $IBMCLOUD_APIKEY -r $REGION
if [ "$?" -ne 0 ]; then
printf "${RED}ibmcloud cli login failed, check credentials. Exiting.${CLEAR}\n"
exit 1
fi
printf "${BLUE}Using subscription:${CLEAR}\n"
printf "${YELLOW}"
ibmcloud account show
printf "${CLEAR}"
#----DELETE IKS CLUSTER----#
printf "${BLUE}Deleting the IKS cluster named ${CLUSTER_NAME}.${CLEAR}\n"
printf "${YELLOW}"
ibmcloud ks cluster rm --cluster ${CLUSTER_NAME} -f --force-delete-storage -s
if [ "$?" -ne 0 ]; then
printf "${RED}Failed to delete IKS cluster ${CLUSTER_NAME}, exiting${CLEAR}\n"
exit 1
fi
printf "${CLEAR}"
printf "${GREEN}Successfully cleaned up the IKS cluster named ${CLUSTER_NAME}.${CLEAR}\n"