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 |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 8 | } |
| 9 | |
Anaël Closson | 40cdf49 | 2017-10-09 14:52:24 +0200 | [diff] [blame] | 10 | delete_service_account() { |
| 11 | kubectl delete clusterrolebinding $1-$2-admin-binding |
| 12 | printf "Service account $1-$2-admin-binding deleted.\n\n" |
| 13 | } |
| 14 | |
Borislav Glozman | 5197e2e | 2017-07-24 10:45:28 +0300 | [diff] [blame] | 15 | delete_registry_key() { |
Mandeep Khinda | 0e8f889 | 2017-08-25 03:31:17 +0000 | [diff] [blame] | 16 | kubectl --namespace $1-$2 delete secret ${1}-docker-registry-key |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 17 | } |
| 18 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 19 | delete_app_helm() { |
kerenj | 78eff21 | 2017-08-29 09:56:36 +0000 | [diff] [blame] | 20 | helm delete $1-$2 --purge |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 21 | } |
| 22 | |
yuryn | 715e36b | 2017-10-15 19:07:29 +0300 | [diff] [blame] | 23 | wait_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 Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 41 | usage() { |
| 42 | cat <<EOF |
| 43 | Usage: $0 [PARAMs] |
| 44 | -u : Display usage |
| 45 | -n [NAMESPACE] : Kubernetes namespace (required) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 46 | -a [APP] : Specify a specific ONAP component (default: all) |
| 47 | from the following choices: |
Dusan Rozman | 03aa27e | 2017-10-11 13:04:23 -0400 | [diff] [blame] | 48 | sdc, aai ,mso, message-router, robot, vid, aaf, uui |
Dusan Rozman | 7704d2a | 2017-09-26 16:04:12 -0400 | [diff] [blame] | 49 | sdnc, portal, policy, appc, multicloud, clamp, consul, vnfsdk |
yuryn | 715e36b | 2017-10-15 19:07:29 +0300 | [diff] [blame] | 50 | -N : Do not wait for deletion of namespace and its objects |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 51 | EOF |
| 52 | } |
| 53 | |
| 54 | #MAINs |
| 55 | NS= |
| 56 | INCL_SVC=false |
| 57 | APP= |
yuryn | 715e36b | 2017-10-15 19:07:29 +0300 | [diff] [blame] | 58 | WAIT_TERMINATE=true |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 59 | |
yuryn | 715e36b | 2017-10-15 19:07:29 +0300 | [diff] [blame] | 60 | while getopts ":n:u:s:a:N" PARAM; do |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 61 | case $PARAM in |
| 62 | u) |
| 63 | usage |
| 64 | exit 1 |
| 65 | ;; |
| 66 | n) |
| 67 | NS=${OPTARG} |
| 68 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 69 | a) |
| 70 | APP=${OPTARG} |
| 71 | if [[ -z $APP ]]; then |
| 72 | usage |
| 73 | exit 1 |
| 74 | fi |
| 75 | ;; |
yuryn | 715e36b | 2017-10-15 19:07:29 +0300 | [diff] [blame] | 76 | N) |
| 77 | WAIT_TERMINATE=false |
| 78 | ;; |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 79 | ?) |
| 80 | usage |
| 81 | exit |
| 82 | ;; |
| 83 | esac |
| 84 | done |
| 85 | |
| 86 | if [[ -z $NS ]]; then |
| 87 | usage |
| 88 | exit 1 |
| 89 | fi |
| 90 | |
| 91 | if [[ ! -z "$APP" ]]; then |
kerenj | 8010284 | 2017-08-24 13:54:21 +0000 | [diff] [blame] | 92 | HELM_APPS=($APP) |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 93 | fi |
| 94 | |
| 95 | printf "\n********** Cleaning up ONAP: ${ONAP_APPS[*]}\n" |
| 96 | |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 97 | for i in ${HELM_APPS[@]}; do |
| 98 | |
kerenj | 78eff21 | 2017-08-29 09:56:36 +0000 | [diff] [blame] | 99 | delete_app_helm $NS $i |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 100 | delete_namespace $NS $i |
Anaël Closson | 40cdf49 | 2017-10-09 14:52:24 +0200 | [diff] [blame] | 101 | delete_service_account $NS $i |
kerenj | 74d723a | 2017-08-22 15:27:04 +0000 | [diff] [blame] | 102 | |
| 103 | done |
| 104 | |
Munir Ahmad | a37c0f4 | 2017-12-07 14:31:01 -0500 | [diff] [blame^] | 105 | delete_app_helm $NS "config" |
| 106 | kubectl delete namespace $NS |
| 107 | |
yuryn | 715e36b | 2017-10-15 19:07:29 +0300 | [diff] [blame] | 108 | if $WAIT_TERMINATE; then |
| 109 | wait_terminate $NS |
| 110 | fi |
Mandeep Khinda | d6ea987 | 2017-06-24 11:49:37 -0400 | [diff] [blame] | 111 | |
| 112 | printf "\n********** Gone **********\n" |