1a3c77397893ec02e564af1eef0d54dc68ceff9a
[osm/devops.git] / installers / k8s / uninstall_osm_k8s_monitoring.sh
1 #!/bin/bash
2
3 # Copyright 2019 Minsait - Indra S.A.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # Author: Jose Manuel Palacios (jmpalacios@minsait.com)
17 # Author: Jose Antonio Martinez (jamartinezv@minsait.com)
18
19 function usage(){
20 echo -e "usage: $0 [OPTIONS]"
21 echo -e "Uninstall OSM Monitoring"
22 echo -e " OPTIONS"
23 echo -e " -n <namespace>: use specified kubernetes namespace - default: monitoring"
24 echo -e " --helm : uninstall tiller"
25 echo -e " --debug : debug script"
26 echo -e " -h / --help : print this help"
27 }
28
29 NAMESPACE=monitoring
30 HELM=""
31 DEBUG=""
32 while getopts ":h-:n:" o; do
33 case "${o}" in
34 h)
35 usage && exit 0
36 ;;
37 n)
38 NAMESPACE="${OPTARG}"
39 ;;
40
41 -)
42 [ "${OPTARG}" == "help" ] && usage && exit 0
43 [ "${OPTARG}" == "helm" ] && HELM="y" && continue
44 [ "${OPTARG}" == "debug" ] && DEBUG="y" && continue
45 echo -e "Invalid option: '--$OPTARG'\n" >&2
46 usage && exit 1
47 ;;
48
49 \?)
50 echo -e "Invalid option: '-$OPTARG'\n" >&2
51 usage && exit 1
52 ;;
53 *)
54 usage && exit 1
55 ;;
56 esac
57 done
58
59 function dump_vars(){
60 echo "NAMESPACE=$NAMESPACE"
61 echo "HELM=$NOTILLER"
62 echo "DEBUG=$DEBUG"
63 }
64
65 if [ -n "$DEBUG" ] ; then
66 set -x
67 fi
68
69
70
71 # remove dashboards
72 echo "Deleting dashboards...."
73 kubectl -n $NAMESPACE delete configmap osm-monitoring-prometheus-summary-grafana > /dev/null 2>&1
74 kubectl -n $NAMESPACE delete configmap osm-monitoring-prometheus-kafka-exporter-grafana > /dev/null 2>&1
75 kubectl -n $NAMESPACE delete configmap osm-monitoring-prometheus-mysql-exporter-grafana > /dev/null 2>&1
76 kubectl -n $NAMESPACE delete configmap osm-monitoring-prometheus-mongodb-exporter-grafana > /dev/null 2>&1
77
78 # remove exporters
79 echo "Deleting exporters...."
80 helm delete --purge osm-kafka-exporter > /dev/null 2>&1
81 helm delete --purge osm-mysql-exporter > /dev/null 2>&1
82 helm delete --purge osm-mongodb-exporter > /dev/null 2>&1
83
84 # remove prometheus-operator
85 echo "Deleting prometheus-operator...."
86 helm delete --purge osm-monitoring > /dev/null 2>&1
87
88 # Delete CRDs
89 kubectl delete crd prometheusrules.monitoring.coreos.com > /dev/null 2>&1
90 kubectl delete crd servicemonitors.monitoring.coreos.com > /dev/null 2>&1
91 kubectl delete crd alertmanagers.monitoring.coreos.com > /dev/null 2>&1
92 kubectl delete crd prometheuses.monitoring.coreos.com > /dev/null 2>&1
93 kubectl delete crd alertmanagers.monitoring.coreos.com > /dev/null 2>&1
94 kubectl delete crd podmonitors.monitoring.coreos.com > /dev/null 2>&1
95
96 # Delete monitoring namespace
97 echo "Deleting monitoring namespace...."
98 kubectl delete namespace $NAMESPACE
99
100 if [ -n "$HELM" ] ; then
101 sudo helm reset --force
102 kubectl delete --namespace kube-system serviceaccount tiller
103 kubectl delete clusterrolebinding tiller-cluster-rule
104 sudo rm /usr/local/bin/helm
105 rm -rf $HOME/.helm
106 fi
107
108