blob: 151b6860de52d175caf7b17c21a97895207fde20 [file] [log] [blame]
garciadeblas7b53d262022-11-04 23:18:48 +01001#!/bin/bash
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16set +eux
17
18# Helm chart 1.6.0 correspondes to Airflow 2.3.0
19AIRFLOW_HELM_VERSION=1.6.0
20PROMPUSHGW_HELM_VERSION=1.18.2
garciadeblasbae51f62023-03-28 18:27:20 +020021ALERTMANAGER_HELM_VERSION=0.22.0
garciadeblas7b53d262022-11-04 23:18:48 +010022
23# Install Airflow helm chart
24function install_airflow() {
25 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
26 # copy airflow-values.yaml to the destination folder
27 sudo mkdir -p ${OSM_HELM_WORK_DIR}
28 sudo cp ${OSM_DEVOPS}/installers/helm/values/airflow-values.yaml ${OSM_HELM_WORK_DIR}
garciadeblasd2d00c72022-11-25 17:21:46 +010029 # update airflow-values.yaml to use the right tag
30 echo "Updating Helm values file helm/values/airflow-values.yaml to use defaultAirflowTag: ${OSM_DOCKER_TAG}"
31 sudo sed -i "s#defaultAirflowTag:.*#defaultAirflowTag: ${OSM_DOCKER_TAG}#g" ${OSM_HELM_WORK_DIR}/airflow-values.yaml
garciadeblas7b53d262022-11-04 23:18:48 +010032 if ! helm -n osm status airflow 2> /dev/null ; then
33 # if it does not exist, create secrets and install
34 kubectl -n osm create secret generic airflow-webserver-secret --from-literal="webserver-secret-key=$(python3 -c 'import secrets; print(secrets.token_hex(16))')"
35 helm repo add apache-airflow https://airflow.apache.org
36 helm repo update
37 helm -n osm install airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION}
38 else
39 # if it exists, upgrade
40 helm repo update
41 helm -n osm upgrade airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION}
42 fi
43 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
44}
45
46# Install Prometheus Pushgateway helm chart
47function install_prometheus_pushgateway() {
48 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
49 if ! helm -n osm status pushgateway 2> /dev/null ; then
50 # if it does not exist, install
51 helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
52 helm repo update
53 helm -n osm install pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION}
54 else
55 # if it exists, upgrade
56 helm repo update
57 helm -n osm upgrade pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION}
58 fi
59 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
60}
61
garciadeblasbae51f62023-03-28 18:27:20 +020062# Install Prometheus AlertManager helm chart
63function install_prometheus_alertmanager() {
64 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
aguilard02609d92023-04-27 09:47:27 +000065 # copy alertmanager-values.yaml to the destination folder
66 sudo mkdir -p ${OSM_HELM_WORK_DIR}
67 sudo cp ${OSM_DEVOPS}/installers/helm/values/alertmanager-values.yaml ${OSM_HELM_WORK_DIR}
garciadeblasbae51f62023-03-28 18:27:20 +020068 if ! helm -n osm status alertmanager 2> /dev/null ; then
69 # if it does not exist, install
70 helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
71 helm repo update
72 helm -n osm install alertmanager prometheus-community/alertmanager -f ${OSM_HELM_WORK_DIR}/alertmanager-values.yaml --version ${ALERTMANAGER_HELM_VERSION}
73 else
74 # if it exists, upgrade
75 helm repo update
76 helm -n osm upgrade alertmanager prometheus-community/alertmanager -f ${OSM_HELM_WORK_DIR}/alertmanager-values.yaml --version ${ALERTMANAGER_HELM_VERSION}
77 fi
78 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
79}
80
garciadeblas7b53d262022-11-04 23:18:48 +010081# main
garciadeblasd2d00c72022-11-25 17:21:46 +010082
83OSM_DEVOPS="/usr/share/osm-devops"
84OSM_HELM_WORK_DIR="/etc/osm/helm"
85OSM_DOCKER_TAG="13"
86
87while getopts ":D:d:t:-: " o; do
garciadeblas7b53d262022-11-04 23:18:48 +010088 case "${o}" in
89 D)
90 OSM_DEVOPS="${OPTARG}"
91 ;;
92 d)
93 OSM_HELM_WORK_DIR="${OPTARG}"
94 ;;
garciadeblasd2d00c72022-11-25 17:21:46 +010095 t)
96 OSM_DOCKER_TAG="${OPTARG}"
97 ;;
garciadeblas7b53d262022-11-04 23:18:48 +010098 -)
99 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue
100 echo -e "Invalid option: '--$OPTARG'\n" >&2
101 exit 1
102 ;;
103 :)
104 echo "Option -$OPTARG requires an argument" >&2
105 exit 1
106 ;;
107 \?)
108 echo -e "Invalid option: '-$OPTARG'\n" >&2
109 exit 1
110 ;;
111 *)
112 exit 1
113 ;;
114 esac
115done
116
117source $OSM_DEVOPS/common/logging
118source $OSM_DEVOPS/common/track
119
120echo "DEBUG_INSTALL=$DEBUG_INSTALL"
121echo "OSM_DEVOPS=$OSM_DEVOPS"
garciadeblasd2d00c72022-11-25 17:21:46 +0100122echo "OSM_DOCKER_TAG=$OSM_DOCKER_TAG"
garciadeblas7b53d262022-11-04 23:18:48 +0100123echo "OSM_HELM_WORK_DIR=$OSM_HELM_WORK_DIR"
124
125install_airflow
126track deploy_osm airflow_ok
127install_prometheus_pushgateway
128track deploy_osm pushgateway_ok
garciadeblasbae51f62023-03-28 18:27:20 +0200129install_prometheus_alertmanager
130track deploy_osm alertmanager_ok
garciadeblas7b53d262022-11-04 23:18:48 +0100131