blob: 35a9d9eb97a6d633d2d3376f1b157e5cf64cfb4f [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"
38 echo -e " -T <docker tag> specify docker tag for the modules specified with option -m"
garciadeblascf603f52025-06-04 11:57:28 +020039 echo -e " -U <docker user>: specify docker user to use when pulling images from a private registry"
40 echo -e " -D <devops path>: use particular devops installation path"
41 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 +020042 echo -e " --debug: debug mode"
garciadeblas0bc87522021-10-20 22:16:17 +020043 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblasd8bc5c32018-05-09 17:37:56 +020044}
45
garciadeblascf603f52025-06-04 11:57:28 +020046HERE=$(dirname "$(readlink --canonicalize "$BASH_SOURCE")")
47OSM_DEVOPS="${OSM_DEVOPS:-"${HERE}/.."}"
48source $OSM_DEVOPS/library/all_funcs
calvinosanc10c82da02020-08-17 11:45:15 +020049
garciadeblas31dd8bb2025-07-08 14:54:24 +020050echo "Load default options and export user installation options"
51source $OSM_DEVOPS/installers/00-default-install-options.rc
beierlm2ce2b002021-12-07 16:02:22 -050052
vijaynag8339ed22019-07-25 17:10:58 +053053RE_CHECK='^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'
garciadeblascf603f52025-06-04 11:57:28 +020054while getopts ":a:c:e:r:k:u:R:D:s:t:U:d:p:T:M:G:O:-: hy" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +020055 case "${o}" in
garciadeblas0bc87522021-10-20 22:16:17 +020056 a)
57 APT_PROXY_URL=${OPTARG}
58 ;;
garciadeblas250b0b62024-01-22 13:30:59 +010059 c)
60 K8S_CLUSTER_ENGINE=${OPTARG}
61 [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ] && continue
62 [ "${K8S_CLUSTER_ENGINE}" == "k3s" ] && continue
garciadeblas250b0b62024-01-22 13:30:59 +010063 echo -e "Invalid argument for -c : ' ${K8S_CLUSTER_ENGINE}'\n" >&2
64 usage && exit 1
65 ;;
garciadeblase3a84a52024-09-27 11:34:55 +020066 e)
67 OSM_K8S_EXTERNAL_IP="${OPTARG}"
68 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +020069 r)
Mike Marchettib8420852018-09-13 13:45:06 -040070 REPOSITORY="${OPTARG}"
71 REPO_ARGS+=(-r "$REPOSITORY")
garciadeblasd8bc5c32018-05-09 17:37:56 +020072 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +020073 k)
Mike Marchettib8420852018-09-13 13:45:06 -040074 REPOSITORY_KEY="${OPTARG}"
75 REPO_ARGS+=(-k "$REPOSITORY_KEY")
garciadeblasd8bc5c32018-05-09 17:37:56 +020076 ;;
77 u)
Mike Marchettib8420852018-09-13 13:45:06 -040078 REPOSITORY_BASE="${OPTARG}"
79 REPO_ARGS+=(-u "$REPOSITORY_BASE")
garciadeblasd8bc5c32018-05-09 17:37:56 +020080 ;;
garciadeblas25e87d22020-01-31 14:27:29 +010081 R)
82 RELEASE="${OPTARG}"
83 REPO_ARGS+=(-R "$RELEASE")
garciadeblas0d45bc82018-11-19 14:25:13 +010084 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +020085 D)
86 OSM_DEVOPS="${OPTARG}"
87 ;;
garciadeblas25e87d22020-01-31 14:27:29 +010088 s)
garciadeblas325032a2023-04-13 18:07:44 +020089 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 +010090 ;;
91 t)
92 OSM_DOCKER_TAG="${OPTARG}"
Antonio Marsicof4ce57c2020-04-23 12:06:19 +020093 REPO_ARGS+=(-t "$OSM_DOCKER_TAG")
garciadeblas25e87d22020-01-31 14:27:29 +010094 ;;
95 U)
96 DOCKER_USER="${OPTARG}"
97 ;;
garciadeblas7f1e1042020-11-30 14:07:03 +000098 d)
garciadeblascf603f52025-06-04 11:57:28 +020099 parse_docker_registry_url "${OPTARG}"
garciadeblas7f1e1042020-11-30 14:07:03 +0000100 ;;
101 p)
102 DOCKER_PROXY_URL="${OPTARG}"
103 ;;
104 T)
105 MODULE_DOCKER_TAG="${OPTARG}"
106 ;;
garciadeblas8d8cd992024-05-21 16:04:14 +0200107 M)
108 KUBECONFIG_MGMT_CLUSTER="${OPTARG}"
109 ;;
110 G)
111 KUBECONFIG_AUX_CLUSTER="${OPTARG}"
112 ;;
garciadeblascf603f52025-06-04 11:57:28 +0200113 O)
114 KUBECONFIG_OSM_CLUSTER="${OPTARG}"
115 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200116 -)
117 [ "${OPTARG}" == "help" ] && usage && exit 0
garciadeblas0bc87522021-10-20 22:16:17 +0200118 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="--debug" && continue
garciadeblas8d8cd992024-05-21 16:04:14 +0200119 [ "${OPTARG}" == "no-mgmt-cluster" ] && INSTALL_MGMT_CLUSTER="" && continue
120 [ "${OPTARG}" == "no-aux-cluster" ] && INSTALL_AUX_CLUSTER="" && continue
garciadeblascf603f52025-06-04 11:57:28 +0200121 if [[ "${OPTARG}" == "client-version" ]]; then
122 OSM_CLIENT_VERSION="${!OPTIND}"; OPTIND=$((OPTIND + 1))
123 continue
124 fi
125 if [[ "${OPTARG}" == "im-version" ]]; then
126 OSM_IM_VERSION="${!OPTIND}"; OPTIND=$((OPTIND + 1))
127 continue
128 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200129 echo -e "Invalid option: '--$OPTARG'\n" >&2
130 usage && exit 1
131 ;;
garciadeblas25e87d22020-01-31 14:27:29 +0100132 :)
133 echo "Option -$OPTARG requires an argument" >&2
134 usage && exit 1
135 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200136 \?)
137 echo -e "Invalid option: '-$OPTARG'\n" >&2
138 usage && exit 1
139 ;;
garciadeblas25e87d22020-01-31 14:27:29 +0100140 h)
141 usage && exit 0
142 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200143 y)
144 ASSUME_YES="y"
145 ;;
146 *)
147 usage && exit 1
148 ;;
149 esac
150done
151
garciadeblas6c66abf2018-05-16 14:46:19 +0200152
garciadeblas0bc87522021-10-20 22:16:17 +0200153[ -z "${DEBUG_INSTALL}" ] || DEBUG Debug is on
garciadeblas28d71bd2023-06-07 23:06:50 +0200154# Installation starts here
155
156# Get README and create OSM_TRACK_INSTALLATION_ID
garciadeblas965aafe2025-06-19 10:07:57 +0200157curl -s https://osm-download.etsi.org/ftp/osm-18.0-eighteen/README.txt > /dev/null 2>&1
garciadeblas28d71bd2023-06-07 23:06:50 +0200158export OSM_TRACK_INSTALLATION_ID="$(date +%s)-$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)"
159
160# Get OS info to be tracked
161os_distro=$(lsb_release -i 2>/dev/null | awk '{print $3}')
162echo $os_distro
163os_release=$(lsb_release -r 2>/dev/null | awk '{print $2}')
164echo $os_release
165os_info="${os_distro}_${os_release}"
166os_info="${os_info// /_}"
167
garciadeblascf603f52025-06-04 11:57:28 +0200168# Initial checks: proxy, root user, proceed
169check_osm_behind_proxy
170track start release $RELEASE none none docker_tag $OSM_DOCKER_TAG none none installation_type Default none none os_info $os_info none none
171track checks checkingroot_ok
172[ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
173track checks noroot_ok
174ask_proceed
175track checks proceed_ok
176
177# Setup prerequisites
178echo "Setting up external IP address"
179setup_external_ip
180[ -n "$APT_PROXY_URL" ] && echo "Configuring APT proxy" && configure_apt_proxy $APT_PROXY_URL
181track prereq prereqok_ok
182
183# Export installation options
garciadeblascf603f52025-06-04 11:57:28 +0200184$OSM_DEVOPS/installers/01-export-osm-install-options.sh || FATAL_TRACK exportinstallopts "01-export-osm-install-options.sh failed"
185track exportinstallopts exportinstallopts_ok
186
187# Setup Client tools
188echo "Setup CLI tools for mgmt and aux cluster"
189$OSM_DEVOPS/installers/10-install-client-tools.sh || FATAL_TRACK installclitools "10-install-client-tools.sh failed"
190track installclitools installclitools_ok
191
192# Install K8s cluster where all OSM components will be deployed
193echo "Installing K8s cluster ..."
194source "${HERE}/../library/utils.sh"
195# setup_external_ip
196export OSM_DEFAULT_IP
197export OSM_K8S_EXTERNAL_IP
198$OSM_DEVOPS/installers/15-install-k8s-cluster.sh || FATAL_TRACK k8scluster "15-install-k8s-cluster.sh"
199track k8scluster k8scluster_ok
200
201# Deploy auxiliary services
202if [ -n "${INSTALL_AUX_CLUSTER}" ]; then
203 echo "Deploy auxiliary services (Gitea, S3)"
204 $OSM_DEVOPS/installers/20-deploy-aux-svc-cluster.sh || FATAL_TRACK deployauxsvc "20-deploy-aux-svc-cluster.sh failed"
205else
206 echo "Skipping deployment of auxiliary services."
207 echo "Using existing git credentials and repos defined in ${CREDENTIALS_DIR}/git_environment.rc"
208# cat << EOF > "${CREDENTIALS_DIR}/git_environment.rc"
garciadeblas823d8a32025-07-08 10:41:53 +0200209# export GIT_BASE_HTTP_URL="${GITEA_HTTP_URL}"
garciadeblascf603f52025-06-04 11:57:28 +0200210# export FLEET_REPO_HTTP_URL="${FLEET_REPO_HTTP_URL}"
211# export FLEET_REPO_SSH_URL="${FLEET_REPO_SSH_URL}"
212# export FLEET_REPO_GIT_USERNAME="${FLEET_REPO_GIT_USERNAME}"
213# export FLEET_REPO_GIT_USER_PASS='${FLEET_REPO_GIT_USER_PASS}'
214# export SW_CATALOGS_REPO_HTTP_URL="${SW_CATALOGS_REPO_HTTP_URL}"
215# export SW_CATALOGS_REPO_SSH_URL="${SW_CATALOGS_REPO_SSH_URL}"
216# export SW_CATALOGS_REPO_GIT_USERNAME="${SW_CATALOGS_REPO_GIT_USERNAME}"
217# export SW_CATALOGS_REPO_GIT_USER_PASS='${SW_CATALOGS_REPO_GIT_USER_PASS}'
218# EOF
219fi
220track deployauxsvc deployauxsvc_ok
221
222# Deploy mgmt services
223if [ -n "${INSTALL_MGMT_CLUSTER}" ]; then
224 echo "Deploy mgmt cluster (Flux, etc.)"
225 $OSM_DEVOPS/installers/30-deploy-mgmt-cluster.sh || FATAL_TRACK mgmtcluster "30-deploy-mgmt-cluster.sh failed"
226else
227 echo "Skipping deployment of mgmt cluster"
228 # TODO: write env variables to files"
229fi
230track mgmtcluster mgmtcluster_ok
231
232# Deploy OSM (OSM helm chart)
233echo "Deploy OSM helm chart"
234export OSM_K8S_EXTERNAL_IP
235$OSM_DEVOPS/installers/40-deploy-osm.sh || FATAL_TRACK deployosm "40-deploy-osm.sh failed"
236track deploy_osm deploy_osm_ok
237
238# Provision OSM
239echo -e "Adding local K8s cluster _system-osm-k8s to OSM ..."
240$OSM_DEVOPS/installers/50-provision-osm.sh || FATAL_TRACK provision-osm "50-provision-osm.sh failed"
241track provisionosm provisionosm_ok
242
garciadeblas965aafe2025-06-19 10:07:57 +0200243curl -s https://osm-download.etsi.org/ftp/osm-18.0-eighteen/README2.txt > /dev/null 2>&1
garciadeblascf603f52025-06-04 11:57:28 +0200244track end
245
246echo "Credentials stored under ${CREDENTIALS_DIR}"
247echo "Git repos for OSM declarative framework stored under ${WORK_REPOS_DIR}"
248echo "Kubeconfigs of the aux-svc cluster, mgmt cluster and OSM cluster stored under ${OSM_HOME_DIR}/clusters"
garciadeblas2fdfb382025-04-29 14:54:23 +0200249echo -e "\nDONE"
250exit 0