blob: 589fffab63db5182131b6e79ebe2282c60c6074b [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"
garciadeblasd8bc5c32018-05-09 17:37:56 +020023 echo -e " -r <repo>: use specified repository name for osm packages"
khelifibca83312025-06-17 16:06:23 +020024 echo -e " -R <release>: use specified release for osm binaries (deb packages, ...)"
garciadeblasd8bc5c32018-05-09 17:37:56 +020025 echo -e " -u <repo base>: use specified repository url for osm packages"
26 echo -e " -k <repo key>: use specified repository public key url"
garciadeblas0bc87522021-10-20 22:16:17 +020027 echo -e " -a <apt proxy url>: use this apt proxy url when downloading apt packages (air-gapped installation)"
garciadeblasb3797412024-06-06 14:26:24 +020028 echo -e " -c <kubernetes engine>: use a specific kubernetes engine (options: kubeadm, k3s), default is kubeadm"
garciadeblas8d8cd992024-05-21 16:04:14 +020029 echo -e " -t <docker tag> specify osm docker tag (default is latest)"
30 echo -e " -M <KUBECONFIG_FILE>: Kubeconfig of an existing cluster to be used as mgmt cluster instead of OSM cluster"
31 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 +020032 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 +020033 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)"
34 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 +020035 echo -e " -s <namespace> namespace where OSM helm chart will be deployed (default is osm)"
garciadeblas7f1e1042020-11-30 14:07:03 +000036 echo -e " -d <docker registry URL> use docker registry URL instead of dockerhub"
37 echo -e " -p <docker proxy URL> set docker proxy URL as part of docker CE configuration"
garciadeblas0b1c75c2025-11-11 23:04:39 +010038 echo -e " -m <MODULE>: module to test a specific docker image (NG-UI, NBI, LCM, RO, MON) (can be used several times)"
39 echo -e " -T <docker tag> use specific docker tag for the module specified with option -m"
garciadeblascf603f52025-06-04 11:57:28 +020040 echo -e " -U <docker user>: specify docker user to use when pulling images from a private registry"
41 echo -e " -D <devops path>: use particular devops installation path"
42 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 +020043 echo -e " --debug: debug mode"
garciadeblas0bc87522021-10-20 22:16:17 +020044 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblasd8bc5c32018-05-09 17:37:56 +020045}
46
garciadeblascf603f52025-06-04 11:57:28 +020047HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
48OSM_DEVOPS="${OSM_DEVOPS:-"${HERE}/.."}"
49source $OSM_DEVOPS/library/all_funcs
calvinosanc10c82da02020-08-17 11:45:15 +020050
garciadeblas31dd8bb2025-07-08 14:54:24 +020051echo "Load default options and export user installation options"
52source $OSM_DEVOPS/installers/00-default-install-options.rc
beierlm2ce2b002021-12-07 16:02:22 -050053
vijaynag8339ed22019-07-25 17:10:58 +053054RE_CHECK='^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'
garciadeblas0b1c75c2025-11-11 23:04:39 +010055while getopts ":a:c:e:r:k:u:R:D:s:t:U:d:p:m:T:M:G:O:-: hy" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +020056 case "${o}" in
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 r)
Mike Marchettib8420852018-09-13 13:45:06 -040071 REPOSITORY="${OPTARG}"
72 REPO_ARGS+=(-r "$REPOSITORY")
garciadeblasd8bc5c32018-05-09 17:37:56 +020073 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +020074 k)
Mike Marchettib8420852018-09-13 13:45:06 -040075 REPOSITORY_KEY="${OPTARG}"
76 REPO_ARGS+=(-k "$REPOSITORY_KEY")
garciadeblasd8bc5c32018-05-09 17:37:56 +020077 ;;
78 u)
Mike Marchettib8420852018-09-13 13:45:06 -040079 REPOSITORY_BASE="${OPTARG}"
80 REPO_ARGS+=(-u "$REPOSITORY_BASE")
garciadeblasd8bc5c32018-05-09 17:37:56 +020081 ;;
garciadeblas25e87d22020-01-31 14:27:29 +010082 R)
83 RELEASE="${OPTARG}"
84 REPO_ARGS+=(-R "$RELEASE")
garciadeblas0d45bc82018-11-19 14:25:13 +010085 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +020086 D)
87 OSM_DEVOPS="${OPTARG}"
88 ;;
garciadeblas25e87d22020-01-31 14:27:29 +010089 s)
garciadeblas325032a2023-04-13 18:07:44 +020090 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 +010091 ;;
92 t)
93 OSM_DOCKER_TAG="${OPTARG}"
Antonio Marsicof4ce57c2020-04-23 12:06:19 +020094 REPO_ARGS+=(-t "$OSM_DOCKER_TAG")
garciadeblas25e87d22020-01-31 14:27:29 +010095 ;;
96 U)
97 DOCKER_USER="${OPTARG}"
98 ;;
garciadeblas7f1e1042020-11-30 14:07:03 +000099 d)
garciadeblascf603f52025-06-04 11:57:28 +0200100 parse_docker_registry_url "${OPTARG}"
garciadeblas7f1e1042020-11-30 14:07:03 +0000101 ;;
102 p)
103 DOCKER_PROXY_URL="${OPTARG}"
104 ;;
garciadeblas0b1c75c2025-11-11 23:04:39 +0100105 m)
106 [ "${OPTARG}" == "NG-UI" ] && MODULES_FOR_TESTING="$MODULES_FOR_TESTING NGUI" && continue
107 [ "${OPTARG}" == "NBI" ] && MODULES_FOR_TESTING="$MODULES_FOR_TESTING NBI" && continue
108 [ "${OPTARG}" == "LCM" ] && MODULES_FOR_TESTING="$MODULES_FOR_TESTING LCM" && continue
109 [ "${OPTARG}" == "RO" ] && MODULES_FOR_TESTING="$MODULES_FOR_TESTING RO" && continue
110 [ "${OPTARG}" == "MON" ] && MODULES_FOR_TESTING="$MODULES_FOR_TESTING MON" && continue
111 [ "${OPTARG}" == "NG-SA" ] && MODULES_FOR_TESTING="$MODULES_FOR_TESTING NG-SA" && continue
112 [ "${OPTARG}" == "osmclient" ] && MODULES_FOR_TESTING="$MODULES_FOR_TESTING osmclient" && continue
113 [ "${OPTARG}" == "prometheus" ] && MODULES_FOR_TESTING="$MODULES_FOR_TESTING prometheus" && continue
114 [ "${OPTARG}" == "webhookTranslator" ] && MODULES_FOR_TESTING="$MODULES_FOR_TESTING webhookTranslator" && continue
115 [ "${OPTARG}" == "keystone" ] && MODULES_FOR_TESTING="$MODULES_FOR_TESTING keystone" && continue
116 ;;
garciadeblas7f1e1042020-11-30 14:07:03 +0000117 T)
118 MODULE_DOCKER_TAG="${OPTARG}"
119 ;;
garciadeblas8d8cd992024-05-21 16:04:14 +0200120 M)
121 KUBECONFIG_MGMT_CLUSTER="${OPTARG}"
122 ;;
123 G)
124 KUBECONFIG_AUX_CLUSTER="${OPTARG}"
125 ;;
garciadeblascf603f52025-06-04 11:57:28 +0200126 O)
127 KUBECONFIG_OSM_CLUSTER="${OPTARG}"
128 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200129 -)
130 [ "${OPTARG}" == "help" ] && usage && exit 0
garciadeblas0bc87522021-10-20 22:16:17 +0200131 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="--debug" && continue
garciadeblas8d8cd992024-05-21 16:04:14 +0200132 [ "${OPTARG}" == "no-mgmt-cluster" ] && INSTALL_MGMT_CLUSTER="" && continue
133 [ "${OPTARG}" == "no-aux-cluster" ] && INSTALL_AUX_CLUSTER="" && continue
garciadeblascf603f52025-06-04 11:57:28 +0200134 if [[ "${OPTARG}" == "client-version" ]]; then
135 OSM_CLIENT_VERSION="${!OPTIND}"; OPTIND=$((OPTIND + 1))
136 continue
137 fi
138 if [[ "${OPTARG}" == "im-version" ]]; then
139 OSM_IM_VERSION="${!OPTIND}"; OPTIND=$((OPTIND + 1))
140 continue
141 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200142 echo -e "Invalid option: '--$OPTARG'\n" >&2
143 usage && exit 1
144 ;;
garciadeblas25e87d22020-01-31 14:27:29 +0100145 :)
146 echo "Option -$OPTARG requires an argument" >&2
147 usage && exit 1
148 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200149 \?)
150 echo -e "Invalid option: '-$OPTARG'\n" >&2
151 usage && exit 1
152 ;;
garciadeblas25e87d22020-01-31 14:27:29 +0100153 h)
154 usage && exit 0
155 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200156 y)
157 ASSUME_YES="y"
158 ;;
159 *)
160 usage && exit 1
161 ;;
162 esac
163done
164
garciadeblas6c66abf2018-05-16 14:46:19 +0200165
garciadeblas0bc87522021-10-20 22:16:17 +0200166[ -z "${DEBUG_INSTALL}" ] || DEBUG Debug is on
garciadeblas28d71bd2023-06-07 23:06:50 +0200167# Installation starts here
168
169# Get README and create OSM_TRACK_INSTALLATION_ID
garciadeblas965aafe2025-06-19 10:07:57 +0200170curl -s https://osm-download.etsi.org/ftp/osm-18.0-eighteen/README.txt > /dev/null 2>&1
garciadeblas28d71bd2023-06-07 23:06:50 +0200171export OSM_TRACK_INSTALLATION_ID="$(date +%s)-$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)"
172
173# Get OS info to be tracked
174os_distro=$(lsb_release -i 2>/dev/null | awk '{print $3}')
175echo $os_distro
176os_release=$(lsb_release -r 2>/dev/null | awk '{print $2}')
177echo $os_release
178os_info="${os_distro}_${os_release}"
179os_info="${os_info// /_}"
180
garciadeblascf603f52025-06-04 11:57:28 +0200181# Initial checks: proxy, root user, proceed
182check_osm_behind_proxy
183track start release $RELEASE none none docker_tag $OSM_DOCKER_TAG none none installation_type Default none none os_info $os_info none none
184track checks checkingroot_ok
185[ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
186track checks noroot_ok
187ask_proceed
188track checks proceed_ok
189
190# Setup prerequisites
191echo "Setting up external IP address"
192setup_external_ip
193[ -n "$APT_PROXY_URL" ] && echo "Configuring APT proxy" && configure_apt_proxy $APT_PROXY_URL
194track prereq prereqok_ok
195
196# Export installation options
garciadeblascf603f52025-06-04 11:57:28 +0200197$OSM_DEVOPS/installers/01-export-osm-install-options.sh || FATAL_TRACK exportinstallopts "01-export-osm-install-options.sh failed"
198track exportinstallopts exportinstallopts_ok
199
200# Setup Client tools
201echo "Setup CLI tools for mgmt and aux cluster"
202$OSM_DEVOPS/installers/10-install-client-tools.sh || FATAL_TRACK installclitools "10-install-client-tools.sh failed"
203track installclitools installclitools_ok
204
205# Install K8s cluster where all OSM components will be deployed
206echo "Installing K8s cluster ..."
207source "${HERE}/../library/utils.sh"
208# setup_external_ip
209export OSM_DEFAULT_IP
210export OSM_K8S_EXTERNAL_IP
211$OSM_DEVOPS/installers/15-install-k8s-cluster.sh || FATAL_TRACK k8scluster "15-install-k8s-cluster.sh"
212track k8scluster k8scluster_ok
213
214# Deploy auxiliary services
215if [ -n "${INSTALL_AUX_CLUSTER}" ]; then
216 echo "Deploy auxiliary services (Gitea, S3)"
217 $OSM_DEVOPS/installers/20-deploy-aux-svc-cluster.sh || FATAL_TRACK deployauxsvc "20-deploy-aux-svc-cluster.sh failed"
218else
219 echo "Skipping deployment of auxiliary services."
220 echo "Using existing git credentials and repos defined in ${CREDENTIALS_DIR}/git_environment.rc"
221# cat << EOF > "${CREDENTIALS_DIR}/git_environment.rc"
garciadeblas823d8a32025-07-08 10:41:53 +0200222# export GIT_BASE_HTTP_URL="${GITEA_HTTP_URL}"
garciadeblascf603f52025-06-04 11:57:28 +0200223# export FLEET_REPO_HTTP_URL="${FLEET_REPO_HTTP_URL}"
224# export FLEET_REPO_SSH_URL="${FLEET_REPO_SSH_URL}"
225# export FLEET_REPO_GIT_USERNAME="${FLEET_REPO_GIT_USERNAME}"
226# export FLEET_REPO_GIT_USER_PASS='${FLEET_REPO_GIT_USER_PASS}'
227# export SW_CATALOGS_REPO_HTTP_URL="${SW_CATALOGS_REPO_HTTP_URL}"
228# export SW_CATALOGS_REPO_SSH_URL="${SW_CATALOGS_REPO_SSH_URL}"
229# export SW_CATALOGS_REPO_GIT_USERNAME="${SW_CATALOGS_REPO_GIT_USERNAME}"
230# export SW_CATALOGS_REPO_GIT_USER_PASS='${SW_CATALOGS_REPO_GIT_USER_PASS}'
231# EOF
232fi
233track deployauxsvc deployauxsvc_ok
234
235# Deploy mgmt services
236if [ -n "${INSTALL_MGMT_CLUSTER}" ]; then
237 echo "Deploy mgmt cluster (Flux, etc.)"
238 $OSM_DEVOPS/installers/30-deploy-mgmt-cluster.sh || FATAL_TRACK mgmtcluster "30-deploy-mgmt-cluster.sh failed"
239else
240 echo "Skipping deployment of mgmt cluster"
241 # TODO: write env variables to files"
242fi
243track mgmtcluster mgmtcluster_ok
244
245# Deploy OSM (OSM helm chart)
246echo "Deploy OSM helm chart"
247export OSM_K8S_EXTERNAL_IP
248$OSM_DEVOPS/installers/40-deploy-osm.sh || FATAL_TRACK deployosm "40-deploy-osm.sh failed"
249track deploy_osm deploy_osm_ok
250
251# Provision OSM
252echo -e "Adding local K8s cluster _system-osm-k8s to OSM ..."
253$OSM_DEVOPS/installers/50-provision-osm.sh || FATAL_TRACK provision-osm "50-provision-osm.sh failed"
254track provisionosm provisionosm_ok
255
garciadeblas965aafe2025-06-19 10:07:57 +0200256curl -s https://osm-download.etsi.org/ftp/osm-18.0-eighteen/README2.txt > /dev/null 2>&1
garciadeblascf603f52025-06-04 11:57:28 +0200257track end
258
259echo "Credentials stored under ${CREDENTIALS_DIR}"
260echo "Git repos for OSM declarative framework stored under ${WORK_REPOS_DIR}"
261echo "Kubeconfigs of the aux-svc cluster, mgmt cluster and OSM cluster stored under ${OSM_HOME_DIR}/clusters"
garciadeblas2fdfb382025-04-29 14:54:23 +0200262echo -e "\nDONE"
263exit 0