Add check on installation of helm-charts in install_ngsa.sh
[osm/devops.git] / installers / install_ngsa.sh
1 #!/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
16 set +eux
17
18 # Helm chart 1.6.0 correspondes to Airflow 2.3.0
19 AIRFLOW_HELM_VERSION=1.9.0
20 PROMPUSHGW_HELM_VERSION=1.18.2
21 ALERTMANAGER_HELM_VERSION=0.22.0
22
23 # Install Airflow helm chart
24 function 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}
29 # 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
32 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
34
35 if ! helm -n osm status airflow 2> /dev/null ; then
36 # if it does not exist, create secrets and install
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} --timeout 10m || FATAL_TRACK ngsa "Failed installing airflow helm chart"
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} || FATAL_TRACK ngsa "Failed installing airflow helm chart"
44 fi
45 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
46 }
47
48 # Install Prometheus Pushgateway helm chart
49 function 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} || FATAL_TRACK ngsa "Failed installing pushgateway helm chart"
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} || FATAL_TRACK ngsa "Failed installing pushgateway helm chart"
60 fi
61 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
62 }
63
64 # Install Prometheus AlertManager helm chart
65 function install_prometheus_alertmanager() {
66 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
67 # 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}
70 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} || FATAL_TRACK ngsa "Failed installing alertmanager helm chart"
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} || FATAL_TRACK ngsa "Failed installing alertmanager helm chart"
79 fi
80 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
81 }
82
83 # main
84
85 DOCKER_REGISTRY_URL=
86 DOCKER_USER="opensourcemano"
87 OSM_DEVOPS="/usr/share/osm-devops"
88 OSM_DOCKER_TAG="13"
89 OSM_HELM_WORK_DIR="/etc/osm/helm"
90
91 while getopts ":D:d:t:r:U:-: " o; do
92 case "${o}" in
93 D)
94 OSM_DEVOPS="${OPTARG}"
95 ;;
96 d)
97 OSM_HELM_WORK_DIR="${OPTARG}"
98 ;;
99 t)
100 OSM_DOCKER_TAG="${OPTARG}"
101 ;;
102 r)
103 DOCKER_REGISTRY_URL="${OPTARG}"
104 ;;
105 U)
106 DOCKER_USER="${OPTARG}"
107 ;;
108 -)
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
125 done
126
127 source $OSM_DEVOPS/common/logging
128 source $OSM_DEVOPS/common/track
129
130 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
131 echo "OSM_DEVOPS=$OSM_DEVOPS"
132 echo "OSM_DOCKER_TAG=$OSM_DOCKER_TAG"
133 echo "OSM_HELM_WORK_DIR=$OSM_HELM_WORK_DIR"
134
135 install_airflow
136 track deploy_osm airflow_ok
137 install_prometheus_pushgateway
138 track deploy_osm pushgateway_ok
139 install_prometheus_alertmanager
140 track deploy_osm alertmanager_ok
141