blob: 30edc701dcd233a83280a8a962549ba1ba5cbb24 [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
Dario Faccin36faaff2023-05-23 17:44:49 +020019AIRFLOW_HELM_VERSION=1.9.0
garciadeblas7b53d262022-11-04 23:18:48 +010020PROMPUSHGW_HELM_VERSION=1.18.2
Dario Faccine93311d2023-02-15 09:29:55 +010021ALERTMANAGER_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
Dario Faccin36faaff2023-05-23 17:44:49 +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
garciadeblas7b53d262022-11-04 23:18:48 +010034 if ! helm -n osm status airflow 2> /dev/null ; then
35 # if it does not exist, create secrets and install
36 kubectl -n osm create secret generic airflow-webserver-secret --from-literal="webserver-secret-key=$(python3 -c 'import secrets; print(secrets.token_hex(16))')"
37 helm repo add apache-airflow https://airflow.apache.org
38 helm repo update
39 helm -n osm install airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION}
40 else
41 # if it exists, upgrade
42 helm repo update
43 helm -n osm upgrade airflow apache-airflow/airflow -f ${OSM_HELM_WORK_DIR}/airflow-values.yaml --version ${AIRFLOW_HELM_VERSION}
44 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
55 helm -n osm install pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION}
56 else
57 # if it exists, upgrade
58 helm repo update
59 helm -n osm upgrade pushgateway prometheus-community/prometheus-pushgateway --version ${PROMPUSHGW_HELM_VERSION}
60 fi
61 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
62}
63
Dario Faccine93311d2023-02-15 09:29:55 +010064# Install Prometheus AlertManager helm chart
65function install_prometheus_alertmanager() {
66 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
Dario Faccin36faaff2023-05-23 17:44:49 +020067 # 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}
Dario Faccine93311d2023-02-15 09:29:55 +010070 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
74 helm -n osm install alertmanager prometheus-community/alertmanager -f ${OSM_HELM_WORK_DIR}/alertmanager-values.yaml --version ${ALERTMANAGER_HELM_VERSION}
75 else
76 # if it exists, upgrade
77 helm repo update
78 helm -n osm upgrade alertmanager prometheus-community/alertmanager -f ${OSM_HELM_WORK_DIR}/alertmanager-values.yaml --version ${ALERTMANAGER_HELM_VERSION}
79 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
Dario Faccin36faaff2023-05-23 17:44:49 +020085DOCKER_REGISTRY_URL=
86DOCKER_USER="opensourcemano"
garciadeblasd2d00c72022-11-25 17:21:46 +010087OSM_DEVOPS="/usr/share/osm-devops"
garciadeblasd2d00c72022-11-25 17:21:46 +010088OSM_DOCKER_TAG="13"
Dario Faccin36faaff2023-05-23 17:44:49 +020089OSM_HELM_WORK_DIR="/etc/osm/helm"
garciadeblasd2d00c72022-11-25 17:21:46 +010090
Dario Faccin36faaff2023-05-23 17:44:49 +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 ;;
Dario Faccin36faaff2023-05-23 17:44:49 +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
Dario Faccine93311d2023-02-15 09:29:55 +0100139install_prometheus_alertmanager
140track deploy_osm alertmanager_ok
garciadeblas7b53d262022-11-04 23:18:48 +0100141