blob: 2d5779ea2a62e5dd89a2d75b1cd9c9abe1ff25ca [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
Mandeep Khinda0e8f8892017-08-25 03:31:17 +00008 printf "Waiting for namespace $_NS termination...\n"
9 while kubectl get namespaces $_NS > /dev/null 2>&1; do
10 sleep 2
11 done
Borislav Glozman5197e2e2017-07-24 10:45:28 +030012 printf "Namespace $_NS deleted.\n\n"
13}
14
Anaël Closson40cdf492017-10-09 14:52:24 +020015delete_service_account() {
16 kubectl delete clusterrolebinding $1-$2-admin-binding
17 printf "Service account $1-$2-admin-binding deleted.\n\n"
18}
19
Borislav Glozman5197e2e2017-07-24 10:45:28 +030020delete_registry_key() {
Mandeep Khinda0e8f8892017-08-25 03:31:17 +000021 kubectl --namespace $1-$2 delete secret ${1}-docker-registry-key
Mandeep Khindad6ea9872017-06-24 11:49:37 -040022}
23
kerenj74d723a2017-08-22 15:27:04 +000024delete_app_helm() {
kerenj78eff212017-08-29 09:56:36 +000025 helm delete $1-$2 --purge
kerenj74d723a2017-08-22 15:27:04 +000026}
27
Mandeep Khindad6ea9872017-06-24 11:49:37 -040028usage() {
29 cat <<EOF
30Usage: $0 [PARAMs]
31-u : Display usage
32-n [NAMESPACE] : Kubernetes namespace (required)
Mandeep Khindad6ea9872017-06-24 11:49:37 -040033-a [APP] : Specify a specific ONAP component (default: all)
34 from the following choices:
Dusan Rozman03aa27e2017-10-11 13:04:23 -040035 sdc, aai ,mso, message-router, robot, vid, aaf, uui
Dusan Rozman7704d2a2017-09-26 16:04:12 -040036 sdnc, portal, policy, appc, multicloud, clamp, consul, vnfsdk
Mandeep Khindad6ea9872017-06-24 11:49:37 -040037EOF
38}
39
40#MAINs
41NS=
42INCL_SVC=false
43APP=
44
Keren Joseph4b7026e2017-09-12 10:13:15 +030045while getopts ":n:u:s:a:" PARAM; do
Mandeep Khindad6ea9872017-06-24 11:49:37 -040046 case $PARAM in
47 u)
48 usage
49 exit 1
50 ;;
51 n)
52 NS=${OPTARG}
53 ;;
Mandeep Khindad6ea9872017-06-24 11:49:37 -040054 a)
55 APP=${OPTARG}
56 if [[ -z $APP ]]; then
57 usage
58 exit 1
59 fi
60 ;;
61 ?)
62 usage
63 exit
64 ;;
65 esac
66done
67
68if [[ -z $NS ]]; then
69 usage
70 exit 1
71fi
72
73if [[ ! -z "$APP" ]]; then
kerenj80102842017-08-24 13:54:21 +000074 HELM_APPS=($APP)
Mandeep Khindad6ea9872017-06-24 11:49:37 -040075fi
76
77printf "\n********** Cleaning up ONAP: ${ONAP_APPS[*]}\n"
78
Mandeep Khindad6ea9872017-06-24 11:49:37 -040079
kerenj74d723a2017-08-22 15:27:04 +000080for i in ${HELM_APPS[@]}; do
81
kerenj78eff212017-08-29 09:56:36 +000082 delete_app_helm $NS $i
kerenj74d723a2017-08-22 15:27:04 +000083 delete_namespace $NS $i
Anaël Closson40cdf492017-10-09 14:52:24 +020084 delete_service_account $NS $i
kerenj74d723a2017-08-22 15:27:04 +000085
86done
87
Mandeep Khindad6ea9872017-06-24 11:49:37 -040088
89printf "\n********** Gone **********\n"