blob: 299f3dec585e56f117006344ff4083075ddece48 [file] [log] [blame]
garciadeblasd8bc5c32018-05-09 17:37:56 +02001#!/bin/bash
garciadeblasd8bc5c32018-05-09 17:37:56 +02002#
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.
garciadeblas0bc87522021-10-20 22:16:17 +020014#
garciadeblasd8bc5c32018-05-09 17:37:56 +020015
16function usage(){
garciadeblas0bc87522021-10-20 22:16:17 +020017 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblasd8bc5c32018-05-09 17:37:56 +020018 echo -e "usage: $0 [OPTIONS]"
garciadeblas81077ae2023-07-03 19:31:15 +020019 echo -e "Install OSM"
garciadeblasd8bc5c32018-05-09 17:37:56 +020020 echo -e " OPTIONS"
garciadeblas7f1e1042020-11-30 14:07:03 +000021 echo -e " -h / --help: print this help"
22 echo -e " -y: do not prompt for confirmation, assumes yes"
garciadeblas2ffcab92025-11-27 10:32:37 +010023 echo -e " -S <gerrit refspec>: use a specific devops gerrit refspec (branch, tag, commit), default is master"
garciadeblas0bc87522021-10-20 22:16:17 +020024 echo -e " -a <apt proxy url>: use this apt proxy url when downloading apt packages (air-gapped installation)"
garciadeblasb3797412024-06-06 14:26:24 +020025 echo -e " -c <kubernetes engine>: use a specific kubernetes engine (options: kubeadm, k3s), default is kubeadm"
garciadeblas8d8cd992024-05-21 16:04:14 +020026 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"
garciadeblascf603f52025-06-04 11:57:28 +020029 echo -e " -O <KUBECONFIG_FILE>: Kubeconfig of an existing cluster to be used as OSM cluster instead of creating a new one from scratch"
garciadeblas8d8cd992024-05-21 16:04:14 +020030 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)"
garciadeblascf603f52025-06-04 11:57:28 +020032 echo -e " -s <namespace> namespace where OSM helm chart will be deployed (default is osm)"
garciadeblas7f1e1042020-11-30 14:07:03 +000033 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"
garciadeblas0b1c75c2025-11-11 23:04:39 +010035 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"
garciadeblascf603f52025-06-04 11:57:28 +020037 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)"
garciadeblas0bc87522021-10-20 22:16:17 +020040 echo -e " --debug: debug mode"
garciadeblas0bc87522021-10-20 22:16:17 +020041 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblasd8bc5c32018-05-09 17:37:56 +020042}
43
garciadeblascf603f52025-06-04 11:57:28 +020044HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
45OSM_DEVOPS="${OSM_DEVOPS:-"${HERE}/.."}"
46source $OSM_DEVOPS/library/all_funcs
calvinosanc10c82da02020-08-17 11:45:15 +020047
garciadeblas31dd8bb2025-07-08 14:54:24 +020048echo "Load default options and export user installation options"
49source $OSM_DEVOPS/installers/00-default-install-options.rc
beierlm2ce2b002021-12-07 16:02:22 -050050
vijaynag8339ed22019-07-25 17:10:58 +053051RE_CHECK='^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'
garciadeblas2ffcab92025-11-27 10:32:37 +010052while getopts ":a:c:e:S:D:s:t:U:d:p:m:T:M:G:O:-: hy" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +020053 case "${o}" in
garciadeblas2ffcab92025-11-27 10:32:37 +010054 S)
55 DEVOPS_GERRIT_REFSPEC="${OPTARG}"
56 ;;
garciadeblas0bc87522021-10-20 22:16:17 +020057 a)
58 APT_PROXY_URL=${OPTARG}
59 ;;
garciadeblas250b0b62024-01-22 13:30:59 +010060 c)
61 K8S_CLUSTER_ENGINE=${OPTARG}
62 [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ] && continue
63 [ "${K8S_CLUSTER_ENGINE}" == "k3s" ] && continue
garciadeblas250b0b62024-01-22 13:30:59 +010064 echo -e "Invalid argument for -c : ' ${K8S_CLUSTER_ENGINE}'\n" >&2
65 usage && exit 1
66 ;;
garciadeblase3a84a52024-09-27 11:34:55 +020067 e)
68 OSM_K8S_EXTERNAL_IP="${OPTARG}"
69 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +020070 D)
71 OSM_DEVOPS="${OPTARG}"
72 ;;
garciadeblas25e87d22020-01-31 14:27:29 +010073 s)
garciadeblas325032a2023-04-13 18:07:44 +020074 OSM_NAMESPACE="${OPTARG}" && [[ ! "${OPTARG}" =~ $RE_CHECK ]] && echo "Namespace $OPTARG is invalid. Regex used for validation is $RE_CHECK" && exit 0
garciadeblas25e87d22020-01-31 14:27:29 +010075 ;;
76 t)
77 OSM_DOCKER_TAG="${OPTARG}"
Antonio Marsicof4ce57c2020-04-23 12:06:19 +020078 REPO_ARGS+=(-t "$OSM_DOCKER_TAG")
garciadeblas25e87d22020-01-31 14:27:29 +010079 ;;
80 U)
81 DOCKER_USER="${OPTARG}"
82 ;;
garciadeblas7f1e1042020-11-30 14:07:03 +000083 d)
garciadeblascf603f52025-06-04 11:57:28 +020084 parse_docker_registry_url "${OPTARG}"
garciadeblas7f1e1042020-11-30 14:07:03 +000085 ;;
86 p)
87 DOCKER_PROXY_URL="${OPTARG}"
88 ;;
garciadeblas0b1c75c2025-11-11 23:04:39 +010089 m)
garciadeblas0b372352025-12-15 12:35:49 +010090 [ "${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
garciadeblas0b1c75c2025-11-11 23:04:39 +0100100 ;;
garciadeblas7f1e1042020-11-30 14:07:03 +0000101 T)
102 MODULE_DOCKER_TAG="${OPTARG}"
103 ;;
garciadeblas8d8cd992024-05-21 16:04:14 +0200104 M)
105 KUBECONFIG_MGMT_CLUSTER="${OPTARG}"
106 ;;
107 G)
108 KUBECONFIG_AUX_CLUSTER="${OPTARG}"
109 ;;
garciadeblascf603f52025-06-04 11:57:28 +0200110 O)
111 KUBECONFIG_OSM_CLUSTER="${OPTARG}"
112 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200113 -)
114 [ "${OPTARG}" == "help" ] && usage && exit 0
garciadeblas0bc87522021-10-20 22:16:17 +0200115 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="--debug" && continue
garciadeblas8d8cd992024-05-21 16:04:14 +0200116 [ "${OPTARG}" == "no-mgmt-cluster" ] && INSTALL_MGMT_CLUSTER="" && continue
117 [ "${OPTARG}" == "no-aux-cluster" ] && INSTALL_AUX_CLUSTER="" && continue
garciadeblascf603f52025-06-04 11:57:28 +0200118 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
garciadeblasd8bc5c32018-05-09 17:37:56 +0200126 echo -e "Invalid option: '--$OPTARG'\n" >&2
127 usage && exit 1
128 ;;
garciadeblas25e87d22020-01-31 14:27:29 +0100129 :)
130 echo "Option -$OPTARG requires an argument" >&2
131 usage && exit 1
132 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200133 \?)
134 echo -e "Invalid option: '-$OPTARG'\n" >&2
135 usage && exit 1
136 ;;
garciadeblas25e87d22020-01-31 14:27:29 +0100137 h)
138 usage && exit 0
139 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200140 y)
141 ASSUME_YES="y"
142 ;;
143 *)
144 usage && exit 1
145 ;;
146 esac
147done
148
garciadeblas6c66abf2018-05-16 14:46:19 +0200149
garciadeblas0bc87522021-10-20 22:16:17 +0200150[ -z "${DEBUG_INSTALL}" ] || DEBUG Debug is on
garciadeblas28d71bd2023-06-07 23:06:50 +0200151# Installation starts here
152
153# Get README and create OSM_TRACK_INSTALLATION_ID
garciadeblas965aafe2025-06-19 10:07:57 +0200154curl -s https://osm-download.etsi.org/ftp/osm-18.0-eighteen/README.txt > /dev/null 2>&1
garciadeblas28d71bd2023-06-07 23:06:50 +0200155export 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
158os_distro=$(lsb_release -i 2>/dev/null | awk '{print $3}')
159echo $os_distro
160os_release=$(lsb_release -r 2>/dev/null | awk '{print $2}')
161echo $os_release
162os_info="${os_distro}_${os_release}"
163os_info="${os_info// /_}"
164
garciadeblascf603f52025-06-04 11:57:28 +0200165# Initial checks: proxy, root user, proceed
166check_osm_behind_proxy
167track start release $RELEASE none none docker_tag $OSM_DOCKER_TAG none none installation_type Default none none os_info $os_info none none
168track 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."
170track checks noroot_ok
171ask_proceed
172track checks proceed_ok
173
174# Setup prerequisites
175echo "Setting up external IP address"
176setup_external_ip
177[ -n "$APT_PROXY_URL" ] && echo "Configuring APT proxy" && configure_apt_proxy $APT_PROXY_URL
178track prereq prereqok_ok
179
180# Export installation options
garciadeblascf603f52025-06-04 11:57:28 +0200181$OSM_DEVOPS/installers/01-export-osm-install-options.sh || FATAL_TRACK exportinstallopts "01-export-osm-install-options.sh failed"
182track exportinstallopts exportinstallopts_ok
183
184# Setup Client tools
185echo "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"
187track installclitools installclitools_ok
188
189# Install K8s cluster where all OSM components will be deployed
190echo "Installing K8s cluster ..."
191source "${HERE}/../library/utils.sh"
192# setup_external_ip
193export OSM_DEFAULT_IP
194export OSM_K8S_EXTERNAL_IP
195$OSM_DEVOPS/installers/15-install-k8s-cluster.sh || FATAL_TRACK k8scluster "15-install-k8s-cluster.sh"
196track k8scluster k8scluster_ok
197
198# Deploy auxiliary services
199if [ -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"
202else
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"
garciadeblas823d8a32025-07-08 10:41:53 +0200206# export GIT_BASE_HTTP_URL="${GITEA_HTTP_URL}"
garciadeblascf603f52025-06-04 11:57:28 +0200207# 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
216fi
217track deployauxsvc deployauxsvc_ok
218
219# Deploy mgmt services
220if [ -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"
223else
224 echo "Skipping deployment of mgmt cluster"
225 # TODO: write env variables to files"
226fi
227track mgmtcluster mgmtcluster_ok
228
229# Deploy OSM (OSM helm chart)
230echo "Deploy OSM helm chart"
231export OSM_K8S_EXTERNAL_IP
232$OSM_DEVOPS/installers/40-deploy-osm.sh || FATAL_TRACK deployosm "40-deploy-osm.sh failed"
233track deploy_osm deploy_osm_ok
234
235# Provision OSM
236echo -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"
238track provisionosm provisionosm_ok
239
garciadeblas965aafe2025-06-19 10:07:57 +0200240curl -s https://osm-download.etsi.org/ftp/osm-18.0-eighteen/README2.txt > /dev/null 2>&1
garciadeblascf603f52025-06-04 11:57:28 +0200241track end
242
243echo "Credentials stored under ${CREDENTIALS_DIR}"
244echo "Git repos for OSM declarative framework stored under ${WORK_REPOS_DIR}"
245echo "Kubeconfigs of the aux-svc cluster, mgmt cluster and OSM cluster stored under ${OSM_HOME_DIR}/clusters"
garciadeblas2fdfb382025-04-29 14:54:23 +0200246echo -e "\nDONE"
247exit 0