forked from TheRealHaoLiu/hyper-acm-deploy
-
Notifications
You must be signed in to change notification settings - Fork 3
/
hyper-acm-uninstall.sh
executable file
·98 lines (62 loc) · 2.75 KB
/
hyper-acm-uninstall.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
#!/bin/bash
source ./helpers.sh
check_dependency
if [ "$#" -lt 1 ]; then
uninstall_usage
exit 0
fi
while getopts "c:n:" arg; do
case $arg in
c)
CLUSTER_NAME="${OPTARG}"
;;
n)
CLUSTER_NAMESPACE="${OPTARG}"
;;
:)
usage
exit 0
;;
*)
uninstall_usage
exit 0
;;
esac
done
comment "info" "1. Validating management cluster status"
oc config view --minify=true --raw=true > hub.kubeconfig
export KUBECONFIG=./hub.kubeconfig
oc cluster-info
if [ $? -ne 0 ]; then
comment "error" "Failed to access the management cluster."
exit 1
fi
HOSTED_CLUSTER="${CLUSTER_NAMESPACE}-${CLUSTER_NAME}"
comment "info" "2. Validating hosted cluster status in the hosted cluster namespace: ${HOSTED_CLUSTER}"
HOSTED_CLUSTER_KUBECONFIG=`oc get hostedcluster -n ${CLUSTER_NAMESPACE} ${CLUSTER_NAME} -o jsonpath={.status.kubeconfig.name}`
oc get secret -n ${CLUSTER_NAMESPACE} ${HOSTED_CLUSTER_KUBECONFIG} -o jsonpath={.data.kubeconfig} | base64 -d > ${HOSTED_CLUSTER_KUBECONFIG}.kubeconfig
export KUBECONFIG=${HOSTED_CLUSTER_KUBECONFIG}.kubeconfig
oc cluster-info
if [ $? -ne 0 ]; then
comment "error" "Failed to access the hosted cluster."
exit 1
fi
comment "info" "3. Uninstalling ACM App component"
export KUBECONFIG=./hub.kubeconfig
oc delete deployments -n ${HOSTED_CLUSTER} multicluster-operators-channel multicluster-operators-hub-subscription multicluster-operators-application multicluster-operators-subscription-report konnectivity-agent-webhook --ignore-not-found
oc delete services -n ${HOSTED_CLUSTER} channels-apps-open-cluster-management-webhook-svc --ignore-not-found
export KUBECONFIG=${HOSTED_CLUSTER_KUBECONFIG}.kubeconfig
oc delete endpoints -n ${HOSTED_CLUSTER} channels-apps-open-cluster-management-webhook-svc --ignore-not-found
oc delete services -n ${HOSTED_CLUSTER} channels-apps-open-cluster-management-webhook-svc --ignore-not-found
comment "info" "4. Uninstalling ACM Policy component"
export KUBECONFIG=./hub.kubeconfig
oc delete deployments -n ${HOSTED_CLUSTER} governance-policy-propagator --ignore-not-found
oc delete deployments -n ${HOSTED_CLUSTER} policy-addon-ctrl-controller-manager -n ${HOSTED_CLUSTER} --ignore-not-found
comment "info" "5. Uninstalling ACM Observability component"
comment "info" "6. Uninstalling ACM foundation component"
comment "info" "6.1 Delete the hosted cluster namespace from the hosted cluster"
export KUBECONFIG=${HOSTED_CLUSTER_KUBECONFIG}.kubeconfig
oc delete namespace ${HOSTED_CLUSTER}
comment "info" "6.2 Delete foundation components from the management cluster"
export KUBECONFIG=./hub.kubeconfig
oc delete deployments -n ${HOSTED_CLUSTER} managedcluster-import-controller hub-registration-controller clustermanager-placement-controller