aboutsummaryrefslogtreecommitdiffstats
path: root/deployment/heat/onap-rke/scripts/cleanup.sh
blob: b65c8097c0efd2aaab7aefe850b0bdfba635717d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash

IFS='
'

if [ -z $1 ] || [ -z $2 ] || [ -z $3 ]; then
	echo "Usage: ./cleanup.sh onap_component_name namespace deployment"
	exit 1
fi

COMPONENT=`echo "$1" | tr '[:upper:]' '[:lower:]'`
NAMESPACE=`echo "$2" | tr '[:upper:]' '[:lower:]'`
DEPLOYMENT=`echo "$3" | tr '[:upper:]' '[:lower:]'`

if [ $COMPONENT == "dcae" ]; then
        ARRAY=(`kubectl get replicasets -n $NAMESPACE | grep $DEPLOYMENT-dcaegen2 | 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" ]; then
        for keyspace in sdctitan sdcrepository sdcartifact sdccomponent sdcaudit workflow dox zusammen_dox zusammen_workflow ; do
	        kubectl -n $NAMESPACE exec dev-cassandra-cassandra-0 -- cqlsh -u cassandra -p cassandra --request-timeout=30 -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