blob: b65c8097c0efd2aaab7aefe850b0bdfba635717d [file] [log] [blame]
Gary Wu950a3232019-03-26 13:08:29 -07001#!/bin/bash
2
3IFS='
4'
5
Marco Plataniabad325e2019-08-16 10:32:58 -04006if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then
7 echo "Usage: ./cleanup.sh onap_component_name namespace deployment"
Gary Wu950a3232019-03-26 13:08:29 -07008 exit 1
9fi
10
Marco Plataniabad325e2019-08-16 10:32:58 -040011COMPONENT=`echo "$1" | tr '[:upper:]' '[:lower:]'`
12NAMESPACE=`echo "$2" | tr '[:upper:]' '[:lower:]'`
13DEPLOYMENT=`echo "$3" | tr '[:upper:]' '[:lower:]'`
Gary Wu950a3232019-03-26 13:08:29 -070014
Marco Plataniabad325e2019-08-16 10:32:58 -040015if [ $COMPONENT == "dcae" ]; then
Marco Platania97919e82019-09-16 09:14:35 -040016 ARRAY=(`kubectl get replicasets -n $NAMESPACE | grep $DEPLOYMENT-dcaegen2 | awk '{print $1}'`)
Gary Wu950a3232019-03-26 13:08:29 -070017 for i in ${ARRAY[*]}; do
Marco Plataniabad325e2019-08-16 10:32:58 -040018 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
30fi
31
32if [ $COMPONENT == "sdc" ]; then
Brian Freeman00a07152019-09-13 09:23:55 -050033 for keyspace in sdctitan sdcrepository sdcartifact sdccomponent sdcaudit workflow dox zusammen_dox zusammen_workflow ; do
34 kubectl -n $NAMESPACE exec dev-cassandra-cassandra-0 -- cqlsh -u cassandra -p cassandra --request-timeout=30 -e "drop keyspace ${keyspace}"
Marco Plataniabad325e2019-08-16 10:32:58 -040035 done
36fi
37
38if [ $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
42fi
43
44if [ $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
48fi
49
50for 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 Wu950a3232019-03-26 13:08:29 -070054 done
55done
Marco Plataniabad325e2019-08-16 10:32:58 -040056
57ARRAY=(`kubectl get services -n $NAMESPACE | grep -e ^$COMPONENT | awk '{print $1}'`)
58for i in ${ARRAY[*]}; do
59 kubectl delete service -n $NAMESPACE $i
Brian Freeman00a07152019-09-13 09:23:55 -050060done