| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 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. |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 14 | # |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 15 | |
| 16 | function usage(){ |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 17 | [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 18 | echo -e "usage: $0 [OPTIONS]" |
| garciadeblas | 81077ae | 2023-07-03 19:31:15 +0200 | [diff] [blame] | 19 | echo -e "Install OSM" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 20 | echo -e " OPTIONS" |
| garciadeblas | 7f1e104 | 2020-11-30 14:07:03 +0000 | [diff] [blame] | 21 | echo -e " -h / --help: print this help" |
| 22 | echo -e " -y: do not prompt for confirmation, assumes yes" |
| garciadeblas | 2ffcab9 | 2025-11-27 10:32:37 +0100 | [diff] [blame] | 23 | echo -e " -S <gerrit refspec>: use a specific devops gerrit refspec (branch, tag, commit), default is master" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 24 | echo -e " -a <apt proxy url>: use this apt proxy url when downloading apt packages (air-gapped installation)" |
| garciadeblas | b379741 | 2024-06-06 14:26:24 +0200 | [diff] [blame] | 25 | echo -e " -c <kubernetes engine>: use a specific kubernetes engine (options: kubeadm, k3s), default is kubeadm" |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 26 | echo -e " -t <docker tag> specify osm docker tag (default is latest)" |
| 27 | echo -e " -M <KUBECONFIG_FILE>: Kubeconfig of an existing cluster to be used as mgmt cluster instead of OSM cluster" |
| 28 | echo -e " -G <KUBECONFIG_FILE>: Kubeconfig of an existing cluster to be used as auxiliary cluster instead of OSM cluster" |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 29 | echo -e " -O <KUBECONFIG_FILE>: Kubeconfig of an existing cluster to be used as OSM cluster instead of creating a new one from scratch" |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 30 | echo -e " --no-mgmt-cluster: Do not provision a mgmt cluster for cloud-native gitops operations in OSM (NEW in Release SIXTEEN) (by default, it is installed)" |
| 31 | echo -e " --no-aux-cluster: Do not provision an auxiliary cluster for cloud-native gitops operations in OSM (NEW in Release SIXTEEN) (by default, it is installed)" |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 32 | echo -e " -s <namespace> namespace where OSM helm chart will be deployed (default is osm)" |
| garciadeblas | 7f1e104 | 2020-11-30 14:07:03 +0000 | [diff] [blame] | 33 | echo -e " -d <docker registry URL> use docker registry URL instead of dockerhub" |
| 34 | echo -e " -p <docker proxy URL> set docker proxy URL as part of docker CE configuration" |
| garciadeblas | 0b1c75c | 2025-11-11 23:04:39 +0100 | [diff] [blame] | 35 | echo -e " -m <MODULE>: module to test a specific docker image (NG-UI, NBI, LCM, RO, MON) (can be used several times)" |
| 36 | echo -e " -T <docker tag> use specific docker tag for the module specified with option -m" |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 37 | echo -e " -U <docker user>: specify docker user to use when pulling images from a private registry" |
| 38 | echo -e " -D <devops path>: use particular devops installation path" |
| 39 | echo -e " -e <external IP>: set the external IP address of the OSM cluster (default is empty, which means autodetect)" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 40 | echo -e " --debug: debug mode" |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 41 | [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 42 | } |
| 43 | |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 44 | HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")") |
| 45 | OSM_DEVOPS="${OSM_DEVOPS:-"${HERE}/.."}" |
| 46 | source $OSM_DEVOPS/library/all_funcs |
| calvinosanc1 | 0c82da0 | 2020-08-17 11:45:15 +0200 | [diff] [blame] | 47 | |
| garciadeblas | 31dd8bb | 2025-07-08 14:54:24 +0200 | [diff] [blame] | 48 | echo "Load default options and export user installation options" |
| 49 | source $OSM_DEVOPS/installers/00-default-install-options.rc |
| beierlm | 2ce2b00 | 2021-12-07 16:02:22 -0500 | [diff] [blame] | 50 | |
| vijaynag | 8339ed2 | 2019-07-25 17:10:58 +0530 | [diff] [blame] | 51 | RE_CHECK='^[a-z0-9]([-a-z0-9]*[a-z0-9])?$' |
| garciadeblas | 2ffcab9 | 2025-11-27 10:32:37 +0100 | [diff] [blame] | 52 | while getopts ":a:c:e:S:D:s:t:U:d:p:m:T:M:G:O:-: hy" o; do |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 53 | case "${o}" in |
| garciadeblas | 2ffcab9 | 2025-11-27 10:32:37 +0100 | [diff] [blame] | 54 | S) |
| 55 | DEVOPS_GERRIT_REFSPEC="${OPTARG}" |
| 56 | ;; |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 57 | a) |
| 58 | APT_PROXY_URL=${OPTARG} |
| 59 | ;; |
| garciadeblas | 250b0b6 | 2024-01-22 13:30:59 +0100 | [diff] [blame] | 60 | c) |
| 61 | K8S_CLUSTER_ENGINE=${OPTARG} |
| 62 | [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ] && continue |
| 63 | [ "${K8S_CLUSTER_ENGINE}" == "k3s" ] && continue |
| garciadeblas | 250b0b6 | 2024-01-22 13:30:59 +0100 | [diff] [blame] | 64 | echo -e "Invalid argument for -c : ' ${K8S_CLUSTER_ENGINE}'\n" >&2 |
| 65 | usage && exit 1 |
| 66 | ;; |
| garciadeblas | e3a84a5 | 2024-09-27 11:34:55 +0200 | [diff] [blame] | 67 | e) |
| 68 | OSM_K8S_EXTERNAL_IP="${OPTARG}" |
| 69 | ;; |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 70 | D) |
| 71 | OSM_DEVOPS="${OPTARG}" |
| 72 | ;; |
| garciadeblas | 25e87d2 | 2020-01-31 14:27:29 +0100 | [diff] [blame] | 73 | s) |
| garciadeblas | 325032a | 2023-04-13 18:07:44 +0200 | [diff] [blame] | 74 | OSM_NAMESPACE="${OPTARG}" && [[ ! "${OPTARG}" =~ $RE_CHECK ]] && echo "Namespace $OPTARG is invalid. Regex used for validation is $RE_CHECK" && exit 0 |
| garciadeblas | 25e87d2 | 2020-01-31 14:27:29 +0100 | [diff] [blame] | 75 | ;; |
| 76 | t) |
| 77 | OSM_DOCKER_TAG="${OPTARG}" |
| Antonio Marsico | f4ce57c | 2020-04-23 12:06:19 +0200 | [diff] [blame] | 78 | REPO_ARGS+=(-t "$OSM_DOCKER_TAG") |
| garciadeblas | 25e87d2 | 2020-01-31 14:27:29 +0100 | [diff] [blame] | 79 | ;; |
| 80 | U) |
| 81 | DOCKER_USER="${OPTARG}" |
| 82 | ;; |
| garciadeblas | 7f1e104 | 2020-11-30 14:07:03 +0000 | [diff] [blame] | 83 | d) |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 84 | parse_docker_registry_url "${OPTARG}" |
| garciadeblas | 7f1e104 | 2020-11-30 14:07:03 +0000 | [diff] [blame] | 85 | ;; |
| 86 | p) |
| 87 | DOCKER_PROXY_URL="${OPTARG}" |
| 88 | ;; |
| garciadeblas | 0b1c75c | 2025-11-11 23:04:39 +0100 | [diff] [blame] | 89 | m) |
| garciadeblas | 0b37235 | 2025-12-15 12:35:49 +0100 | [diff] [blame] | 90 | [ "${OPTARG}" == "NG-UI" ] && MODULES_FOR_TESTING="NGUI $MODULES_FOR_TESTING" && continue |
| 91 | [ "${OPTARG}" == "NBI" ] && MODULES_FOR_TESTING="NBI $MODULES_FOR_TESTING" && continue |
| 92 | [ "${OPTARG}" == "LCM" ] && MODULES_FOR_TESTING="LCM $MODULES_FOR_TESTING" && continue |
| 93 | [ "${OPTARG}" == "RO" ] && MODULES_FOR_TESTING="RO $MODULES_FOR_TESTING" && continue |
| 94 | [ "${OPTARG}" == "MON" ] && MODULES_FOR_TESTING="MON $MODULES_FOR_TESTING" && continue |
| 95 | [ "${OPTARG}" == "NG-SA" ] && MODULES_FOR_TESTING="NG-SA $MODULES_FOR_TESTING" && continue |
| 96 | [ "${OPTARG}" == "osmclient" ] && MODULES_FOR_TESTING="osmclient $MODULES_FOR_TESTING" && continue |
| 97 | [ "${OPTARG}" == "prometheus" ] && MODULES_FOR_TESTING="prometheus $MODULES_FOR_TESTING" && continue |
| 98 | [ "${OPTARG}" == "webhookTranslator" ] && MODULES_FOR_TESTING="webhookTranslator $MODULES_FOR_TESTING" && continue |
| 99 | [ "${OPTARG}" == "keystone" ] && MODULES_FOR_TESTING="keystone $MODULES_FOR_TESTING" && continue |
| garciadeblas | 0b1c75c | 2025-11-11 23:04:39 +0100 | [diff] [blame] | 100 | ;; |
| garciadeblas | 7f1e104 | 2020-11-30 14:07:03 +0000 | [diff] [blame] | 101 | T) |
| 102 | MODULE_DOCKER_TAG="${OPTARG}" |
| 103 | ;; |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 104 | M) |
| 105 | KUBECONFIG_MGMT_CLUSTER="${OPTARG}" |
| 106 | ;; |
| 107 | G) |
| 108 | KUBECONFIG_AUX_CLUSTER="${OPTARG}" |
| 109 | ;; |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 110 | O) |
| 111 | KUBECONFIG_OSM_CLUSTER="${OPTARG}" |
| 112 | ;; |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 113 | -) |
| 114 | [ "${OPTARG}" == "help" ] && usage && exit 0 |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 115 | [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="--debug" && continue |
| garciadeblas | 8d8cd99 | 2024-05-21 16:04:14 +0200 | [diff] [blame] | 116 | [ "${OPTARG}" == "no-mgmt-cluster" ] && INSTALL_MGMT_CLUSTER="" && continue |
| 117 | [ "${OPTARG}" == "no-aux-cluster" ] && INSTALL_AUX_CLUSTER="" && continue |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 118 | if [[ "${OPTARG}" == "client-version" ]]; then |
| 119 | OSM_CLIENT_VERSION="${!OPTIND}"; OPTIND=$((OPTIND + 1)) |
| 120 | continue |
| 121 | fi |
| 122 | if [[ "${OPTARG}" == "im-version" ]]; then |
| 123 | OSM_IM_VERSION="${!OPTIND}"; OPTIND=$((OPTIND + 1)) |
| 124 | continue |
| 125 | fi |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 126 | echo -e "Invalid option: '--$OPTARG'\n" >&2 |
| 127 | usage && exit 1 |
| 128 | ;; |
| garciadeblas | 25e87d2 | 2020-01-31 14:27:29 +0100 | [diff] [blame] | 129 | :) |
| 130 | echo "Option -$OPTARG requires an argument" >&2 |
| 131 | usage && exit 1 |
| 132 | ;; |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 133 | \?) |
| 134 | echo -e "Invalid option: '-$OPTARG'\n" >&2 |
| 135 | usage && exit 1 |
| 136 | ;; |
| garciadeblas | 25e87d2 | 2020-01-31 14:27:29 +0100 | [diff] [blame] | 137 | h) |
| 138 | usage && exit 0 |
| 139 | ;; |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 140 | y) |
| 141 | ASSUME_YES="y" |
| 142 | ;; |
| 143 | *) |
| 144 | usage && exit 1 |
| 145 | ;; |
| 146 | esac |
| 147 | done |
| 148 | |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 149 | |
| garciadeblas | 0bc8752 | 2021-10-20 22:16:17 +0200 | [diff] [blame] | 150 | [ -z "${DEBUG_INSTALL}" ] || DEBUG Debug is on |
| garciadeblas | 28d71bd | 2023-06-07 23:06:50 +0200 | [diff] [blame] | 151 | # Installation starts here |
| 152 | |
| 153 | # Get README and create OSM_TRACK_INSTALLATION_ID |
| garciadeblas | 965aafe | 2025-06-19 10:07:57 +0200 | [diff] [blame] | 154 | curl -s https://osm-download.etsi.org/ftp/osm-18.0-eighteen/README.txt > /dev/null 2>&1 |
| garciadeblas | 28d71bd | 2023-06-07 23:06:50 +0200 | [diff] [blame] | 155 | export OSM_TRACK_INSTALLATION_ID="$(date +%s)-$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)" |
| 156 | |
| 157 | # Get OS info to be tracked |
| 158 | os_distro=$(lsb_release -i 2>/dev/null | awk '{print $3}') |
| 159 | echo $os_distro |
| 160 | os_release=$(lsb_release -r 2>/dev/null | awk '{print $2}') |
| 161 | echo $os_release |
| 162 | os_info="${os_distro}_${os_release}" |
| 163 | os_info="${os_info// /_}" |
| 164 | |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 165 | # Initial checks: proxy, root user, proceed |
| 166 | check_osm_behind_proxy |
| 167 | track start release $RELEASE none none docker_tag $OSM_DOCKER_TAG none none installation_type Default none none os_info $os_info none none |
| 168 | track checks checkingroot_ok |
| 169 | [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges." |
| 170 | track checks noroot_ok |
| 171 | ask_proceed |
| 172 | track checks proceed_ok |
| 173 | |
| 174 | # Setup prerequisites |
| 175 | echo "Setting up external IP address" |
| 176 | setup_external_ip |
| 177 | [ -n "$APT_PROXY_URL" ] && echo "Configuring APT proxy" && configure_apt_proxy $APT_PROXY_URL |
| 178 | track prereq prereqok_ok |
| 179 | |
| 180 | # Export installation options |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 181 | $OSM_DEVOPS/installers/01-export-osm-install-options.sh || FATAL_TRACK exportinstallopts "01-export-osm-install-options.sh failed" |
| 182 | track exportinstallopts exportinstallopts_ok |
| 183 | |
| 184 | # Setup Client tools |
| 185 | echo "Setup CLI tools for mgmt and aux cluster" |
| 186 | $OSM_DEVOPS/installers/10-install-client-tools.sh || FATAL_TRACK installclitools "10-install-client-tools.sh failed" |
| 187 | track installclitools installclitools_ok |
| 188 | |
| 189 | # Install K8s cluster where all OSM components will be deployed |
| 190 | echo "Installing K8s cluster ..." |
| 191 | source "${HERE}/../library/utils.sh" |
| 192 | # setup_external_ip |
| 193 | export OSM_DEFAULT_IP |
| 194 | export OSM_K8S_EXTERNAL_IP |
| 195 | $OSM_DEVOPS/installers/15-install-k8s-cluster.sh || FATAL_TRACK k8scluster "15-install-k8s-cluster.sh" |
| 196 | track k8scluster k8scluster_ok |
| 197 | |
| 198 | # Deploy auxiliary services |
| 199 | if [ -n "${INSTALL_AUX_CLUSTER}" ]; then |
| 200 | echo "Deploy auxiliary services (Gitea, S3)" |
| 201 | $OSM_DEVOPS/installers/20-deploy-aux-svc-cluster.sh || FATAL_TRACK deployauxsvc "20-deploy-aux-svc-cluster.sh failed" |
| 202 | else |
| 203 | echo "Skipping deployment of auxiliary services." |
| 204 | echo "Using existing git credentials and repos defined in ${CREDENTIALS_DIR}/git_environment.rc" |
| 205 | # cat << EOF > "${CREDENTIALS_DIR}/git_environment.rc" |
| garciadeblas | 823d8a3 | 2025-07-08 10:41:53 +0200 | [diff] [blame] | 206 | # export GIT_BASE_HTTP_URL="${GITEA_HTTP_URL}" |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 207 | # export FLEET_REPO_HTTP_URL="${FLEET_REPO_HTTP_URL}" |
| 208 | # export FLEET_REPO_SSH_URL="${FLEET_REPO_SSH_URL}" |
| 209 | # export FLEET_REPO_GIT_USERNAME="${FLEET_REPO_GIT_USERNAME}" |
| 210 | # export FLEET_REPO_GIT_USER_PASS='${FLEET_REPO_GIT_USER_PASS}' |
| 211 | # export SW_CATALOGS_REPO_HTTP_URL="${SW_CATALOGS_REPO_HTTP_URL}" |
| 212 | # export SW_CATALOGS_REPO_SSH_URL="${SW_CATALOGS_REPO_SSH_URL}" |
| 213 | # export SW_CATALOGS_REPO_GIT_USERNAME="${SW_CATALOGS_REPO_GIT_USERNAME}" |
| 214 | # export SW_CATALOGS_REPO_GIT_USER_PASS='${SW_CATALOGS_REPO_GIT_USER_PASS}' |
| 215 | # EOF |
| 216 | fi |
| 217 | track deployauxsvc deployauxsvc_ok |
| 218 | |
| 219 | # Deploy mgmt services |
| 220 | if [ -n "${INSTALL_MGMT_CLUSTER}" ]; then |
| 221 | echo "Deploy mgmt cluster (Flux, etc.)" |
| 222 | $OSM_DEVOPS/installers/30-deploy-mgmt-cluster.sh || FATAL_TRACK mgmtcluster "30-deploy-mgmt-cluster.sh failed" |
| 223 | else |
| 224 | echo "Skipping deployment of mgmt cluster" |
| 225 | # TODO: write env variables to files" |
| 226 | fi |
| 227 | track mgmtcluster mgmtcluster_ok |
| 228 | |
| 229 | # Deploy OSM (OSM helm chart) |
| 230 | echo "Deploy OSM helm chart" |
| 231 | export OSM_K8S_EXTERNAL_IP |
| 232 | $OSM_DEVOPS/installers/40-deploy-osm.sh || FATAL_TRACK deployosm "40-deploy-osm.sh failed" |
| 233 | track deploy_osm deploy_osm_ok |
| 234 | |
| 235 | # Provision OSM |
| 236 | echo -e "Adding local K8s cluster _system-osm-k8s to OSM ..." |
| 237 | $OSM_DEVOPS/installers/50-provision-osm.sh || FATAL_TRACK provision-osm "50-provision-osm.sh failed" |
| 238 | track provisionosm provisionosm_ok |
| 239 | |
| garciadeblas | 965aafe | 2025-06-19 10:07:57 +0200 | [diff] [blame] | 240 | curl -s https://osm-download.etsi.org/ftp/osm-18.0-eighteen/README2.txt > /dev/null 2>&1 |
| garciadeblas | cf603f5 | 2025-06-04 11:57:28 +0200 | [diff] [blame] | 241 | track end |
| 242 | |
| 243 | echo "Credentials stored under ${CREDENTIALS_DIR}" |
| 244 | echo "Git repos for OSM declarative framework stored under ${WORK_REPOS_DIR}" |
| 245 | echo "Kubeconfigs of the aux-svc cluster, mgmt cluster and OSM cluster stored under ${OSM_HOME_DIR}/clusters" |
| garciadeblas | 2fdfb38 | 2025-04-29 14:54:23 +0200 | [diff] [blame] | 246 | echo -e "\nDONE" |
| 247 | exit 0 |