Make cleanup script more generic 07/93707/3
authorMarco Platania <platania@research.att.com>
Fri, 16 Aug 2019 14:32:58 +0000 (10:32 -0400)
committerMarco Platania <platania@research.att.com>
Fri, 16 Aug 2019 17:44:52 +0000 (13:44 -0400)
- Fix usage instructions
- Correct wrong input sequence

Issue-ID: INT-1073

Signed-off-by: Marco Platania <platania@research.att.com>
Change-Id: Ic01eb302d92d893d17eb71a9341be514cb12dc3f

deployment/heat/onap-rke/cleanup.sh [new file with mode: 0755]
deployment/heat/onap-rke/scripts/cleanup.sh

diff --git a/deployment/heat/onap-rke/cleanup.sh b/deployment/heat/onap-rke/cleanup.sh
new file mode 100755 (executable)
index 0000000..24f263b
--- /dev/null
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+IFS='
+'
+
+if [ -z $1 ]; then
+       echo "ONAP component name missing"
+       echo "Usage: ./cleanup.sh onap_component_name"
+       exit 1
+fi
+
+( cd scripts; ./cleanup.sh $1 onap dev )
index f602c70..405bc5a 100755 (executable)
@@ -3,39 +3,58 @@
 IFS='
 '
 
-if [ -z $1 ]; then
-       echo "ONAP component name missing"
-       echo "Usage: ./cleanup.sh onap_component_name"
+if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then
+       echo "Usage: ./cleanup.sh onap_component_name namespace deployment"
        exit 1
 fi
 
-COMPONENT=$1
+COMPONENT=`echo "$1" | tr '[:upper:]' '[:lower:]'`
+NAMESPACE=`echo "$2" | tr '[:upper:]' '[:lower:]'`
+DEPLOYMENT=`echo "$3" | tr '[:upper:]' '[:lower:]'`
 
-if [ $COMPONENT == "dcae" ] || [ $COMPONENT == "DCAE" ]; then
-       kubectl delete service consul -n onap
+if [ $COMPONENT == "dcae" ]; then
+        ARRAY=(`kubectl get replicasets -n $NAMESPACE | grep $DEPLOYMENT- | awk '{print $1}'`)
+       for i in ${ARRAY[*]}; do
+               kubectl delete replicaset -n $NAMESPACE $i
+       done
+
+       ARRAY=(`kubectl get services -n $NAMESPACE | grep -e ^xdcae | awk '{print $1}'`)
+       for i in ${ARRAY[*]}; do
+               kubectl delete service -n $NAMESPACE $i
+       done
+
+       ARRAY=(`kubectl get services -n $NAMESPACE | grep -e ^holmes | awk '{print $1}'`)
+       for i in ${ARRAY[*]}; do
+               kubectl delete service -n $NAMESPACE $i
+       done
 fi
 
-if [ $COMPONENT == "sdc" ] || [ $COMPONENT == "SDC" ]; then
+if [ $COMPONENT == "sdc" ]; then
         for keyspace in sdctitan sdcrepository sdcartifact sdccomponent sdcaudit; do
-               kubectl -n onap exec dev-cassandra-cassandra-0 -- cqlsh -u cassandra -p cassandra -e "drop keyspace ${keyspace}"
+               kubectl -n $NAMESPACE exec dev-cassandra-cassandra-0 -- cqlsh -u cassandra -p cassandra -e "drop keyspace ${keyspace}"
         done
 fi
 
-if [ $COMPONENT == "so" ] || [ $COMPONENT == "SO" ]; then
+if [ $COMPONENT == "so" ]; then
         for database in camundabpmn catalogdb requestdb; do
-               kubectl -n onap exec dev-mariadb-galera-mariadb-galera-0 -- mysql -uroot -psecretpassword -e "drop database ${database}"
+               kubectl -n $NAMESPACE exec dev-mariadb-galera-mariadb-galera-0 -- mysql -uroot -psecretpassword -e "drop database ${database}"
         done
 fi
 
-if [ $COMPONENT == "sdnc" ] || [ $COMPONENT == "SDNC" ]; then
+if [ $COMPONENT == "sdnc" ]; then
         for database in sdnctl; do
-               kubectl -n onap exec dev-mariadb-galera-mariadb-galera-0 -- mysql -uroot -psecretpassword -e "drop database ${database}"
+               kubectl -n $NAMESPACE exec dev-mariadb-galera-mariadb-galera-0 -- mysql -uroot -psecretpassword -e "drop database ${database}"
         done
 fi
 
-for op in secrets configmaps pvc pv services deployments statefulsets clusterrolebinding job; do
-       ARRAY=(`kubectl get $op -n onap | grep dev-$COMPONENT | awk '{print $1}'`)
+for op in secrets configmaps pvc pv deployments statefulsets clusterrolebinding jobs; do
+       ARRAY=(`kubectl get $op -n $NAMESPACE | grep $DEPLOYMENT-$COMPONENT | awk '{print $1}'`)
        for i in ${ARRAY[*]}; do
-               kubectl delete $op -n onap $i
+               kubectl delete $op -n $NAMESPACE $i
        done
 done
+
+ARRAY=(`kubectl get services -n $NAMESPACE | grep -e ^$COMPONENT | awk '{print $1}'`)
+for i in ${ARRAY[*]}; do
+       kubectl delete service -n $NAMESPACE $i
+done
\ No newline at end of file