Update K8s Monitoring to support Grafana 8
[osm/devops.git] / installers / k8s / change-charts-prometheus-operator.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 # Script to generate new charts for kube-prometheus-stack
20 HERE=$(dirname $(readlink -f ${BASH_SOURCE[0]}))
21 source $HERE/versions_monitoring
22 V_OPERATOR=""
23
24 # Assign versions
25 V_OPERATOR=$PROMETHEUS_OPERATOR
26
27 WORK_DIR=$HERE
28 CHARTS_DIR="$HERE/helm_charts"
29 mkdir -p $CHARTS_DIR
30
31
32 # Delete old versions
33 cd $CHARTS_DIR
34
35 rm -rf kube-prometheus-stack > /dev/null 2>&1
36 rm kube-prometheus-stack* > /dev/null 2>&1
37
38 echo "Fetching prometheus-community/kube-prometheus-stack..."
39 helm fetch --version=$V_OPERATOR prometheus-community/kube-prometheus-stack
40 tar xvf kube-prometheus-stack-$V_OPERATOR.tgz > /dev/null 2>&1
41 cd $WORK_DIR
42
43
44 # Patching Grafana dashboards
45 cd $CHARTS_DIR/kube-prometheus-stack/templates/grafana/dashboards-1.14
46 for f in $(find . -name '*.yaml*');
47 do
48 # Set the correct datasource in all dashboards
49 linenumber=`cat -n $f | grep -A8 '"name": "datasource"' | grep regex | awk '{print $1}'`
50 sed -e "$linenumber s/\"regex\": \"\"/\"regex\": \"Prometheus\"/" -i $f
51 done
52 cd $WORK_DIR
53
54
55 exit 0