blob: b41679b061aa8d32a1a32050d7abef455d6897fd [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 Rozman03aa27e2017-10-11 13:04:23 -040048 sdc, aai ,mso, message-router, robot, vid, aaf, uui
Dusan Rozman7704d2a2017-09-26 16:04:12 -040049 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
kerenj74d723a2017-08-22 15:27:04 +000097for i in ${HELM_APPS[@]}; do
98
kerenj78eff212017-08-29 09:56:36 +000099 delete_app_helm $NS $i
kerenj74d723a2017-08-22 15:27:04 +0000100 delete_namespace $NS $i
Anaël Closson40cdf492017-10-09 14:52:24 +0200101 delete_service_account $NS $i
kerenj74d723a2017-08-22 15:27:04 +0000102
103done
104
Munir Ahmada37c0f42017-12-07 14:31:01 -0500105delete_app_helm $NS "config"
106kubectl delete namespace $NS
107
yuryn715e36b2017-10-15 19:07:29 +0300108if $WAIT_TERMINATE; then
109 wait_terminate $NS
110fi
Mandeep Khindad6ea9872017-06-24 11:49:37 -0400111
112printf "\n********** Gone **********\n"