blob: cdc651b1a9e5f31418e75100e019fb84a2743e16 [file] [log] [blame]
Mandeep Khindad6ea9872017-06-24 11:49:37 -04001#!/bin/bash
Borislav Glozman5197e2e2017-07-24 10:45:28 +03002
3. $(dirname "$0")/setenv.bash
4
Mandeep Khindad6ea9872017-06-24 11:49:37 -04005delete_namespace() {
Borislav Glozman5197e2e2017-07-24 10:45:28 +03006 _NS=$1-$2
7 kubectl delete namespace $_NS
Borislav Glozman5197e2e2017-07-24 10:45:28 +03008}
9
Anaël Closson40cdf492017-10-09 14:52:24 +020010delete_service_account() {
11 kubectl delete clusterrolebinding $1-$2-admin-binding
12 printf "Service account $1-$2-admin-binding deleted.\n\n"
13}
14
Borislav Glozman5197e2e2017-07-24 10:45:28 +030015delete_registry_key() {
Mandeep Khinda0e8f8892017-08-25 03:31:17 +000016 kubectl --namespace $1-$2 delete secret ${1}-docker-registry-key
Mandeep Khindad6ea9872017-06-24 11:49:37 -040017}
18
kerenj74d723a2017-08-22 15:27:04 +000019delete_app_helm() {
kerenj78eff212017-08-29 09:56:36 +000020 helm delete $1-$2 --purge
kerenj74d723a2017-08-22 15:27:04 +000021}
22
yuryn715e36b2017-10-15 19:07:29 +030023wait_terminate() {
24 printf "Waiting for namespaces termination...\n"
25 while true; do
26 declare -i _STATUS=0
27 for i in ${HELM_APPS[@]}; do
28 kubectl get namespaces $1-$i > /dev/null 2>&1
29 if [ "$?" -eq "0" ]; then
30 _STATUS=1
31 break
32 fi
33 done
34 if [ "$_STATUS" -eq "0" ]; then
35 break
36 fi
37 sleep 2
38 done
39}
40
Mandeep Khindad6ea9872017-06-24 11:49:37 -040041usage() {
42 cat <<EOF
43Usage: $0 [PARAMs]
44-u : Display usage
45-n [NAMESPACE] : Kubernetes namespace (required)
Mandeep Khindad6ea9872017-06-24 11:49:37 -040046-a [APP] : Specify a specific ONAP component (default: all)
47 from the following choices:
Dusan Rozman7704d2a2017-09-26 16:04:12 -040048 sdc, aai ,mso, message-router, robot, vid, aaf
49 sdnc, portal, policy, appc, multicloud, clamp, consul, vnfsdk
yuryn715e36b2017-10-15 19:07:29 +030050-N : Do not wait for deletion of namespace and its objects
Mandeep Khindad6ea9872017-06-24 11:49:37 -040051EOF
52}
53
54#MAINs
55NS=
56INCL_SVC=false
57APP=
yuryn715e36b2017-10-15 19:07:29 +030058WAIT_TERMINATE=true
Mandeep Khindad6ea9872017-06-24 11:49:37 -040059
yuryn715e36b2017-10-15 19:07:29 +030060while getopts ":n:u:s:a:N" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -040061 case $PARAM in
62 u)
63 usage
64 exit 1
65 ;;
66 n)
67 NS=${OPTARG}
68 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -040069 a)
70 APP=${OPTARG}
71 if [[ -z $APP ]]; then
72 usage
73 exit 1
74 fi
75 ;;
yuryn715e36b2017-10-15 19:07:29 +030076 N)
77 WAIT_TERMINATE=false
78 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -040079 ?)
80 usage
81 exit
82 ;;
83 esac
84done
85
86if [[ -z $NS ]]; then
87 usage
88 exit 1
89fi
90
91if [[ ! -z "$APP" ]]; then
kerenj80102842017-08-24 13:54:21 +000092 HELM_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -040093fi
94
95printf "\n********** Cleaning up ONAP: ${ONAP_APPS[*]}\n"
96
Mandeep Khindad6ea9872017-06-24 11:49:37 -040097
kerenj74d723a2017-08-22 15:27:04 +000098for i in ${HELM_APPS[@]}; do
99
kerenj78eff212017-08-29 09:56:36 +0000100 delete_app_helm $NS $i
kerenj74d723a2017-08-22 15:27:04 +0000101 delete_namespace $NS $i
Anaël Closson40cdf492017-10-09 14:52:24 +0200102 delete_service_account $NS $i
kerenj74d723a2017-08-22 15:27:04 +0000103
104done
105
yuryn715e36b2017-10-15 19:07:29 +0300106if $WAIT_TERMINATE; then
107 wait_terminate $NS
108fi
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400109
110printf "\n********** Gone **********\n"