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