forked from dt-orders/keptn-orders-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleteCluster.sh
executable file
·86 lines (78 loc) · 3.23 KB
/
deleteCluster.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
#!/bin/bash
# load in the shared library and validate argument
source ./deploymentArgument.lib
DEPLOYMENT=$1
validate_deployment_argument $DEPLOYMENT
RESOURCE_PREFIX=$(cat creds.json | jq -r '.resourcePrefix')
CLUSTER_NAME="$RESOURCE_PREFIX"-keptn-orders-cluster
clear
case $DEPLOYMENT in
eks)
CLUSTER_REGION=$(cat creds.json | jq -r '.eksClusterRegion')
echo "===================================================="
echo "About to delete $DEPLOYMENT cluster."
echo " Cluster Name : $CLUSTER_NAME"
echo " Cluster Region : $CLUSTER_REGION"
echo ""
echo "This will take several minutes"
echo "===================================================="
read -rsp $'Press ctrl-c to abort. Press any key to continue...\n' -n1 key
echo ""
START_TIME=$(date)
eksctl delete cluster --name=$CLUSTER_NAME --region=$CLUSTER_REGION
;;
aks)
AKS_RESOURCEGROUP="$RESOURCE_PREFIX-keptn-orders-group"
AKS_SERVICE_PRINCIPAL="$RESOURCE_PREFIX-keptn-orders-sp"
echo "===================================================="
echo "About to delete $DEPLOYMENT_NAME cluster:"
echo " CLUSTER_NAME : $CLUSTER_NAME"
echo " AKS_RESOURCEGROUP : $AKS_RESOURCEGROUP"
echo " AKS_SERVICE_PRINCIPAL : $AKS_SERVICE_PRINCIPAL"
echo ""
echo "This will take several minutes"
echo "===================================================="
read -rsp $'Press ctrl-c to abort. Press any key to continue...\n' -n1 key
echo ""
START_TIME=$(date)
echo "Deleting cluster $CLUSTER_NAME ..."
az aks delete --name $CLUSTER_NAME --resource-group $AKS_RESOURCEGROUP
echo "Deleting resource group $AKS_RESOURCEGROUP ..."
az group delete --name $AKS_RESOURCEGROUP -y
# need to look up service principal id and then delete it
# this is outside of the resource group
AKS_SERVICE_PRINCIPAL_APPID=$(az ad sp list --display-name $AKS_SERVICE_PRINCIPAL | jq -r '.[0].appId')
if [ "$AKS_SERVICE_PRINCIPAL_APPID" != "null" ] ; then
echo "Deleting service principal $AKS_SERVICE_PRINCIPAL ..."
az ad sp delete --id $AKS_SERVICE_PRINCIPAL_APPID
fi
;;
ocp)
# Open shift
echo "TODO -- need to add scripts"
exit 1
;;
gke)
CLUSTER_ZONE=$(cat creds.json | jq -r '.gkeClusterZone')
CLUSTER_REGION=$(cat creds.json | jq -r '.gkeClusterRegion')
GKE_PROJECT=$(cat creds.json | jq -r '.gkeProject')
echo "===================================================="
echo "About to delete $DEPLOYMENT cluster."
echo " Project : $GKE_PROJECT"
echo " Cluster Name : $CLUSTER_NAME"
echo " Cluster Zone : $CLUSTER_ZONE"
echo ""
echo "This will take several minutes"
echo "===================================================="
read -rsp $'Press ctrl-c to abort. Press any key to continue...\n' -n1 key
echo ""
START_TIME=$(date)
# this command will prompt for confirmation
gcloud container clusters delete $CLUSTER_NAME --zone=$CLUSTER_ZONE --project=$GKE_PROJECT
;;
esac
echo "===================================================="
echo "Finished deleting $DEPLOYMENT Cluster"
echo "===================================================="
echo "Script start time : "$START_TIME
echo "Script end time : "$(date)