blob: 56da955c13bb435cd2e687c80f63fe963b8cb7d5 [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}"
garciadeblas659b1042023-07-20 17:02:19 +020031 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
garciadeblas7b53d262022-11-04 23:18:48 +010037 helm repo add apache-airflow https://airflow.apache.org
38 helm repo update
aguilard2becf422023-08-10 07:45:44 +000039 helm -n osm install airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION} --timeout 10m || FATAL_TRACK ngsa "Failed installing airflow helm chart"
garciadeblas7b53d262022-11-04 23:18:48 +010040 else
41 # if it exists, upgrade
42 helm repo update
aguilard2becf422023-08-10 07:45:44 +000043 helm -n osm upgrade airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION} || FATAL_TRACK ngsa "Failed installing airflow helm chart"
garciadeblas7b53d262022-11-04 23:18:48 +010044 fi
45 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
46}
47
48# Install Prometheus Pushgateway helm chart
49function install_prometheus_pushgateway() {
50 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
51 if ! helm -n osm status pushgateway 2> /dev/null ; then
52 # if it does not exist, install
53 helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
54 helm repo update
aguilard2becf422023-08-10 07:45:44 +000055 helm -n osm install pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION} || FATAL_TRACK ngsa "Failed installing pushgateway helm chart"
garciadeblas7b53d262022-11-04 23:18:48 +010056 else
57 # if it exists, upgrade
58 helm repo update
aguilard2becf422023-08-10 07:45:44 +000059 helm -n osm upgrade pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION} || FATAL_TRACK ngsa "Failed installing pushgateway helm chart"
garciadeblas7b53d262022-11-04 23:18:48 +010060 fi
61 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
62}
63
garciadeblasbae51f62023-03-28 18:27:20 +020064# Install Prometheus AlertManager helm chart
65function install_prometheus_alertmanager() {
66 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
aguilard02609d92023-04-27 09:47:27 +000067 # copy alertmanager-values.yaml to the destination folder
68 sudo mkdir -p ${OSM_HELM_WORK_DIR}
69 sudo cp ${OSM_DEVOPS}/installers/helm/values/alertmanager-values.yaml ${OSM_HELM_WORK_DIR}
garciadeblasbae51f62023-03-28 18:27:20 +020070 if ! helm -n osm status alertmanager 2> /dev/null ; then
71 # if it does not exist, install
72 helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
73 helm repo update
aguilard2becf422023-08-10 07:45:44 +000074 helm -n osm install alertmanager prometheus-community/alertmanager -f ${OSM_HELM_WORK_DIR}/alertmanager-values.yaml --version ${ALERTMANAGER_HELM_VERSION} || FATAL_TRACK ngsa "Failed installing alertmanager helm chart"
garciadeblasbae51f62023-03-28 18:27:20 +020075 else
76 # if it exists, upgrade
77 helm repo update
aguilard2becf422023-08-10 07:45:44 +000078 helm -n osm upgrade alertmanager prometheus-community/alertmanager -f ${OSM_HELM_WORK_DIR}/alertmanager-values.yaml --version ${ALERTMANAGER_HELM_VERSION} || FATAL_TRACK ngsa "Failed installing alertmanager helm chart"
garciadeblasbae51f62023-03-28 18:27:20 +020079 fi
80 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
81}
82
garciadeblas7b53d262022-11-04 23:18:48 +010083# main
garciadeblasd2d00c72022-11-25 17:21:46 +010084
garciadeblas37630992023-05-09 13:33:22 +020085DOCKER_REGISTRY_URL=
86DOCKER_USER="opensourcemano"
garciadeblasd2d00c72022-11-25 17:21:46 +010087OSM_DEVOPS="/usr/share/osm-devops"
garciadeblas0b299a12023-07-03 19:28:50 +020088OSM_DOCKER_TAG="14"
garciadeblas37630992023-05-09 13:33:22 +020089OSM_HELM_WORK_DIR="/etc/osm/helm"
garciadeblasd2d00c72022-11-25 17:21:46 +010090
garciadeblas37630992023-05-09 13:33:22 +020091while getopts ":D:d:t:r:U:-: " o; do
garciadeblas7b53d262022-11-04 23:18:48 +010092 case "${o}" in
93 D)
94 OSM_DEVOPS="${OPTARG}"
95 ;;
96 d)
97 OSM_HELM_WORK_DIR="${OPTARG}"
98 ;;
garciadeblasd2d00c72022-11-25 17:21:46 +010099 t)
100 OSM_DOCKER_TAG="${OPTARG}"
101 ;;
garciadeblas37630992023-05-09 13:33:22 +0200102 r)
103 DOCKER_REGISTRY_URL="${OPTARG}"
104 ;;
105 U)
106 DOCKER_USER="${OPTARG}"
107 ;;
garciadeblas7b53d262022-11-04 23:18:48 +0100108 -)
109 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="y" && continue
110 echo -e "Invalid option: '--$OPTARG'\n" >&2
111 exit 1
112 ;;
113 :)
114 echo "Option -$OPTARG requires an argument" >&2
115 exit 1
116 ;;
117 \?)
118 echo -e "Invalid option: '-$OPTARG'\n" >&2
119 exit 1
120 ;;
121 *)
122 exit 1
123 ;;
124 esac
125done
126
127source $OSM_DEVOPS/common/logging
128source $OSM_DEVOPS/common/track
129
130echo "DEBUG_INSTALL=$DEBUG_INSTALL"
131echo "OSM_DEVOPS=$OSM_DEVOPS"
garciadeblasd2d00c72022-11-25 17:21:46 +0100132echo "OSM_DOCKER_TAG=$OSM_DOCKER_TAG"
garciadeblas7b53d262022-11-04 23:18:48 +0100133echo "OSM_HELM_WORK_DIR=$OSM_HELM_WORK_DIR"
134
135install_airflow
136track deploy_osm airflow_ok
137install_prometheus_pushgateway
138track deploy_osm pushgateway_ok
garciadeblasbae51f62023-03-28 18:27:20 +0200139install_prometheus_alertmanager
140track deploy_osm alertmanager_ok
garciadeblas7b53d262022-11-04 23:18:48 +0100141