Feature 11007: replace charmed mongodb with bitnami helm chart
[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 " --debug : debug script"
25 echo -e " -h / --help : print this help"
26 }
27
28 NAMESPACE=monitoring
29 DEBUG=""
30 while getopts ":h-:n:" o; do
31 case "${o}" in
32 h)
33 usage && exit 0
34 ;;
35 n)
36 NAMESPACE="${OPTARG}"
37 ;;
38
39 -)
40 [ "${OPTARG}" == "help" ] && usage && exit 0
41 [ "${OPTARG}" == "debug" ] && DEBUG="y" && continue
42 echo -e "Invalid option: '--$OPTARG'\n" >&2
43 usage && exit 1
44 ;;
45
46 \?)
47 echo -e "Invalid option: '-$OPTARG'\n" >&2
48 usage && exit 1
49 ;;
50 *)
51 usage && exit 1
52 ;;
53 esac
54 done
55
56 function dump_vars(){
57 echo "NAMESPACE=$NAMESPACE"
58 echo "DEBUG=$DEBUG"
59 }
60
61 if [ -n "$DEBUG" ] ; then
62 set -x
63 fi
64
65
66
67 # remove dashboards
68 echo "Deleting dashboards...."
69 kubectl -n $NAMESPACE delete configmap osm-monitoring-osm-summary-grafana > /dev/null 2>&1
70 kubectl -n $NAMESPACE delete configmap osm-monitoring-osm-nodes-grafana > /dev/null 2>&1
71 kubectl -n $NAMESPACE delete configmap osm-monitoring-prometheus-kafka-exporter-grafana > /dev/null 2>&1
72 kubectl -n $NAMESPACE delete configmap osm-monitoring-prometheus-mysql-exporter-grafana > /dev/null 2>&1
73 kubectl -n $NAMESPACE delete configmap osm-monitoring-prometheus-mongodb-exporter-grafana > /dev/null 2>&1
74
75 # remove exporters
76 echo "Deleting exporters...."
77 helm delete --purge osm-kafka-exporter > /dev/null 2>&1
78 helm delete --purge osm-mysql-exporter > /dev/null 2>&1
79 helm delete --purge osm-mongodb-exporter > /dev/null 2>&1
80
81 # remove kube-prometheus-stack
82 echo "Deleting kube-prometheus-stack...."
83 helm delete --purge osm-monitoring > /dev/null 2>&1
84
85 # Delete CRDs
86 kubectl delete crd prometheusrules.monitoring.coreos.com > /dev/null 2>&1
87 kubectl delete crd servicemonitors.monitoring.coreos.com > /dev/null 2>&1
88 kubectl delete crd alertmanagers.monitoring.coreos.com > /dev/null 2>&1
89 kubectl delete crd prometheuses.monitoring.coreos.com > /dev/null 2>&1
90 kubectl delete crd alertmanagers.monitoring.coreos.com > /dev/null 2>&1
91 kubectl delete crd podmonitors.monitoring.coreos.com > /dev/null 2>&1
92
93 # Delete svcs
94 kubectl -n kube-system delete service osm-monitoring-kube-promet-coredns
95 kubectl -n kube-system delete service osm-monitoring-kube-promet-kube-controller-manager
96 kubectl -n kube-system delete service osm-monitoring-kube-promet-kube-etcd
97 kubectl -n kube-system delete service osm-monitoring-kube-promet-kube-proxy
98 kubectl -n kube-system delete service osm-monitoring-kube-promet-kube-scheduler
99 kubectl -n kube-system delete service osm-monitoring-kube-promet-kubelet
100
101 # Delete webhooks
102 kubectl delete validatingwebhookconfigurations.admissionregistration.k8s.io osm-monitoring-kube-promet-admission
103 kubectl delete mutatingwebhookconfigurations.admissionregistration.k8s.io osm-monitoring-kube-promet-admission
104
105 # Delete monitoring namespace
106 echo "Deleting monitoring namespace...."
107 kubectl delete namespace $NAMESPACE