Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | IFS=' |
| 4 | ' |
| 5 | |
Marco Platania | bad325e | 2019-08-16 10:32:58 -0400 | [diff] [blame] | 6 | if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then |
| 7 | echo "Usage: ./cleanup.sh onap_component_name namespace deployment" |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 8 | exit 1 |
| 9 | fi |
| 10 | |
Marco Platania | bad325e | 2019-08-16 10:32:58 -0400 | [diff] [blame] | 11 | COMPONENT=`echo "$1" | tr '[:upper:]' '[:lower:]'` |
| 12 | NAMESPACE=`echo "$2" | tr '[:upper:]' '[:lower:]'` |
| 13 | DEPLOYMENT=`echo "$3" | tr '[:upper:]' '[:lower:]'` |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 14 | |
Marco Platania | bad325e | 2019-08-16 10:32:58 -0400 | [diff] [blame] | 15 | if [ $COMPONENT == "dcae" ]; then |
| 16 | ARRAY=(`kubectl get replicasets -n $NAMESPACE | grep $DEPLOYMENT- | awk '{print $1}'`) |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 17 | for i in ${ARRAY[*]}; do |
Marco Platania | bad325e | 2019-08-16 10:32:58 -0400 | [diff] [blame] | 18 | kubectl delete replicaset -n $NAMESPACE $i |
| 19 | done |
| 20 | |
| 21 | ARRAY=(`kubectl get services -n $NAMESPACE | grep -e ^xdcae | awk '{print $1}'`) |
| 22 | for i in ${ARRAY[*]}; do |
| 23 | kubectl delete service -n $NAMESPACE $i |
| 24 | done |
| 25 | |
| 26 | ARRAY=(`kubectl get services -n $NAMESPACE | grep -e ^holmes | awk '{print $1}'`) |
| 27 | for i in ${ARRAY[*]}; do |
| 28 | kubectl delete service -n $NAMESPACE $i |
| 29 | done |
| 30 | fi |
| 31 | |
| 32 | if [ $COMPONENT == "sdc" ]; then |
| 33 | for keyspace in sdctitan sdcrepository sdcartifact sdccomponent sdcaudit; do |
| 34 | kubectl -n $NAMESPACE exec dev-cassandra-cassandra-0 -- cqlsh -u cassandra -p cassandra -e "drop keyspace ${keyspace}" |
| 35 | done |
| 36 | fi |
| 37 | |
| 38 | if [ $COMPONENT == "so" ]; then |
| 39 | for database in camundabpmn catalogdb requestdb; do |
| 40 | kubectl -n $NAMESPACE exec dev-mariadb-galera-mariadb-galera-0 -- mysql -uroot -psecretpassword -e "drop database ${database}" |
| 41 | done |
| 42 | fi |
| 43 | |
| 44 | if [ $COMPONENT == "sdnc" ]; then |
| 45 | for database in sdnctl; do |
| 46 | kubectl -n $NAMESPACE exec dev-mariadb-galera-mariadb-galera-0 -- mysql -uroot -psecretpassword -e "drop database ${database}" |
| 47 | done |
| 48 | fi |
| 49 | |
| 50 | for op in secrets configmaps pvc pv deployments statefulsets clusterrolebinding jobs; do |
| 51 | ARRAY=(`kubectl get $op -n $NAMESPACE | grep $DEPLOYMENT-$COMPONENT | awk '{print $1}'`) |
| 52 | for i in ${ARRAY[*]}; do |
| 53 | kubectl delete $op -n $NAMESPACE $i |
Gary Wu | 950a323 | 2019-03-26 13:08:29 -0700 | [diff] [blame] | 54 | done |
| 55 | done |
Marco Platania | bad325e | 2019-08-16 10:32:58 -0400 | [diff] [blame] | 56 | |
| 57 | ARRAY=(`kubectl get services -n $NAMESPACE | grep -e ^$COMPONENT | awk '{print $1}'`) |
| 58 | for i in ${ARRAY[*]}; do |
| 59 | kubectl delete service -n $NAMESPACE $i |
| 60 | done |