Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 1 | #!/bin/bash |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 2 | |
| 3 | . $(dirname "$0")/setenv.bash |
| 4 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 5 | delete_namespace() { |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 6 | _NS=$1-$2 |
| 7 | kubectl delete namespace $_NS |
Mandeep Khinda | 0e8f889 | 2017-08-25 03:31:17 +0000 | [diff] [blame] | 8 | printf "Waiting for namespace $_NS termination...\n" |
| 9 | while kubectl get namespaces $_NS > /dev/null 2>&1; do |
| 10 | sleep 2 |
| 11 | done |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 12 | printf "Namespace $_NS deleted.\n\n" |
| 13 | } |
| 14 | |
Anaël Closson | 40cdf49 | 2017-10-09 14:52:24 +0200 | [diff] [blame] | 15 | delete_service_account() { |
| 16 | kubectl delete clusterrolebinding $1-$2-admin-binding |
| 17 | printf "Service account $1-$2-admin-binding deleted.\n\n" |
| 18 | } |
| 19 | |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 20 | delete_registry_key() { |
Mandeep Khinda | 0e8f889 | 2017-08-25 03:31:17 +0000 | [diff] [blame] | 21 | kubectl --namespace $1-$2 delete secret ${1}-docker-registry-key |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 22 | } |
| 23 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 24 | delete_app_helm() { |
kerenj | 78eff21 | 2017-08-29 09:56:36 +0000 | [diff] [blame] | 25 | helm delete $1-$2 --purge |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 28 | usage() { |
| 29 | cat <<EOF |
| 30 | Usage: $0 [PARAMs] |
| 31 | -u : Display usage |
| 32 | -n [NAMESPACE] : Kubernetes namespace (required) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 33 | -a [APP] : Specify a specific ONAP component (default: all) |
| 34 | from the following choices: |
Dusan Rozman | 03aa27e | 2017-10-11 13:04:23 -0400 | [diff] [blame] | 35 | sdc, aai ,mso, message-router, robot, vid, aaf, uui |
Dusan Rozman | 7704d2a | 2017-09-26 16:04:12 -0400 | [diff] [blame] | 36 | sdnc, portal, policy, appc, multicloud, clamp, consul, vnfsdk |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 37 | EOF |
| 38 | } |
| 39 | |
| 40 | #MAINs |
| 41 | NS= |
| 42 | INCL_SVC=false |
| 43 | APP= |
| 44 | |
Keren Joseph | 4b7026e | 2017-09-12 10:13:15 +0300 | [diff] [blame] | 45 | while getopts ":n:u:s:a:" PARAM; do |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 46 | case $PARAM in |
| 47 | u) |
| 48 | usage |
| 49 | exit 1 |
| 50 | ;; |
| 51 | n) |
| 52 | NS=${OPTARG} |
| 53 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 54 | 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 |
| 66 | done |
| 67 | |
| 68 | if [[ -z $NS ]]; then |
| 69 | usage |
| 70 | exit 1 |
| 71 | fi |
| 72 | |
| 73 | if [[ ! -z "$APP" ]]; then |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 74 | HELM_APPS=($APP) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 75 | fi |
| 76 | |
| 77 | printf "\n********** Cleaning up ONAP: ${ONAP_APPS[*]}\n" |
| 78 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 79 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 80 | for i in ${HELM_APPS[@]}; do |
| 81 | |
kerenj | 78eff21 | 2017-08-29 09:56:36 +0000 | [diff] [blame] | 82 | delete_app_helm $NS $i |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 83 | delete_namespace $NS $i |
Anaël Closson | 40cdf49 | 2017-10-09 14:52:24 +0200 | [diff] [blame] | 84 | delete_service_account $NS $i |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 85 | |
| 86 | done |
| 87 | |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 88 | |
| 89 | printf "\n********** Gone **********\n" |