blob: 87f5daa1d7c37644c2e8025feec1fc9c047a8e22 [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
garciadeblas0b7ef272023-05-10 10:50:34 +020019AIRFLOW_HELM_VERSION=1.9.0
garciadeblas7b53d262022-11-04 23:18:48 +010020PROMPUSHGW_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
garciadeblas836354f2023-05-10 18:12:00 +020032 echo "Updating Helm values file helm/values/airflow-values.yaml to use defaultAirflowRepository: ${DOCKER_REGISTRY_URL}${DOCKER_USER}/airflow"
33 sudo sed -i "s#defaultAirflowRepository:.*#defaultAirflowRepository: ${DOCKER_REGISTRY_URL}${DOCKER_USER}/airflow#g" ${OSM_HELM_WORK_DIR}/airflow-values.yaml
garciadeblas8080e4b2023-04-14 09:57:17 +020034
garciadeblas7b53d262022-11-04 23:18:48 +010035 if ! helm -n osm status airflow 2> /dev/null ; then
36 # if it does not exist, create secrets and install
37 kubectl -n osm create secret generic airflow-webserver-secret --from-literal="webserver-secret-key=$(python3 -c 'import secrets; print(secrets.token_hex(16))')"
38 helm repo add apache-airflow https://airflow.apache.org
39 helm repo update
40 helm -n osm install airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION}
41 else
42 # if it exists, upgrade
43 helm repo update
44 helm -n osm upgrade airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION}
45 fi
46 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
47}
48
49# Install Prometheus Pushgateway helm chart
50function install_prometheus_pushgateway() {
51 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
52 if ! helm -n osm status pushgateway 2> /dev/null ; then
53 # if it does not exist, install
54 helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
55 helm repo update
56 helm -n osm install pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION}
57 else
58 # if it exists, upgrade
59 helm repo update
60 helm -n osm upgrade pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION}
61 fi
62 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
63}
64
garciadeblasbae51f62023-03-28 18:27:20 +020065# Install Prometheus AlertManager helm chart
66function install_prometheus_alertmanager() {
67 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
aguilard02609d92023-04-27 09:47:27 +000068 # copy alertmanager-values.yaml to the destination folder
69 sudo mkdir -p ${OSM_HELM_WORK_DIR}
70 sudo cp ${OSM_DEVOPS}/installers/helm/values/alertmanager-values.yaml ${OSM_HELM_WORK_DIR}
garciadeblasbae51f62023-03-28 18:27:20 +020071 if ! helm -n osm status alertmanager 2> /dev/null ; then
72 # if it does not exist, install
73 helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
74 helm repo update
75 helm -n osm install alertmanager prometheus-community/alertmanager -f ${OSM_HELM_WORK_DIR}/alertmanager-values.yaml --version ${ALERTMANAGER_HELM_VERSION}
76 else
77 # if it exists, upgrade
78 helm repo update
79 helm -n osm upgrade alertmanager prometheus-community/alertmanager -f ${OSM_HELM_WORK_DIR}/alertmanager-values.yaml --version ${ALERTMANAGER_HELM_VERSION}
80 fi
81 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
82}
83
garciadeblas7b53d262022-11-04 23:18:48 +010084# main
garciadeblasd2d00c72022-11-25 17:21:46 +010085
garciadeblas37630992023-05-09 13:33:22 +020086DOCKER_REGISTRY_URL=
87DOCKER_USER="opensourcemano"
garciadeblasd2d00c72022-11-25 17:21:46 +010088OSM_DEVOPS="/usr/share/osm-devops"
garciadeblasd2d00c72022-11-25 17:21:46 +010089OSM_DOCKER_TAG="13"
garciadeblas37630992023-05-09 13:33:22 +020090OSM_HELM_WORK_DIR="/etc/osm/helm"
garciadeblasd2d00c72022-11-25 17:21:46 +010091
garciadeblas37630992023-05-09 13:33:22 +020092while getopts ":D:d:t:r:U:-: " o; do
garciadeblas7b53d262022-11-04 23:18:48 +010093 case "${o}" in
94 D)
95 OSM_DEVOPS="${OPTARG}"
96 ;;
97 d)
98 OSM_HELM_WORK_DIR="${OPTARG}"
99 ;;
garciadeblasd2d00c72022-11-25 17:21:46 +0100100 t)
101 OSM_DOCKER_TAG="${OPTARG}"
102 ;;
garciadeblas37630992023-05-09 13:33:22 +0200103 r)
104 DOCKER_REGISTRY_URL="${OPTARG}"
105 ;;
106 U)
107 DOCKER_USER="${OPTARG}"
108 ;;
garciadeblas7b53d262022-11-04 23:18:48 +0100109 -)
110 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue
111 echo -e "Invalid option: '--$OPTARG'\n" >&2
112 exit 1
113 ;;
114 :)
115 echo "Option -$OPTARG requires an argument" >&2
116 exit 1
117 ;;
118 \?)
119 echo -e "Invalid option: '-$OPTARG'\n" >&2
120 exit 1
121 ;;
122 *)
123 exit 1
124 ;;
125 esac
126done
127
128source $OSM_DEVOPS/common/logging
129source $OSM_DEVOPS/common/track
130
131echo "DEBUG_INSTALL=$DEBUG_INSTALL"
132echo "OSM_DEVOPS=$OSM_DEVOPS"
garciadeblasd2d00c72022-11-25 17:21:46 +0100133echo "OSM_DOCKER_TAG=$OSM_DOCKER_TAG"
garciadeblas7b53d262022-11-04 23:18:48 +0100134echo "OSM_HELM_WORK_DIR=$OSM_HELM_WORK_DIR"
135
136install_airflow
137track deploy_osm airflow_ok
138install_prometheus_pushgateway
139track deploy_osm pushgateway_ok
garciadeblasbae51f62023-03-28 18:27:20 +0200140install_prometheus_alertmanager
141track deploy_osm alertmanager_ok
garciadeblas7b53d262022-11-04 23:18:48 +0100142