blob: aa7f4a287588c6210a39d83a077e83301cbd7942 [file] [log] [blame]
garciadeblascf603f52025-06-04 11:57:28 +02001#!/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 -e -o pipefail
17
18HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
19source "${HERE}/../library/functions.sh"
20source "${HERE}/../library/trap.sh"
21source "${HERE}/../library/logging"
22source "${HERE}/../library/track"
23
24source "${HERE}/00-default-install-options.rc"
25[ ! -f "${OSM_HOME_DIR}/user-install-options.rc" ] || source "${OSM_HOME_DIR}/user-install-options.rc"
26source "${CREDENTIALS_DIR}/git_environment.rc"
27
28OSM_HELM_WORK_DIR="/etc/osm/helm"
garciadeblascf603f52025-06-04 11:57:28 +020029KUBECONFIG_AUX_CLUSTER_FILE="${OSM_HOME_DIR}/clusters/kubeconfig-aux-svc.yaml"
30KUBECONFIG_MGMT_CLUSTER_FILE="${OSM_HOME_DIR}/clusters/kubeconfig-mgmt.yaml"
31[ "${HERE}" == "/usr/share/osm-devops/installers" ] || OSM_HELM_UPDATE_DEPENDENCIES="y"
32OSM_GITOPS_ENABLED=${INSTALL_MGMT_CLUSTER:-"y"}
33
34# TODO: move this to a parent script that creates the VM
35mkdir -p "${OSM_HOME_DIR}/clusters"
36if [ -n "${KUBECONFIG_OSM_CLUSTER}" ]; then
37 cp "${KUBECONFIG_OSM_CLUSTER}" "${OSM_HOME_DIR}/clusters/kubeconfig-osm.yaml"
38else
39 cp "${HOME}/.kube/config" "${OSM_HOME_DIR}/clusters/kubeconfig-osm.yaml"
40fi
41
42export KUBECONFIG="${OSM_HOME_DIR}/clusters/kubeconfig-osm.yaml"
garciadeblas8a28f6d2025-06-11 11:11:56 +020043if [ -z "${OSM_K8S_NGINX_IPADDRESS}" ]; then
44 echo "OSM_K8S_NGINX_IPADDRESS is not set, will try to get it from the cluster"
45 OSM_K8S_NGINX_IPADDRESS=$(kubectl get svc ingress-nginx-controller -n ingress-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}' 2>/dev/null)
46fi
47echo "Using OSM_K8S_NGINX_IPADDRESS=${OSM_K8S_NGINX_IPADDRESS}"
garciadeblascf603f52025-06-04 11:57:28 +020048
49# Create folder to store helm values
50sudo mkdir -p ${OSM_HELM_WORK_DIR}
51
52# Saving secrets
53echo "Creating namespace ${OSM_NAMESPACE}"
garciadeblas8a28f6d2025-06-11 11:11:56 +020054kubectl get ns "${OSM_NAMESPACE}" >/dev/null 2>&1 || kubectl create ns "${OSM_NAMESPACE}"
garciadeblascf603f52025-06-04 11:57:28 +020055echo "Saving age keys in OSM cluster"
garciadeblas8a28f6d2025-06-11 11:11:56 +020056kubectl -n ${OSM_NAMESPACE} get secret mgmt-cluster-age-keys >/dev/null 2>&1 || \
garciadeblascf603f52025-06-04 11:57:28 +020057kubectl -n ${OSM_NAMESPACE} create secret generic mgmt-cluster-age-keys --from-file=privkey="${CREDENTIALS_DIR}/age.mgmt.key" --from-file=pubkey="${CREDENTIALS_DIR}/age.mgmt.pub"
58echo "Creating secrets with kubeconfig files"
garciadeblas8a28f6d2025-06-11 11:11:56 +020059if [ -f "${KUBECONFIG_AUX_CLUSTER_FILE}" ]; then
60 kubectl -n ${OSM_NAMESPACE} get secret auxcluster-secret >/dev/null 2>&1 || \
61 kubectl -n ${OSM_NAMESPACE} create secret generic auxcluster-secret --from-file=kubeconfig="${KUBECONFIG_AUX_CLUSTER_FILE}"
62fi
63if [ -f "${KUBECONFIG_MGMT_CLUSTER_FILE}" ]; then
64 kubectl -n ${OSM_NAMESPACE} get secret mgmtcluster-secret >/dev/null 2>&1 || \
65 kubectl -n ${OSM_NAMESPACE} create secret generic mgmtcluster-secret --from-file=kubeconfig="${KUBECONFIG_MGMT_CLUSTER_FILE}"
66fi
garciadeblascf603f52025-06-04 11:57:28 +020067# Update helm dependencies
68[ -n "${OSM_HELM_UPDATE_DEPENDENCIES}" ] && \
69 echo "Updating helm dependencies" && \
70 helm dependency update "${HERE}/helm/osm"
71
72# Generate helm values to be passed with --set
73OSM_HELM_OPTS=""
74# OSM_HELM_OPTS="${OSM_HELM_OPTS} --set nbi.useOsmSecret=false"
75
76# TODO: review if next line is really needed or should be conditional to DOCKER_REGISTRY_URL not empty
77# [ -n "${DOCKER_REGISTRY_URL}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.image.repository=${DOCKER_REGISTRY_URL}${DOCKER_USER}"
78OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.image.repositoryBase=${DOCKER_REGISTRY_URL}${DOCKER_USER}"
79[ ! "$OSM_DOCKER_TAG" == "testing-daily" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set-string global.image.tag=${OSM_DOCKER_TAG}"
80[ ! "$OSM_DOCKER_TAG" == "testing-daily" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set prometheus.server.sidecarContainers.prometheus-config-sidecar.image=${DOCKER_REGISTRY_URL}${DOCKER_USER}/prometheus:${OSM_DOCKER_TAG}"
81
garciadeblas8a28f6d2025-06-11 11:11:56 +020082OSM_BASE_DOMAIN="${OSM_BASE_DOMAIN:-"${OSM_K8S_NGINX_IPADDRESS}.nip.io"}"
83OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.hostname=${OSM_BASE_DOMAIN}"
84OSM_HELM_OPTS="${OSM_HELM_OPTS} --set grafana.ingress.hosts={grafana.${OSM_BASE_DOMAIN}}"
85OSM_HELM_OPTS="${OSM_HELM_OPTS} --set prometheus.server.ingress.hosts={prometheus.${OSM_BASE_DOMAIN}}"
garciadeblas9b3ae032025-08-06 12:09:29 +020086OSM_HELM_OPTS="${OSM_HELM_OPTS} --set airflow.ingress.web.hosts={airflow.${OSM_BASE_DOMAIN}}"
garciadeblas8a28f6d2025-06-11 11:11:56 +020087# OSM_HELM_OPTS="${OSM_HELM_OPTS} --set prometheus.alertmanager.ingress.hosts={alertmanager.${OSM_BASE_DOMAIN}}"
garciadeblascf603f52025-06-04 11:57:28 +020088if [ -z "${OSM_GITOPS_ENABLED}" ]; then
89 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.gitops.enabled=false"
90else
garciadeblas823d8a32025-07-08 10:41:53 +020091 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.gitops.gitBaseUrl=${GIT_BASE_HTTP_URL}"
garciadeblascf603f52025-06-04 11:57:28 +020092 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.gitops.fleetRepoUrl=${FLEET_REPO_HTTP_URL}"
93 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.gitops.swcatalogsRepoUrl=${SW_CATALOGS_REPO_HTTP_URL}"
94 # TODO: evaluate if we need to set two git user names, one for fleet and one for sw-catalogs
garciadeblas823d8a32025-07-08 10:41:53 +020095 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.gitops.gitUser=${GIT_BASE_USERNAME}"
garciadeblascf603f52025-06-04 11:57:28 +020096 AGE_MGMT_PUBKEY=$(tr -d '\n' < ${CREDENTIALS_DIR}/age.mgmt.pub)
97 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.gitops.pubkey=${AGE_MGMT_PUBKEY}"
98fi
99
100if [ -n "${OSM_BEHIND_PROXY}" ]; then
101 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.behindHttpProxy=true"
102 [ -n "${HTTP_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.HTTP_PROXY=\"${HTTP_PROXY}\""
103 [ -n "${HTTPS_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.HTTPS_PROXY=\"${HTTPS_PROXY}\""
104 if [ -n "${NO_PROXY}" ]; then
105 if [[ ! "${NO_PROXY}" =~ .*".svc".* ]]; then
106 NO_PROXY="${NO_PROXY},.svc"
107 fi
108 if [[ ! "${NO_PROXY}" =~ .*".cluster.local".* ]]; then
109 NO_PROXY="${NO_PROXY},.cluster.local"
110 fi
111 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.NO_PROXY=\"${NO_PROXY//,/\,}\""
112 fi
113fi
114
115echo "helm upgrade --install -n $OSM_NAMESPACE --create-namespace $OSM_HELM_RELEASE ${HERE}/helm/osm ${OSM_HELM_OPTS}"
116helm upgrade --install -n $OSM_NAMESPACE --create-namespace $OSM_HELM_RELEASE ${HERE}/helm/osm ${OSM_HELM_OPTS}
117# Override existing values.yaml with the final values.yaml used to install OSM
118helm -n $OSM_NAMESPACE get values $OSM_HELM_RELEASE | sudo tee -a ${OSM_HELM_WORK_DIR}/osm-values.yaml
119
120# Check OSM health state
121echo -e "Checking OSM health state..."
122set +e
123${HERE}/45-osm-health.sh || \
124(echo -e "OSM is not healthy, but will probably converge to a healthy state soon." && \
125echo -e "Check OSM status with: kubectl -n ${OSM_NAMESPACE} get all" && \
126track healthchecks osm_unhealthy didnotconverge)
127track healthchecks after_healthcheck_ok
128set -e
129
130echo -e "Saving OSM enviroment to credentials folder..."
131OSM_HOSTNAME=$(kubectl get --namespace osm -o jsonpath="{.spec.rules[0].host}" ingress nbi-ingress)
garciadeblas8a28f6d2025-06-11 11:11:56 +0200132# OSM_HOSTNAME="nbi.${OSM_BASE_DOMAIN}:443"
garciadeblascf603f52025-06-04 11:57:28 +0200133echo -e "OSM HOSTNAME: ${OSM_HOSTNAME}"
134
135cat << EOF > "${CREDENTIALS_DIR}/osm_environment.rc"
136export OSM_HOSTNAME="${OSM_HOSTNAME}"
137EOF