Make cleanup script more generic

- Fix usage instructions
- Correct wrong input sequence

Issue-ID: INT-1073

Signed-off-by: Marco Platania <platania@research.att.com>
Change-Id: Ic01eb302d92d893d17eb71a9341be514cb12dc3f
diff --git a/deployment/heat/onap-rke/cleanup.sh b/deployment/heat/onap-rke/cleanup.sh
new file mode 100755
index 0000000..24f263b
--- /dev/null
+++ b/deployment/heat/onap-rke/cleanup.sh
@@ -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 )
diff --git a/deployment/heat/onap-rke/scripts/cleanup.sh b/deployment/heat/onap-rke/scripts/cleanup.sh
index f602c70..405bc5a 100755
--- a/deployment/heat/onap-rke/scripts/cleanup.sh
+++ b/deployment/heat/onap-rke/scripts/cleanup.sh
@@ -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
-fi
-
-if [ $COMPONENT == "sdc" ] || [ $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}"
-        done
-fi
-
-if [ $COMPONENT == "so" ] || [ $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}"
-        done
-fi
-
-if [ $COMPONENT == "sdnc" ] || [ $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}"
-        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}'`)
+if [ $COMPONENT == "dcae" ]; then
+        ARRAY=(`kubectl get replicasets -n $NAMESPACE | grep $DEPLOYMENT- | awk '{print $1}'`)
 	for i in ${ARRAY[*]}; do
-		kubectl delete $op -n onap $i
+		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" ]; then
+        for keyspace in sdctitan sdcrepository sdcartifact sdccomponent sdcaudit; do
+	        kubectl -n $NAMESPACE exec dev-cassandra-cassandra-0 -- cqlsh -u cassandra -p cassandra -e "drop keyspace ${keyspace}"
+        done
+fi
+
+if [ $COMPONENT == "so" ]; then
+        for database in camundabpmn catalogdb requestdb; do
+		kubectl -n $NAMESPACE exec dev-mariadb-galera-mariadb-galera-0 -- mysql -uroot -psecretpassword -e "drop database ${database}"
+        done
+fi
+
+if [ $COMPONENT == "sdnc" ]; then
+        for database in sdnctl; do
+		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 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 $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