blob: 6cde383f7a7a975784218a9ec5329965ecbdc717 [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"
24 echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)"
25 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"
32 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)"
33 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)"
34 echo -e " -D <devops path>: use local devops installation path"
garciadeblas325032a2023-04-13 18:07:44 +020035 echo -e " -s <namespace> namespace when installed using k8s, default is osm"
Mike Marchettib8420852018-09-13 13:45:06 -040036 echo -e " -H <VCA host> use specific juju host controller IP"
37 echo -e " -S <VCA secret> use VCA/juju secret key"
garciadeblasaa3ddf42019-04-04 19:04:32 +020038 echo -e " -P <VCA pubkey> use VCA/juju public key file"
Adam Israel5ddc97f2019-09-03 18:11:12 -040039 echo -e " -A <VCA apiproxy> use VCA/juju API proxy"
magnussonl1bbe9452020-02-25 13:43:17 +010040 echo -e " --pla: install the PLA module for placement support"
garciadeblas836354f2023-05-10 18:12:00 +020041 echo -e " --old-sa: install old Service Assurance framework (MON, POL); do not install Airflow and Pushgateway"
garciadeblasef3f37c2024-05-31 17:30:48 +020042 echo -e " --ng-sa: install new Service Assurance framework (Airflow, AlertManager and Pushgateway) (enabled by default)"
43 echo -e " -o <COMPONENT>: ONLY installs the specified component (k8s_monitor, ng-sa, k8scluster, docker, deploy-osm)"
garciadeblas8d8cd992024-05-21 16:04:14 +020044 echo -e " -O <openrc file path/cloud name>: install OSM to an OpenStack infrastructure. <openrc file/cloud name> is required. If a <cloud name> is used, the clouds.yaml file should be under ~/.config/openstack/ or /etc/openstack/"
45 echo -e " -N <openstack public network name/ID>: public network name required to setup OSM to OpenStack"
46 echo -e " -f <path to SSH public key>: public SSH key to use to deploy OSM to OpenStack"
47 echo -e " -F <path to cloud-init file>: cloud-init userdata file to deploy OSM to OpenStack"
48 echo -e " -w <work dir>: Location to store runtime installation"
David Garcia79f4f532020-04-07 12:59:34 +020049 echo -e " -l: LXD cloud yaml file"
50 echo -e " -L: LXD credentials yaml file"
David Garcia404ae122020-04-28 11:47:55 +020051 echo -e " -K: Specifies the name of the controller to use - The controller must be already bootstrapped"
garciadeblas7f1e1042020-11-30 14:07:03 +000052 echo -e " -d <docker registry URL> use docker registry URL instead of dockerhub"
53 echo -e " -p <docker proxy URL> set docker proxy URL as part of docker CE configuration"
54 echo -e " -T <docker tag> specify docker tag for the modules specified with option -m"
garciadeblas0bc87522021-10-20 22:16:17 +020055 echo -e " --debug: debug mode"
garciadeblas9a510862021-04-21 14:15:56 +020056 echo -e " --nocachelxdimages: do not cache local lxd images, do not create cronjob for that cache (will save installation time, might affect instantiation time)"
garciadeblas0bc87522021-10-20 22:16:17 +020057 echo -e " --cachelxdimages: cache local lxd images, create cronjob for that cache (will make installation longer)"
David Garcia79f4f532020-04-07 12:59:34 +020058 echo -e " --nolxd: do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)"
garciadeblasa3e26612018-05-30 17:58:55 +020059 echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)"
Mike Marchettib8420852018-09-13 13:45:06 -040060 echo -e " --nojuju: do not juju, assumes already installed"
Mike Marchettib8420852018-09-13 13:45:06 -040061 echo -e " --nohostports: do not expose docker ports to host (useful for creating multiple instances of osm on the same host)"
62 echo -e " --nohostclient: do not install the osmclient"
garciadeblase990f662018-05-18 11:43:39 +020063 echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
romeromonser599d5e22020-03-06 10:23:29 +010064 echo -e " --k8s_monitor: install the OSM kubernetes monitoring with prometheus and grafana"
Antonio Marsicof4ce57c2020-04-23 12:06:19 +020065 echo -e " --volume: create a VM volume when installing to OpenStack"
garciadeblasd8bc5c32018-05-09 17:37:56 +020066 echo -e " --showopts: print chosen options and exit (only for debugging)"
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020067 echo -e " --charmed: Deploy and operate OSM with Charms on k8s"
68 echo -e " [--bundle <bundle path>]: Specify with which bundle to deploy OSM with charms (--charmed option)"
69 echo -e " [--k8s <kubeconfig path>]: Specify with which kubernetes to deploy OSM with charms (--charmed option)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +020070 echo -e " [--vca <name>]: Specifies the name of the controller to use - The controller must be already bootstrapped (--charmed option)"
aticig5d19ac22022-05-06 13:46:22 +030071 echo -e " [--small-profile]: Do not install and configure LXD which aims to use only K8s Clouds (--charmed option)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +020072 echo -e " [--lxd <yaml path>]: Takes a YAML file as a parameter with the LXD Cloud information (--charmed option)"
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020073 echo -e " [--lxd-cred <yaml path>]: Takes a YAML file as a parameter with the LXD Credentials information (--charmed option)"
74 echo -e " [--microstack]: Installs microstack as a vim. (--charmed option)"
David Garcia4bd2bf02021-05-05 19:01:43 +020075 echo -e " [--overlay]: Add an overlay to override some defaults of the default bundle (--charmed option)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +020076 echo -e " [--ha]: Installs High Availability bundle. (--charmed option)"
beierlmf2782c52020-11-05 17:04:05 -050077 echo -e " [--tag]: Docker image tag. (--charmed option)"
78 echo -e " [--registry]: Docker registry with optional credentials as user:pass@hostname:port (--charmed option)"
garciadeblas0bc87522021-10-20 22:16:17 +020079 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblasd8bc5c32018-05-09 17:37:56 +020080}
81
Mike Marchettib8420852018-09-13 13:45:06 -040082# takes a juju/accounts.yaml file and returns the password specific
Adam Israel8232e562018-11-21 16:47:45 -050083# for a controller. I wrote this using only bash tools to minimize
Mike Marchettib8420852018-09-13 13:45:06 -040084# additions of other packages
85function parse_juju_password {
garciadeblas0bc87522021-10-20 22:16:17 +020086 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
87 password_file="${HOME}/.local/share/juju/accounts.yaml"
88 local controller_name=$1
89 local s='[[:space:]]*' w='[a-zA-Z0-9_-]*' fs=$(echo @|tr @ '\034')
90 sed -ne "s|^\($s\):|\1|" \
91 -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
92 -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $password_file |
93 awk -F$fs -v controller=$controller_name '{
94 indent = length($1)/2;
95 vname[indent] = $2;
96 for (i in vname) {if (i > indent) {delete vname[i]}}
97 if (length($3) > 0) {
98 vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
99 if (match(vn,controller) && match($2,"password")) {
100 printf("%s",$3);
101 }
102 }
103 }'
104 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
105}
106
107function set_vca_variables() {
108 OSM_VCA_CLOUDNAME="lxd-cloud"
109 [ -n "$OSM_VCA_HOST" ] && OSM_VCA_CLOUDNAME="localhost"
110 if [ -z "$OSM_VCA_HOST" ]; then
garciadeblas325032a2023-04-13 18:07:44 +0200111 [ -z "$CONTROLLER_NAME" ] && OSM_VCA_HOST=`sg lxd -c "juju show-controller $OSM_NAMESPACE"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
garciadeblas0bc87522021-10-20 22:16:17 +0200112 [ -n "$CONTROLLER_NAME" ] && OSM_VCA_HOST=`juju show-controller $CONTROLLER_NAME |grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
113 [ -z "$OSM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
114 fi
115 if [ -z "$OSM_VCA_SECRET" ]; then
garciadeblas325032a2023-04-13 18:07:44 +0200116 [ -z "$CONTROLLER_NAME" ] && OSM_VCA_SECRET=$(parse_juju_password $OSM_NAMESPACE)
garciadeblas0bc87522021-10-20 22:16:17 +0200117 [ -n "$CONTROLLER_NAME" ] && OSM_VCA_SECRET=$(parse_juju_password $CONTROLLER_NAME)
118 [ -z "$OSM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
119 fi
120 if [ -z "$OSM_VCA_PUBKEY" ]; then
121 OSM_VCA_PUBKEY=$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)
122 [ -z "$OSM_VCA_PUBKEY" ] && FATAL "Cannot obtain juju public key"
123 fi
124 if [ -z "$OSM_VCA_CACERT" ]; then
garciadeblas325032a2023-04-13 18:07:44 +0200125 [ -z "$CONTROLLER_NAME" ] && OSM_VCA_CACERT=$(juju controllers --format json | jq -r --arg controller $OSM_NAMESPACE '.controllers[$controller]["ca-cert"]' | base64 | tr -d \\n)
garciadeblas0bc87522021-10-20 22:16:17 +0200126 [ -n "$CONTROLLER_NAME" ] && OSM_VCA_CACERT=$(juju controllers --format json | jq -r --arg controller $CONTROLLER_NAME '.controllers[$controller]["ca-cert"]' | base64 | tr -d \\n)
127 [ -z "$OSM_VCA_CACERT" ] && FATAL "Cannot obtain juju CA certificate"
128 fi
Mike Marchettib8420852018-09-13 13:45:06 -0400129}
130
Benjamin Diazba2cca92018-11-08 21:07:15 -0300131function generate_secret() {
garciadeblas0bc87522021-10-20 22:16:17 +0200132 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
Benjamin Diazba2cca92018-11-08 21:07:15 -0300133 head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32
garciadeblas0bc87522021-10-20 22:16:17 +0200134 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
calvinosanc10c82da02020-08-17 11:45:15 +0200135}
136
beierlm2ce2b002021-12-07 16:02:22 -0500137function check_packages() {
138 NEEDED_PACKAGES="$1"
139 echo -e "Checking required packages: ${NEEDED_PACKAGES}"
140 for PACKAGE in ${NEEDED_PACKAGES} ; do
garciadeblas835088e2022-01-28 11:25:18 +0100141 dpkg -L ${PACKAGE}
beierlm2ce2b002021-12-07 16:02:22 -0500142 if [ $? -ne 0 ]; then
garciadeblas835088e2022-01-28 11:25:18 +0100143 echo -e "Package ${PACKAGE} is not installed."
144 echo -e "Updating apt-cache ..."
beierlm2ce2b002021-12-07 16:02:22 -0500145 sudo apt-get update
garciadeblas835088e2022-01-28 11:25:18 +0100146 echo -e "Installing ${PACKAGE} ..."
beierlm2ce2b002021-12-07 16:02:22 -0500147 sudo apt-get install -y ${PACKAGE} || FATAL "failed to install ${PACKAGE}"
148 fi
149 done
150 echo -e "Required packages are present: ${NEEDED_PACKAGES}"
151}
152
garciadeblasd8bc5c32018-05-09 17:37:56 +0200153function ask_user(){
154 # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive
155 # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed
156 # Return: true(0) if user type 'yes'; false (1) if user type 'no'
garciadeblas0bc87522021-10-20 22:16:17 +0200157 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblasd8bc5c32018-05-09 17:37:56 +0200158 read -e -p "$1" USER_CONFIRMATION
159 while true ; do
160 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0
161 [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1
162 [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0
163 [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1
164 read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION
165 done
garciadeblas0bc87522021-10-20 22:16:17 +0200166 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblasd8bc5c32018-05-09 17:37:56 +0200167}
168
garciadeblasd8bc5c32018-05-09 17:37:56 +0200169function install_osmclient(){
garciadeblas0bc87522021-10-20 22:16:17 +0200170 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblasd8bc5c32018-05-09 17:37:56 +0200171 CLIENT_RELEASE=${RELEASE#"-R "}
172 CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
173 CLIENT_REPOSITORY=${REPOSITORY#"-r "}
garciadeblasd8bc5c32018-05-09 17:37:56 +0200174 CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "}
175 key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY
garciadeblas0bc87522021-10-20 22:16:17 +0200176 curl $key_location | sudo APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 apt-key add -
garciadeblas078f5982019-11-27 15:06:06 +0100177 sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient IM"
garciadeblas80b2e172023-06-01 18:38:13 +0200178 sudo apt-get -y update
179 sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-pip
garciadeblas078f5982019-11-27 15:06:06 +0100180 sudo -H LC_ALL=C python3 -m pip install -U pip
garciadeblas80b2e172023-06-01 18:38:13 +0200181 sudo DEBIAN_FRONTEND=noninteractive apt-get install -y python3-osm-im python3-osmclient
beierlm920d7562021-04-21 05:13:53 -0400182 if [ -f /usr/lib/python3/dist-packages/osm_im/requirements.txt ]; then
beierlm021b3072021-04-27 14:33:24 -0400183 python3 -m pip install -r /usr/lib/python3/dist-packages/osm_im/requirements.txt
beierlm920d7562021-04-21 05:13:53 -0400184 fi
185 if [ -f /usr/lib/python3/dist-packages/osmclient/requirements.txt ]; then
garciadeblas357a3c22023-06-26 09:10:11 +0200186 sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libmagic1
beierlm021b3072021-04-27 14:33:24 -0400187 python3 -m pip install -r /usr/lib/python3/dist-packages/osmclient/requirements.txt
beierlm920d7562021-04-21 05:13:53 -0400188 fi
garciadeblasd8bc5c32018-05-09 17:37:56 +0200189 echo -e "\nOSM client installed"
garciadeblas779b1bf2024-05-22 18:47:09 +0200190 echo -e "OSM client assumes that OSM host is running in localhost (127.0.0.1)."
191 echo -e "In case you want to interact with a different OSM host, you will have to configure this env variable in your .bashrc file:"
garciadeblas18582e92024-05-21 12:13:50 +0200192 echo " export OSM_HOSTNAME=nbi.${OSM_DEFAULT_IP}.nip.io"
garciadeblas0bc87522021-10-20 22:16:17 +0200193 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblasd8bc5c32018-05-09 17:37:56 +0200194 return 0
195}
196
garciadeblas453d4582020-12-16 19:03:10 +0100197function docker_login() {
garciadeblas0bc87522021-10-20 22:16:17 +0200198 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblas453d4582020-12-16 19:03:10 +0100199 echo "Docker login"
garciadeblas0bc87522021-10-20 22:16:17 +0200200 [ -z "${DEBUG_INSTALL}" ] || DEBUG "Docker registry user: ${DOCKER_REGISTRY_USER}"
201 sg docker -c "docker login -u ${DOCKER_REGISTRY_USER} -p ${DOCKER_REGISTRY_PASSWORD} --password-stdin"
202 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblas453d4582020-12-16 19:03:10 +0100203}
204
garciadeblasf6ed60c2020-07-08 14:30:29 +0000205#deploys osm pods and services
garciadeblas9bae86f2024-05-31 17:15:18 +0200206function deploy_osm_helm_chart() {
garciadeblas0bc87522021-10-20 22:16:17 +0200207 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblas8080e4b2023-04-14 09:57:17 +0200208 # Generate helm values to be passed with -f osm-values.yaml
209 sudo mkdir -p ${OSM_HELM_WORK_DIR}
garciadeblas8375da12023-10-10 10:52:29 +0200210 if [ -n "${INSTALL_JUJU}" ]; then
211 sudo bash -c "cat << EOF > ${OSM_HELM_WORK_DIR}/osm-values.yaml
garciadeblas8080e4b2023-04-14 09:57:17 +0200212vca:
213 pubkey: \"${OSM_VCA_PUBKEY}\"
214EOF"
garciadeblas8375da12023-10-10 10:52:29 +0200215 fi
garciadeblas8080e4b2023-04-14 09:57:17 +0200216
217 # Generate helm values to be passed with --set
218 OSM_HELM_OPTS=""
219 # OSM_HELM_OPTS="${OSM_HELM_OPTS} --set nbi.useOsmSecret=false"
garciadeblase6d45882024-05-22 15:03:00 +0200220
221 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.image.repositoryBase=${DOCKER_REGISTRY_URL}${DOCKER_USER}"
222 [ ! "$OSM_DOCKER_TAG" == "testing-daily" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set-string global.image.tag=${OSM_DOCKER_TAG}"
223 [ ! "$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}"
224
garciadeblas18582e92024-05-21 12:13:50 +0200225 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.hostname=${OSM_DEFAULT_IP}.nip.io"
226 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set grafana.ingress.hosts={grafana.${OSM_DEFAULT_IP}.nip.io}"
227 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set prometheus.server.ingress.hosts={prometheus.${OSM_DEFAULT_IP}.nip.io}"
228 # OSM_HELM_OPTS="${OSM_HELM_OPTS} --set prometheus.alertmanager.ingress.hosts={alertmanager.${OSM_DEFAULT_IP}.nip.io}"
garciadeblas8d8cd992024-05-21 16:04:14 +0200229 [ -z "${INSTALL_MGMT_CLUSTER}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.gitops.enabled=false}"
garciadeblas18582e92024-05-21 12:13:50 +0200230
garciadeblas8375da12023-10-10 10:52:29 +0200231 if [ -n "${INSTALL_JUJU}" ]; then
232 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set vca.enabled=true"
233 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set vca.host=${OSM_VCA_HOST}"
234 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set vca.secret=${OSM_VCA_SECRET}"
235 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set vca.cacert=${OSM_VCA_CACERT}"
236 fi
garciadeblas8080e4b2023-04-14 09:57:17 +0200237 [ -n "$OSM_VCA_APIPROXY" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set lcm.config.OSMLCM_VCA_APIPROXY=${OSM_VCA_APIPROXY}"
garciadeblas18582e92024-05-21 12:13:50 +0200238
garciadeblas8080e4b2023-04-14 09:57:17 +0200239 [ -n "${INSTALL_NGSA}" ] || OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.oldServiceAssurance=true"
garciadeblas555702a2023-05-31 23:47:01 +0200240 if [ -n "${OSM_BEHIND_PROXY}" ]; then
241 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.behindHttpProxy=true"
garciadeblas8c2b2642023-11-02 07:56:50 +0100242 [ -n "${HTTP_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.HTTP_PROXY=\"${HTTP_PROXY}\""
243 [ -n "${HTTPS_PROXY}" ] && OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.HTTPS_PROXY=\"${HTTPS_PROXY}\""
244 if [ -n "${NO_PROXY}" ]; then
245 if [[ ! "${NO_PROXY}" =~ .*".svc".* ]]; then
246 NO_PROXY="${NO_PROXY},.svc"
247 fi
248 if [[ ! "${NO_PROXY}" =~ .*".cluster.local".* ]]; then
249 NO_PROXY="${NO_PROXY},.cluster.local"
250 fi
251 OSM_HELM_OPTS="${OSM_HELM_OPTS} --set global.httpProxy.NO_PROXY=\"${NO_PROXY//,/\,}\""
252 fi
garciadeblas555702a2023-05-31 23:47:01 +0200253 fi
garciadeblas8080e4b2023-04-14 09:57:17 +0200254
garciadeblas8375da12023-10-10 10:52:29 +0200255 if [ -n "${INSTALL_JUJU}" ]; then
256 OSM_HELM_OPTS="-f ${OSM_HELM_WORK_DIR}/osm-values.yaml ${OSM_HELM_OPTS}"
257 fi
garciadeblase6d45882024-05-22 15:03:00 +0200258 echo "helm upgrade --install -n $OSM_NAMESPACE --create-namespace $OSM_NAMESPACE $OSM_DEVOPS/installers/helm/osm ${OSM_HELM_OPTS}"
259 helm upgrade --install -n $OSM_NAMESPACE --create-namespace $OSM_NAMESPACE $OSM_DEVOPS/installers/helm/osm ${OSM_HELM_OPTS}
garciadeblas8080e4b2023-04-14 09:57:17 +0200260 # Override existing values.yaml with the final values.yaml used to install OSM
261 helm -n $OSM_NAMESPACE get values $OSM_NAMESPACE | sudo tee -a ${OSM_HELM_WORK_DIR}/osm-values.yaml
garciadeblas0bc87522021-10-20 22:16:17 +0200262 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
vijaynag8339ed22019-07-25 17:10:58 +0530263}
264
David Garciaa1376012020-10-19 15:42:42 +0200265#deploy charmed services
266function deploy_charmed_services() {
garciadeblas0bc87522021-10-20 22:16:17 +0200267 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblas325032a2023-04-13 18:07:44 +0200268 juju add-model $OSM_NAMESPACE $OSM_VCA_K8S_CLOUDNAME
garciadeblascdc1b002023-11-21 13:46:36 +0100269 juju deploy ch:mongodb-k8s -m $OSM_NAMESPACE --channel latest/stable
garciadeblas0bc87522021-10-20 22:16:17 +0200270 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
David Garciaa1376012020-10-19 15:42:42 +0200271}
272
garciadeblasca342382023-09-06 12:31:41 +0200273#deploy mongodb
274function deploy_mongodb() {
275 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblasb9a84e42024-05-31 15:06:40 +0200276 MONGO_OPTS="-d ${OSM_HELM_WORK_DIR} -D ${OSM_DEVOPS} -s ${OSM_NAMESPACE} -t ${OSM_DOCKER_TAG} -U ${DOCKER_USER} ${DEBUG_INSTALL}"
zamre4db5d532023-10-16 16:47:10 +0000277 [ -n "${DOCKER_REGISTRY_URL}" ] && MONGO_OPTS="${MONGO_OPTS} -r ${DOCKER_REGISTRY_URL}"
278 $OSM_DEVOPS/installers/install_mongodb.sh ${MONGO_OPTS} || \
279 FATAL_TRACK install_osm_mongodb_service "install_mongodb.sh failed"
garciadeblasca342382023-09-06 12:31:41 +0200280 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
281}
282
garciadeblas7b53d262022-11-04 23:18:48 +0100283function install_osm_ngsa_service() {
284 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblasb9a84e42024-05-31 15:06:40 +0200285 NGSA_OPTS="-i ${OSM_DEFAULT_IP} -d ${OSM_HELM_WORK_DIR} -D ${OSM_DEVOPS} -s ${OSM_NAMESPACE} -t ${OSM_DOCKER_TAG} -U ${DOCKER_USER} ${DEBUG_INSTALL}"
garciadeblas37630992023-05-09 13:33:22 +0200286 [ -n "${DOCKER_REGISTRY_URL}" ] && NGSA_OPTS="${NGSA_OPTS} -r ${DOCKER_REGISTRY_URL}"
287 $OSM_DEVOPS/installers/install_ngsa.sh ${NGSA_OPTS} || \
garciadeblas7b53d262022-11-04 23:18:48 +0100288 FATAL_TRACK install_osm_ngsa_service "install_ngsa.sh failed"
289 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
290}
291
garciadeblase92a18d2020-07-03 16:24:23 +0000292function add_local_k8scluster() {
garciadeblas0bc87522021-10-20 22:16:17 +0200293 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblas18582e92024-05-21 12:13:50 +0200294 # OSM_HOSTNAME=$(kubectl get --namespace osm -o jsonpath="{.spec.rules[0].host}" ingress nbi-ingress)
295 OSM_HOSTNAME="nbi.${OSM_DEFAULT_IP}.nip.io:443"
296 /usr/bin/osm --hostname ${OSM_HOSTNAME} --all-projects vim-create \
garciadeblase92a18d2020-07-03 16:24:23 +0000297 --name _system-osm-vim \
298 --account_type dummy \
299 --auth_url http://dummy \
300 --user osm --password osm --tenant osm \
301 --description "dummy" \
302 --config '{management_network_name: mgmt}'
garciadeblas18582e92024-05-21 12:13:50 +0200303 /usr/bin/osm --hostname ${OSM_HOSTNAME} --all-projects k8scluster-add \
garciadeblase92a18d2020-07-03 16:24:23 +0000304 --creds ${HOME}/.kube/config \
305 --vim _system-osm-vim \
306 --k8s-nets '{"net1": null}' \
garciadeblas18582e92024-05-21 12:13:50 +0200307 --version '1.29' \
garciadeblase92a18d2020-07-03 16:24:23 +0000308 --description "OSM Internal Cluster" \
309 _system-osm-k8s
garciadeblas0bc87522021-10-20 22:16:17 +0200310 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblase92a18d2020-07-03 16:24:23 +0000311}
312
garciadeblas0bc87522021-10-20 22:16:17 +0200313function configure_apt_proxy() {
314 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
315 OSM_APT_PROXY=$1
316 OSM_APT_PROXY_FILE="/etc/apt/apt.conf.d/osm-apt"
317 echo "Configuring apt proxy in file ${OSM_APT_PROXY_FILE}"
318 if [ ! -f ${OSM_APT_PROXY_FILE} ]; then
319 sudo bash -c "cat <<EOF > ${OSM_APT_PROXY}
320Acquire::http { Proxy \"${OSM_APT_PROXY}\"; }
321EOF"
322 else
323 sudo sed -i "s|Proxy.*|Proxy \"${OSM_APT_PROXY}\"; }|" ${OSM_APT_PROXY_FILE}
324 fi
325 sudo apt-get update || FATAL "Configured apt proxy, but couldn't run 'apt-get update'. Check ${OSM_APT_PROXY_FILE}"
garciadeblas4d89c372021-11-25 11:57:18 +0100326 track prereq apt_proxy_configured_ok
garciadeblas0bc87522021-10-20 22:16:17 +0200327 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
328}
329
garciadeblasfa3eb332022-11-15 14:11:56 +0100330function ask_proceed() {
garciadeblas0bc87522021-10-20 22:16:17 +0200331 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblasadcf95e2022-01-28 17:15:39 +0100332
garciadeblas0bc87522021-10-20 22:16:17 +0200333 [ -z "$ASSUME_YES" ] && ! ask_user "The installation will do the following
334 1. Install and configure LXD
335 2. Install juju
336 3. Install docker CE
337 4. Disable swap space
338 5. Install and initialize Kubernetes
339 as pre-requirements.
340 Do you want to proceed (Y/n)? " y && echo "Cancelled!" && exit 1
garciadeblasfa3eb332022-11-15 14:11:56 +0100341
342 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
343}
344
345function check_osm_behind_proxy() {
346 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
347
348 export OSM_BEHIND_PROXY=""
349 export OSM_PROXY_ENV_VARIABLES=""
350 [ -n "${http_proxy}" ] && OSM_BEHIND_PROXY="y" && echo "http_proxy=${http_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} http_proxy"
351 [ -n "${https_proxy}" ] && OSM_BEHIND_PROXY="y" && echo "https_proxy=${https_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} https_proxy"
352 [ -n "${HTTP_PROXY}" ] && OSM_BEHIND_PROXY="y" && echo "HTTP_PROXY=${HTTP_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} HTTP_PROXY"
353 [ -n "${HTTPS_PROXY}" ] && OSM_BEHIND_PROXY="y" && echo "https_proxy=${HTTPS_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} HTTPS_PROXY"
354 [ -n "${no_proxy}" ] && echo "no_proxy=${no_proxy}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} no_proxy"
355 [ -n "${NO_PROXY}" ] && echo "NO_PROXY=${NO_PROXY}" && OSM_PROXY_ENV_VARIABLES="${OSM_PROXY_ENV_VARIABLES} NO_PROXY"
356
357 echo "OSM_BEHIND_PROXY=${OSM_BEHIND_PROXY}"
358 echo "OSM_PROXY_ENV_VARIABLES=${OSM_PROXY_ENV_VARIABLES}"
359
360 if [ -n "${OSM_BEHIND_PROXY}" ]; then
361 [ -z "$ASSUME_YES" ] && ! ask_user "
362The following env variables have been found for the current user:
363${OSM_PROXY_ENV_VARIABLES}.
364
365This suggests that this machine is behind a proxy and a special configuration is required.
366The installer will install Docker CE, LXD and Juju to work behind a proxy using those
367env variables.
368
369Take into account that the installer uses apt, curl, wget, docker, lxd, juju and snap.
370Depending on the program, the env variables to work behind a proxy might be different
371(e.g. http_proxy vs HTTP_PROXY).
372
373For that reason, it is strongly recommended that at least http_proxy, https_proxy, HTTP_PROXY
374and HTTPS_PROXY are defined.
375
376Finally, some of the programs (apt, snap) those programs are run as sudoer, requiring that
377those env variables are also set for root user. If you are not sure whether those variables
378are configured for the root user, you can stop the installation now.
379
380Do you want to proceed with the installation (Y/n)? " y && echo "Cancelled!" && exit 1
381 else
382 echo "This machine is not behind a proxy"
383 fi
384
385 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
386}
387
388function find_devops_folder() {
garciadeblas9bae86f2024-05-31 17:15:18 +0200389 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblasfa3eb332022-11-15 14:11:56 +0100390 if [ -z "$OSM_DEVOPS" ]; then
391 if [ -n "$TEST_INSTALLER" ]; then
392 echo -e "\nUsing local devops repo for OSM installation"
393 OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))"
394 else
395 echo -e "\nCreating temporary dir for OSM installation"
396 OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
397 trap 'rm -rf "$OSM_DEVOPS"' EXIT
398 git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS
399 fi
400 fi
garciadeblas9bae86f2024-05-31 17:15:18 +0200401 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
402}
403
404function install_lxd() {
405 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
406 LXD_INSTALL_OPTS="-D ${OSM_DEVOPS} -i ${OSM_DEFAULT_IF} ${DEBUG_INSTALL}"
407 [ -n "${OSM_BEHIND_PROXY}" ] && LXD_INSTALL_OPTS="${LXD_INSTALL_OPTS} -P"
408 $OSM_DEVOPS/installers/install_lxd.sh ${LXD_INSTALL_OPTS} || FATAL_TRACK lxd "install_lxd.sh failed"
409 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
410}
411
412function install_docker_ce() {
413 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
414 DOCKER_CE_OPTS="-D ${OSM_DEVOPS} ${DEBUG_INSTALL}"
415 [ -n "${DOCKER_PROXY_URL}" ] && DOCKER_CE_OPTS="${DOCKER_CE_OPTS} -p ${DOCKER_PROXY_URL}"
416 [ -n "${OSM_BEHIND_PROXY}" ] && DOCKER_CE_OPTS="${DOCKER_CE_OPTS} -P"
417 $OSM_DEVOPS/installers/install_docker_ce.sh ${DOCKER_CE_OPTS} || FATAL_TRACK docker_ce "install_docker_ce.sh failed"
418 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
419}
420
421function install_k8s_cluster() {
422 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
423 if [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ]; then
424 KUBEADM_INSTALL_OPTS="-d ${OSM_WORK_DIR} -D ${OSM_DEVOPS} ${DEBUG_INSTALL}"
425 $OSM_DEVOPS/installers/install_kubeadm_cluster.sh ${KUBEADM_INSTALL_OPTS} || \
426 FATAL_TRACK k8scluster "install_kubeadm_cluster.sh failed"
garciadeblasb3797412024-06-06 14:26:24 +0200427 K8SCLUSTER_ADDONS_INSTALL_OPTS="-i ${OSM_DEFAULT_IP} -d ${OSM_WORK_DIR} -D ${OSM_DEVOPS} ${DEBUG_INSTALL} --all"
garciadeblas9bae86f2024-05-31 17:15:18 +0200428 $OSM_DEVOPS/installers/install_cluster_addons.sh ${K8SCLUSTER_ADDONS_INSTALL_OPTS} || \
garciadeblasb3797412024-06-06 14:26:24 +0200429 FATAL_TRACK k8scluster "install_cluster_addons.sh failed for kubeadm cluster"
430 elif [ "${K8S_CLUSTER_ENGINE}" == "k3s" ]; then
garciadeblas1f338482024-07-04 19:26:54 +0200431 K3S_INSTALL_OPTS="-i ${OSM_DEFAULT_IP} -D ${OSM_DEVOPS} ${DEBUG_INSTALL}"
garciadeblas117fd4a2024-08-21 18:18:14 +0200432 [ -n "${DOCKER_PROXY_URL}" ] && K3S_INSTALL_OPTS="${K3S_INSTALL_OPTS} -p ${DOCKER_PROXY_URL}"
garciadeblasb3797412024-06-06 14:26:24 +0200433 # The K3s installation script will automatically take the HTTP_PROXY, HTTPS_PROXY and NO_PROXY,
434 # as well as the CONTAINERD_HTTP_PROXY, CONTAINERD_HTTPS_PROXY and CONTAINERD_NO_PROXY variables
435 # from the shell, if they are present, and write them to the environment file of k3s systemd service,
436 $OSM_DEVOPS/installers/install_k3s_cluster.sh ${K3S_INSTALL_OPTS} || \
437 FATAL_TRACK k8scluster "install_k3s_cluster.sh failed"
438 K8SCLUSTER_ADDONS_INSTALL_OPTS="-i ${OSM_DEFAULT_IP} -d ${OSM_WORK_DIR} -D ${OSM_DEVOPS} ${DEBUG_INSTALL} --certmgr --nginx"
439 $OSM_DEVOPS/installers/install_cluster_addons.sh ${K8SCLUSTER_ADDONS_INSTALL_OPTS} || \
440 FATAL_TRACK k8scluster "install_cluster_addons.sh failed for k3s cluster"
garciadeblas9bae86f2024-05-31 17:15:18 +0200441 fi
442 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
443}
444
445function deploy_osm() {
garciadeblasb3797412024-06-06 14:26:24 +0200446 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblas9bae86f2024-05-31 17:15:18 +0200447 deploy_mongodb
448 track deploy_osm deploy_mongodb_ok
449 deploy_osm_helm_chart
450 track deploy_osm deploy_osm_services_k8s_ok
451 if [ -n "$INSTALL_NGSA" ]; then
452 # optional NGSA install
453 install_osm_ngsa_service
454 track deploy_osm install_osm_ngsa_ok
455 fi
garciadeblasb3797412024-06-06 14:26:24 +0200456 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblasfa3eb332022-11-15 14:11:56 +0100457}
458
459function install_osm() {
460 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
461
462 trap ctrl_c INT
463
garciadeblasfa3eb332022-11-15 14:11:56 +0100464 check_osm_behind_proxy
garciadeblasfa3eb332022-11-15 14:11:56 +0100465 check_packages "git wget curl tar snapd"
garciadeblas8375da12023-10-10 10:52:29 +0200466 if [ -n "${INSTALL_JUJU}" ]; then
467 sudo snap install jq || FATAL "Could not install jq (snap package). Make sure that snap works"
468 fi
garciadeblasfa3eb332022-11-15 14:11:56 +0100469 find_devops_folder
470
garciadeblas28d71bd2023-06-07 23:06:50 +0200471 track start release $RELEASE none none docker_tag $OSM_DOCKER_TAG none none installation_type $OSM_INSTALLATION_TYPE none none os_info $os_info none none
garciadeblasfa3eb332022-11-15 14:11:56 +0100472
473 track checks checkingroot_ok
474 [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
475 track checks noroot_ok
garciadeblasfa3eb332022-11-15 14:11:56 +0100476 ask_proceed
garciadeblas4d89c372021-11-25 11:57:18 +0100477 track checks proceed_ok
vijaynag8339ed22019-07-25 17:10:58 +0530478
garciadeblas0bc87522021-10-20 22:16:17 +0200479 echo "Installing OSM"
480
garciadeblas28d71bd2023-06-07 23:06:50 +0200481 [ -n "$DOCKER_REGISTRY_URL" ] && parse_docker_registry_url
482
garciadeblas0bc87522021-10-20 22:16:17 +0200483 echo "Determining IP address of the interface with the default route"
garciadeblas45ab04c2022-11-25 10:59:03 +0100484 [ -z "$OSM_DEFAULT_IF" ] && OSM_DEFAULT_IF=$(ip route list|awk '$1=="default" {print $5; exit}')
485 [ -z "$OSM_DEFAULT_IF" ] && OSM_DEFAULT_IF=$(route -n |awk '$1~/^0.0.0.0/ {print $8; exit}')
486 [ -z "$OSM_DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
487 OSM_DEFAULT_IP=`ip -o -4 a s ${OSM_DEFAULT_IF} |awk '{split($4,a,"/"); print a[1]; exit}'`
488 [ -z "$OSM_DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
garciadeblas0bc87522021-10-20 22:16:17 +0200489
490 # configure apt proxy
491 [ -n "$APT_PROXY_URL" ] && configure_apt_proxy $APT_PROXY_URL
Mike Marchettib8420852018-09-13 13:45:06 -0400492
garciadeblas8375da12023-10-10 10:52:29 +0200493 # if lxd is requested, we will install it
garciadeblas9bae86f2024-05-31 17:15:18 +0200494 [ -n "$INSTALL_LXD" ] && install_lxd
David Garcia79f4f532020-04-07 12:59:34 +0200495
garciadeblas4d89c372021-11-25 11:57:18 +0100496 track prereq prereqok_ok
Mike Marchettib8420852018-09-13 13:45:06 -0400497
garciadeblas250b0b62024-01-22 13:30:59 +0100498 if [ -n "$INSTALL_DOCKER" ] || [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ]; then
garciadeblas9c624882024-04-01 15:01:27 +0200499 if [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ]; then
500 echo "Kubeadm requires docker, so docker will be installed."
501 fi
garciadeblas9bae86f2024-05-31 17:15:18 +0200502 install_docker_ce
garciadeblas95804f82021-11-08 23:02:01 +0100503 fi
garciadeblas4d89c372021-11-25 11:57:18 +0100504 track docker_ce docker_ce_ok
David Garcia6cbfee12020-10-23 10:40:20 +0200505
garciadeblas8d8cd992024-05-21 16:04:14 +0200506 echo "Installing helm client ..."
garciadeblas9c624882024-04-01 15:01:27 +0200507 $OSM_DEVOPS/installers/install_helm_client.sh -D ${OSM_DEVOPS} ${DEBUG_INSTALL} || \
508 FATAL_TRACK k8scluster "install_helm_client.sh failed"
509 track helm_client install_helm_client_ok
510
garciadeblas8d8cd992024-05-21 16:04:14 +0200511 echo "Installing K8s cluster ..."
garciadeblas9bae86f2024-05-31 17:15:18 +0200512 install_k8s_cluster
garciadeblas8d8cd992024-05-21 16:04:14 +0200513 kubectl create namespace ${OSM_NAMESPACE}
garciadeblas9c624882024-04-01 15:01:27 +0200514 track k8scluster k8scluster_ok
David Garcia6cbfee12020-10-23 10:40:20 +0200515
garciadeblas8375da12023-10-10 10:52:29 +0200516 if [ -n "${INSTALL_JUJU}" ]; then
garciadeblas8d8cd992024-05-21 16:04:14 +0200517 echo "Installing Juju ..."
garciadeblas8375da12023-10-10 10:52:29 +0200518 JUJU_OPTS="-D ${OSM_DEVOPS} -s ${OSM_NAMESPACE} -i ${OSM_DEFAULT_IP} ${DEBUG_INSTALL} ${INSTALL_CACHELXDIMAGES}"
519 [ -n "${OSM_VCA_HOST}" ] && JUJU_OPTS="$JUJU_OPTS -H ${OSM_VCA_HOST}"
520 [ -n "${LXD_CLOUD_FILE}" ] && JUJU_OPTS="$JUJU_OPTS -l ${LXD_CLOUD_FILE}"
521 [ -n "${LXD_CRED_FILE}" ] && JUJU_OPTS="$JUJU_OPTS -L ${LXD_CRED_FILE}"
522 [ -n "${CONTROLLER_NAME}" ] && JUJU_OPTS="$JUJU_OPTS -K ${CONTROLLER_NAME}"
523 [ -n "${OSM_BEHIND_PROXY}" ] && JUJU_OPTS="${JUJU_OPTS} -P"
524 $OSM_DEVOPS/installers/install_juju.sh ${JUJU_OPTS} || FATAL_TRACK juju "install_juju.sh failed"
525 set_vca_variables
526 fi
garciadeblas4d89c372021-11-25 11:57:18 +0100527 track juju juju_ok
Adam Israel5ddc97f2019-09-03 18:11:12 -0400528
garciadeblas9bae86f2024-05-31 17:15:18 +0200529 # This track is maintained for backwards compatibility
garciadeblas4d89c372021-11-25 11:57:18 +0100530 track docker_images docker_images_ok
vijaynag8339ed22019-07-25 17:10:58 +0530531
garciadeblas8d8cd992024-05-21 16:04:14 +0200532 # Install mgmt cluster
533 echo "Installing mgmt cluster ..."
534 MGMTCLUSTER_INSTALL_OPTS="-D ${OSM_DEVOPS} ${DEBUG_INSTALL}"
535 [ -n "${INSTALL_MGMT_CLUSTER}" ] || MGMTCLUSTER_INSTALL_OPTS="${MGMTCLUSTER_INSTALL_OPTS} --no-mgmt-cluster"
536 [ -n "${INSTALL_AUX_CLUSTER}" ] || MGMTCLUSTER_INSTALL_OPTS="${MGMTCLUSTER_INSTALL_OPTS} --no-aux-cluster"
537 export KUBECONFIG_MGMT_CLUSTER=${KUBECONFIG_MGMT_CLUSTER:-"$HOME/.kube/config"}
538 export KUBECONFIG_AUX_CLUSTER=${KUBECONFIG_AUX_CLUSTER:-"$HOME/.kube/config"}
539 MGMTCLUSTER_INSTALL_OPTS="${MGMTCLUSTER_INSTALL_OPTS} -M ${KUBECONFIG_MGMT_CLUSTER}"
540 MGMTCLUSTER_INSTALL_OPTS="${MGMTCLUSTER_INSTALL_OPTS} -G ${KUBECONFIG_AUX_CLUSTER}"
541 echo "Options: ${MGMTCLUSTER_INSTALL_OPTS}"
542 $OSM_DEVOPS/installers/mgmt-cluster/install_mgmt_cluster.sh ${MGMTCLUSTER_INSTALL_OPTS} || \
543 FATAL_TRACK mgmtcluster "install_mgmt_cluster.sh failed"
544 track mgmtcluster mgmt_and_aux_cluster_ok
545
garciadeblas9bae86f2024-05-31 17:15:18 +0200546 # Deploy OSM (mongodb, OSM helm chart, NGSA)
garciadeblas8d8cd992024-05-21 16:04:14 +0200547 echo "Deploying OSM in the K8s cluster ..."
garciadeblas9bae86f2024-05-31 17:15:18 +0200548 deploy_osm
549
garciadeblas0bc87522021-10-20 22:16:17 +0200550 if [ -n "$INSTALL_K8S_MONITOR" ]; then
551 # install OSM MONITORING
552 install_k8s_monitoring
garciadeblas4d89c372021-11-25 11:57:18 +0100553 track deploy_osm install_k8s_monitoring_ok
vijaynag8339ed22019-07-25 17:10:58 +0530554 fi
555
garciadeblas8d8cd992024-05-21 16:04:14 +0200556 [ -z "$INSTALL_NOHOSTCLIENT" ] && echo "Installing osmclient ..." && install_osmclient
garciadeblas4d89c372021-11-25 11:57:18 +0100557 track osmclient osmclient_ok
beierlma4a37f72020-06-26 12:55:01 -0400558
garciadeblas4a9adcd2020-07-03 15:32:05 +0000559 echo -e "Checking OSM health state..."
garciadeblas325032a2023-04-13 18:07:44 +0200560 $OSM_DEVOPS/installers/osm_health.sh -s ${OSM_NAMESPACE} -k || \
garciadeblasf4f0e0f2021-12-03 11:37:40 +0100561 (echo -e "OSM is not healthy, but will probably converge to a healthy state soon." && \
garciadeblas325032a2023-04-13 18:07:44 +0200562 echo -e "Check OSM status with: kubectl -n ${OSM_NAMESPACE} get all" && \
garciadeblasf4f0e0f2021-12-03 11:37:40 +0100563 track healthchecks osm_unhealthy didnotconverge)
garciadeblas4d89c372021-11-25 11:57:18 +0100564 track healthchecks after_healthcheck_ok
vijaynag8339ed22019-07-25 17:10:58 +0530565
garciadeblas8d8cd992024-05-21 16:04:14 +0200566 echo -e "Adding local K8s cluster _system-osm-k8s to OSM ..."
garciadeblas0bc87522021-10-20 22:16:17 +0200567 add_local_k8scluster
garciadeblas4d89c372021-11-25 11:57:18 +0100568 track final_ops add_local_k8scluster_ok
garciadeblase92a18d2020-07-03 16:24:23 +0000569
garciadeblasb4c35932024-01-22 12:56:21 +0100570 # if lxd is requested, iptables firewall is updated to work with both docker and LXD
571 if [ -n "$INSTALL_LXD" ]; then
572 arrange_docker_default_network_policy
573 fi
Gulsum Atici5e263302023-01-30 19:11:31 +0300574
garciadeblase400dfd2023-12-12 21:53:43 +0100575 wget -q -O- https://osm-download.etsi.org/ftp/osm-15.0-fifteen/README2.txt &> /dev/null
garciadeblas6c66abf2018-05-16 14:46:19 +0200576 track end
garciadeblas0bc87522021-10-20 22:16:17 +0200577 sudo find /etc/osm
578 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblasd8bc5c32018-05-09 17:37:56 +0200579 return 0
580}
581
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200582function install_to_openstack() {
garciadeblas0bc87522021-10-20 22:16:17 +0200583 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200584
585 if [ -z "$2" ]; then
586 FATAL "OpenStack installer requires a valid external network name"
587 fi
588
589 # Install Pip for Python3
garciadeblas0bc87522021-10-20 22:16:17 +0200590 sudo apt install -y python3-pip python3-venv
591 sudo -H LC_ALL=C python3 -m pip install -U pip
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200592
Antonio Marsico75a38c72020-12-21 17:29:42 +0100593 # Create a venv to avoid conflicts with the host installation
594 python3 -m venv $OPENSTACK_PYTHON_VENV
595
596 source $OPENSTACK_PYTHON_VENV/bin/activate
597
Antonio Marsicoef3b2362021-03-19 18:54:57 +0100598 # Install Ansible, OpenStack client and SDK, latest openstack version supported is Train
Antonio Marsico75a38c72020-12-21 17:29:42 +0100599 python -m pip install -U wheel
Antonio Marsicoef3b2362021-03-19 18:54:57 +0100600 python -m pip install -U "python-openstackclient<=4.0.2" "openstacksdk>=0.12.0,<=0.36.2" "ansible>=2.10,<2.11"
Antonio Marsico75a38c72020-12-21 17:29:42 +0100601
602 # Install the Openstack cloud module (ansible>=2.10)
603 ansible-galaxy collection install openstack.cloud
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200604
605 export ANSIBLE_CONFIG="$OSM_DEVOPS/installers/openstack/ansible.cfg"
606
607 OSM_INSTALLER_ARGS="${REPO_ARGS[@]}"
608
Antonio Marsico75a38c72020-12-21 17:29:42 +0100609 ANSIBLE_VARS="external_network_name=$2 setup_volume=$3 server_name=$OPENSTACK_VM_NAME"
610
611 if [ -n "$OPENSTACK_SSH_KEY_FILE" ]; then
612 ANSIBLE_VARS+=" key_file=$OPENSTACK_SSH_KEY_FILE"
613 fi
614
615 if [ -n "$OPENSTACK_USERDATA_FILE" ]; then
616 ANSIBLE_VARS+=" userdata_file=$OPENSTACK_USERDATA_FILE"
617 fi
618
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200619 # Execute the Ansible playbook based on openrc or clouds.yaml
620 if [ -e "$1" ]; then
621 . $1
Antonio Marsico75a38c72020-12-21 17:29:42 +0100622 ansible-playbook -e installer_args="\"$OSM_INSTALLER_ARGS\"" -e "$ANSIBLE_VARS" \
623 $OSM_DEVOPS/installers/openstack/site.yml
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200624 else
Antonio Marsico75a38c72020-12-21 17:29:42 +0100625 ansible-playbook -e installer_args="\"$OSM_INSTALLER_ARGS\"" -e "$ANSIBLE_VARS" \
626 -e cloud_name=$1 $OSM_DEVOPS/installers/openstack/site.yml
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200627 fi
628
Antonio Marsico75a38c72020-12-21 17:29:42 +0100629 # Exit from venv
630 deactivate
631
garciadeblas0bc87522021-10-20 22:16:17 +0200632 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200633 return 0
634}
635
Gulsum Atici3d3a7672023-02-01 11:15:52 +0300636function arrange_docker_default_network_policy() {
637 echo -e "Fixing firewall so docker and LXD can share the same host without affecting each other."
638 sudo iptables -I DOCKER-USER -j ACCEPT
639 sudo iptables-save | sudo tee /etc/iptables/rules.v4
640 sudo ip6tables-save | sudo tee /etc/iptables/rules.v6
641}
642
romeromonsere366b1a2019-11-19 19:49:26 +0100643function install_k8s_monitoring() {
garciadeblas0bc87522021-10-20 22:16:17 +0200644 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
romeromonsere366b1a2019-11-19 19:49:26 +0100645 # install OSM monitoring
garciadeblasb9a84e42024-05-31 15:06:40 +0200646 sudo $OSM_DEVOPS/installers/k8s/install_osm_k8s_monitoring.sh -o ${OSM_NAMESPACE} || FATAL_TRACK install_k8s_monitoring "k8s/install_osm_k8s_monitoring.sh failed"
garciadeblas0bc87522021-10-20 22:16:17 +0200647 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
romeromonsere366b1a2019-11-19 19:49:26 +0100648}
649
garciadeblasd8bc5c32018-05-09 17:37:56 +0200650function dump_vars(){
garciadeblas0bc87522021-10-20 22:16:17 +0200651 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
652 echo "APT_PROXY_URL=$APT_PROXY_URL"
garciadeblas250b0b62024-01-22 13:30:59 +0100653 echo "K8S_CLUSTER_ENGINE=$K8S_CLUSTER_ENGINE"
garciadeblas0bc87522021-10-20 22:16:17 +0200654 echo "DEBUG_INSTALL=$DEBUG_INSTALL"
garciadeblas0bc87522021-10-20 22:16:17 +0200655 echo "DOCKER_PROXY_URL=$DOCKER_PROXY_URL"
656 echo "DOCKER_REGISTRY_URL=$DOCKER_REGISTRY_URL"
657 echo "DOCKER_USER=$DOCKER_USER"
658 echo "INSTALL_CACHELXDIMAGES=$INSTALL_CACHELXDIMAGES"
garciadeblas8375da12023-10-10 10:52:29 +0200659 echo "INSTALL_JUJU=$INSTALL_JUJU"
garciadeblas0bc87522021-10-20 22:16:17 +0200660 echo "INSTALL_K8S_MONITOR=$INSTALL_K8S_MONITOR"
garciadeblas0bc87522021-10-20 22:16:17 +0200661 echo "INSTALL_LXD=$INSTALL_LXD"
garciadeblas7b53d262022-11-04 23:18:48 +0100662 echo "INSTALL_NGSA=$INSTALL_NGSA"
garciadeblasf69804b2024-01-22 13:09:21 +0100663 echo "INSTALL_DOCKER=$INSTALL_DOCKER"
garciadeblas6c66abf2018-05-16 14:46:19 +0200664 echo "INSTALL_ONLY=$INSTALL_ONLY"
garciadeblasef3f37c2024-05-31 17:30:48 +0200665 echo "INSTALL_ONLY_DEPLOY_OSM=$INSTALL_ONLY_DEPLOY_OSM"
666 echo "INSTALL_ONLY_DOCKER_CE=$INSTALL_ONLY_DOCKER_CE"
667 echo "INSTALL_ONLY_K8S_CLUSTER=$INSTALL_ONLY_K8S_CLUSTER"
668 echo "INSTALL_ONLY_NGSA=$INSTALL_ONLY_NGSA"
garciadeblas0bc87522021-10-20 22:16:17 +0200669 echo "INSTALL_PLA=$INSTALL_PLA"
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200670 echo "INSTALL_TO_OPENSTACK=$INSTALL_TO_OPENSTACK"
garciadeblas0bc87522021-10-20 22:16:17 +0200671 echo "INSTALL_VIMEMU=$INSTALL_VIMEMU"
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200672 echo "OPENSTACK_PUBLIC_NET_NAME=$OPENSTACK_PUBLIC_NET_NAME"
673 echo "OPENSTACK_OPENRC_FILE_OR_CLOUD=$OPENSTACK_OPENRC_FILE_OR_CLOUD"
674 echo "OPENSTACK_ATTACH_VOLUME=$OPENSTACK_ATTACH_VOLUME"
Antonio Marsico75a38c72020-12-21 17:29:42 +0100675 echo "OPENSTACK_SSH_KEY_FILE"="$OPENSTACK_SSH_KEY_FILE"
676 echo "OPENSTACK_USERDATA_FILE"="$OPENSTACK_USERDATA_FILE"
677 echo "OPENSTACK_VM_NAME"="$OPENSTACK_VM_NAME"
garciadeblas0bc87522021-10-20 22:16:17 +0200678 echo "OSM_DEVOPS=$OSM_DEVOPS"
679 echo "OSM_DOCKER_TAG=$OSM_DOCKER_TAG"
garciadeblas7b53d262022-11-04 23:18:48 +0100680 echo "OSM_HELM_WORK_DIR=$OSM_HELM_WORK_DIR"
garciadeblas325032a2023-04-13 18:07:44 +0200681 echo "OSM_NAMESPACE=$OSM_NAMESPACE"
garciadeblas0bc87522021-10-20 22:16:17 +0200682 echo "OSM_VCA_HOST=$OSM_VCA_HOST"
683 echo "OSM_VCA_PUBKEY=$OSM_VCA_PUBKEY"
684 echo "OSM_VCA_SECRET=$OSM_VCA_SECRET"
685 echo "OSM_WORK_DIR=$OSM_WORK_DIR"
686 echo "PULL_IMAGES=$PULL_IMAGES"
687 echo "RECONFIGURE=$RECONFIGURE"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200688 echo "RELEASE=$RELEASE"
689 echo "REPOSITORY=$REPOSITORY"
690 echo "REPOSITORY_BASE=$REPOSITORY_BASE"
691 echo "REPOSITORY_KEY=$REPOSITORY_KEY"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200692 echo "SHOWOPTS=$SHOWOPTS"
garciadeblas0bc87522021-10-20 22:16:17 +0200693 echo "TEST_INSTALLER=$TEST_INSTALLER"
garciadeblas0bc87522021-10-20 22:16:17 +0200694 echo "UNINSTALL=$UNINSTALL"
695 echo "UPDATE=$UPDATE"
garciadeblas0bc87522021-10-20 22:16:17 +0200696 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblasd8bc5c32018-05-09 17:37:56 +0200697}
698
garciadeblas453d4582020-12-16 19:03:10 +0100699function parse_docker_registry_url() {
garciadeblas0bc87522021-10-20 22:16:17 +0200700 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
garciadeblas453d4582020-12-16 19:03:10 +0100701 DOCKER_REGISTRY_USER=$(echo "$DOCKER_REGISTRY_URL" | awk '{split($1,a,"@"); split(a[1],b,":"); print b[1]}')
702 DOCKER_REGISTRY_PASSWORD=$(echo "$DOCKER_REGISTRY_URL" | awk '{split($1,a,"@"); split(a[1],b,":"); print b[2]}')
703 DOCKER_REGISTRY_URL=$(echo "$DOCKER_REGISTRY_URL" | awk '{split($1,a,"@"); print a[2]}')
garciadeblas0bc87522021-10-20 22:16:17 +0200704 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
garciadeblas453d4582020-12-16 19:03:10 +0100705}
706
garciadeblasadcf95e2022-01-28 17:15:39 +0100707function ctrl_c() {
708 [ -z "${DEBUG_INSTALL}" ] || DEBUG beginning of function
709 echo "** Trapped CTRL-C"
710 FATAL "User stopped the installation"
711 [ -z "${DEBUG_INSTALL}" ] || DEBUG end of function
712}
713
garciadeblasd8bc5c32018-05-09 17:37:56 +0200714UNINSTALL=""
garciadeblasd8bc5c32018-05-09 17:37:56 +0200715UPDATE=""
716RECONFIGURE=""
717TEST_INSTALLER=""
718INSTALL_LXD=""
719SHOWOPTS=""
garciadeblasd8bc5c32018-05-09 17:37:56 +0200720ASSUME_YES=""
garciadeblas0bc87522021-10-20 22:16:17 +0200721APT_PROXY_URL=""
garciadeblasb3797412024-06-06 14:26:24 +0200722K8S_CLUSTER_ENGINE="k3s"
garciadeblas0bc87522021-10-20 22:16:17 +0200723DEBUG_INSTALL=""
garciadeblas18582e92024-05-21 12:13:50 +0200724RELEASE="testing-daily"
725REPOSITORY="testing"
garciadeblasfa3eb332022-11-15 14:11:56 +0100726INSTALL_K8S_MONITOR=""
garciadeblas836354f2023-05-10 18:12:00 +0200727INSTALL_NGSA="y"
garciadeblasfa3eb332022-11-15 14:11:56 +0100728INSTALL_PLA=""
729INSTALL_VIMEMU=""
garciadeblasd8bc5c32018-05-09 17:37:56 +0200730LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd"
731LXD_REPOSITORY_PATH=""
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200732INSTALL_TO_OPENSTACK=""
733OPENSTACK_OPENRC_FILE_OR_CLOUD=""
734OPENSTACK_PUBLIC_NET_NAME=""
735OPENSTACK_ATTACH_VOLUME="false"
Antonio Marsico75a38c72020-12-21 17:29:42 +0100736OPENSTACK_SSH_KEY_FILE=""
737OPENSTACK_USERDATA_FILE=""
738OPENSTACK_VM_NAME="server-osm"
739OPENSTACK_PYTHON_VENV="$HOME/.virtual-envs/osm"
garciadeblas6c66abf2018-05-16 14:46:19 +0200740INSTALL_ONLY=""
garciadeblasef3f37c2024-05-31 17:30:48 +0200741INSTALL_ONLY_DEPLOY_OSM=""
742INSTALL_ONLY_DOCKER_CE=""
743INSTALL_ONLY_K8S_CLUSTER=""
744INSTALL_ONLY_NGSA=""
garciadeblasb7166812024-01-22 13:16:26 +0100745INSTALL_DOCKER=""
garciadeblas8375da12023-10-10 10:52:29 +0200746INSTALL_JUJU=""
garciadeblas0d45bc82018-11-19 14:25:13 +0100747INSTALL_NOHOSTCLIENT=""
garciadeblas0bc87522021-10-20 22:16:17 +0200748INSTALL_CACHELXDIMAGES=""
garciadeblas8d8cd992024-05-21 16:04:14 +0200749INSTALL_AUX_CLUSTER="y"
750INSTALL_MGMT_CLUSTER="y"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200751OSM_DEVOPS=
lavadoe07b1642018-10-25 10:58:34 -0500752OSM_VCA_HOST=
753OSM_VCA_SECRET=
garciadeblasaa3ddf42019-04-04 19:04:32 +0200754OSM_VCA_PUBKEY=
David Garcia79f4f532020-04-07 12:59:34 +0200755OSM_VCA_CLOUDNAME="localhost"
beierlma4a37f72020-06-26 12:55:01 -0400756OSM_VCA_K8S_CLOUDNAME="k8scloud"
garciadeblas325032a2023-04-13 18:07:44 +0200757OSM_NAMESPACE=osm
Mike Marchettib8420852018-09-13 13:45:06 -0400758REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg"
garciadeblas870e60a2018-11-21 16:44:21 +0100759REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/debian"
Mike Marchettib8420852018-09-13 13:45:06 -0400760OSM_WORK_DIR="/etc/osm"
garciadeblas7b53d262022-11-04 23:18:48 +0100761OSM_HELM_WORK_DIR="${OSM_WORK_DIR}/helm"
vijaynag8339ed22019-07-25 17:10:58 +0530762OSM_HOST_VOL="/var/lib/osm"
garciadeblas325032a2023-04-13 18:07:44 +0200763OSM_NAMESPACE_VOL="${OSM_HOST_VOL}/${OSM_NAMESPACE}"
garciadeblas931a5122023-10-03 17:52:02 +0200764OSM_DOCKER_TAG="testing-daily"
garciadeblas0d45bc82018-11-19 14:25:13 +0100765DOCKER_USER=opensourcemano
766PULL_IMAGES="y"
Benjamin Diazaa0af712018-10-04 14:02:34 -0300767KAFKA_TAG=2.11-1.0.2
garciadeblas0ab16612022-02-22 14:23:57 +0100768KIWIGRID_K8S_SIDECAR_TAG="1.15.6"
769PROMETHEUS_TAG=v2.28.1
770GRAFANA_TAG=8.1.1
lavado6ad812e2019-11-29 10:58:58 -0500771PROMETHEUS_NODE_EXPORTER_TAG=0.18.1
772PROMETHEUS_CADVISOR_TAG=latest
lavado9a8df7c2018-10-24 09:35:34 -0500773KEYSTONEDB_TAG=10
Benjamin Diazba2cca92018-11-08 21:07:15 -0300774OSM_DATABASE_COMMONKEY=
lavado53eb8f52018-11-16 12:58:23 -0500775ELASTIC_VERSION=6.4.2
lavado4e8662c2018-11-28 11:28:14 -0500776ELASTIC_CURATOR_VERSION=5.5.4
vijaynag8339ed22019-07-25 17:10:58 +0530777POD_NETWORK_CIDR=10.244.0.0/16
778K8S_MANIFEST_DIR="/etc/kubernetes/manifests"
779RE_CHECK='^[a-z0-9]([-a-z0-9]*[a-z0-9])?$'
garciadeblas7f1e1042020-11-30 14:07:03 +0000780DOCKER_REGISTRY_URL=
781DOCKER_PROXY_URL=
782MODULE_DOCKER_TAG=
garciadeblas4d89c372021-11-25 11:57:18 +0100783OSM_INSTALLATION_TYPE="Default"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200784
garciadeblas8d8cd992024-05-21 16:04:14 +0200785while getopts ":a:c:r:n:k:u:R:D:o:O:N:H:S:s:t:U:P:A:l:L:K:d:p:T:f:F:G:M:-: hy" o; do
garciadeblasd8bc5c32018-05-09 17:37:56 +0200786 case "${o}" in
garciadeblas0bc87522021-10-20 22:16:17 +0200787 a)
788 APT_PROXY_URL=${OPTARG}
789 ;;
garciadeblas250b0b62024-01-22 13:30:59 +0100790 c)
791 K8S_CLUSTER_ENGINE=${OPTARG}
792 [ "${K8S_CLUSTER_ENGINE}" == "kubeadm" ] && continue
793 [ "${K8S_CLUSTER_ENGINE}" == "k3s" ] && continue
garciadeblas250b0b62024-01-22 13:30:59 +0100794 echo -e "Invalid argument for -c : ' ${K8S_CLUSTER_ENGINE}'\n" >&2
795 usage && exit 1
796 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200797 r)
Mike Marchettib8420852018-09-13 13:45:06 -0400798 REPOSITORY="${OPTARG}"
799 REPO_ARGS+=(-r "$REPOSITORY")
garciadeblasd8bc5c32018-05-09 17:37:56 +0200800 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200801 k)
Mike Marchettib8420852018-09-13 13:45:06 -0400802 REPOSITORY_KEY="${OPTARG}"
803 REPO_ARGS+=(-k "$REPOSITORY_KEY")
garciadeblasd8bc5c32018-05-09 17:37:56 +0200804 ;;
805 u)
Mike Marchettib8420852018-09-13 13:45:06 -0400806 REPOSITORY_BASE="${OPTARG}"
807 REPO_ARGS+=(-u "$REPOSITORY_BASE")
garciadeblasd8bc5c32018-05-09 17:37:56 +0200808 ;;
garciadeblas25e87d22020-01-31 14:27:29 +0100809 R)
810 RELEASE="${OPTARG}"
811 REPO_ARGS+=(-R "$RELEASE")
garciadeblas0d45bc82018-11-19 14:25:13 +0100812 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200813 D)
814 OSM_DEVOPS="${OPTARG}"
815 ;;
garciadeblas6c66abf2018-05-16 14:46:19 +0200816 o)
817 INSTALL_ONLY="y"
garciadeblasb5a630f2020-03-05 18:32:16 +0000818 [ "${OPTARG}" == "k8s_monitor" ] && INSTALL_K8S_MONITOR="y" && continue
garciadeblasef3f37c2024-05-31 17:30:48 +0200819 [ "${OPTARG}" == "ng-sa" ] && INSTALL_ONLY_NGSA="y" && continue
820 [ "${OPTARG}" == "docker" ] && INSTALL_ONLY_DOCKER_CE="y" && continue
821 [ "${OPTARG}" == "k8scluster" ] && INSTALL_ONLY_K8S_CLUSTER="y" && continue
822 [ "${OPTARG}" == "deploy-osm" ] && INSTALL_ONLY_DEPLOY_OSM="y" && continue
garciadeblas6c66abf2018-05-16 14:46:19 +0200823 ;;
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200824 O)
825 INSTALL_TO_OPENSTACK="y"
826 if [ -n "${OPTARG}" ]; then
827 OPENSTACK_OPENRC_FILE_OR_CLOUD="${OPTARG}"
828 else
829 echo -e "Invalid argument for -O : ' $OPTARG'\n" >&2
830 usage && exit 1
831 fi
832 ;;
Antonio Marsico75a38c72020-12-21 17:29:42 +0100833 f)
834 OPENSTACK_SSH_KEY_FILE="${OPTARG}"
835 ;;
836 F)
837 OPENSTACK_USERDATA_FILE="${OPTARG}"
838 ;;
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200839 N)
840 OPENSTACK_PUBLIC_NET_NAME="${OPTARG}"
841 ;;
garciadeblas25e87d22020-01-31 14:27:29 +0100842 H)
843 OSM_VCA_HOST="${OPTARG}"
844 ;;
845 S)
846 OSM_VCA_SECRET="${OPTARG}"
847 ;;
848 s)
garciadeblas325032a2023-04-13 18:07:44 +0200849 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 +0100850 ;;
851 t)
852 OSM_DOCKER_TAG="${OPTARG}"
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200853 REPO_ARGS+=(-t "$OSM_DOCKER_TAG")
garciadeblas25e87d22020-01-31 14:27:29 +0100854 ;;
855 U)
856 DOCKER_USER="${OPTARG}"
857 ;;
858 P)
859 OSM_VCA_PUBKEY=$(cat ${OPTARG})
860 ;;
861 A)
862 OSM_VCA_APIPROXY="${OPTARG}"
863 ;;
David Garcia79f4f532020-04-07 12:59:34 +0200864 l)
865 LXD_CLOUD_FILE="${OPTARG}"
866 ;;
867 L)
868 LXD_CRED_FILE="${OPTARG}"
869 ;;
David Garcia404ae122020-04-28 11:47:55 +0200870 K)
871 CONTROLLER_NAME="${OPTARG}"
872 ;;
garciadeblas7f1e1042020-11-30 14:07:03 +0000873 d)
874 DOCKER_REGISTRY_URL="${OPTARG}"
875 ;;
876 p)
877 DOCKER_PROXY_URL="${OPTARG}"
878 ;;
879 T)
880 MODULE_DOCKER_TAG="${OPTARG}"
881 ;;
garciadeblas8d8cd992024-05-21 16:04:14 +0200882 M)
883 KUBECONFIG_MGMT_CLUSTER="${OPTARG}"
884 ;;
885 G)
886 KUBECONFIG_AUX_CLUSTER="${OPTARG}"
887 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200888 -)
889 [ "${OPTARG}" == "help" ] && usage && exit 0
garciadeblas0bc87522021-10-20 22:16:17 +0200890 [ "${OPTARG}" == "debug" ] && DEBUG_INSTALL="--debug" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200891 [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue
garciadeblas8d8cd992024-05-21 16:04:14 +0200892 [ "${OPTARG}" == "no-mgmt-cluster" ] && INSTALL_MGMT_CLUSTER="" && continue
893 [ "${OPTARG}" == "no-aux-cluster" ] && INSTALL_AUX_CLUSTER="" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200894 [ "${OPTARG}" == "update" ] && UPDATE="y" && continue
895 [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue
896 [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
897 [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
garciadeblas8375da12023-10-10 10:52:29 +0200898 [ "${OPTARG}" == "lxd" ] && INSTALL_LXD="y" && continue
899 [ "${OPTARG}" == "nolxd" ] && INSTALL_LXD="" && continue
garciadeblasf69804b2024-01-22 13:09:21 +0100900 [ "${OPTARG}" == "docker" ] && INSTALL_DOCKER="y" && continue
901 [ "${OPTARG}" == "nodocker" ] && INSTALL_DOCKER="" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200902 [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue
garciadeblas8375da12023-10-10 10:52:29 +0200903 [ "${OPTARG}" == "juju" ] && INSTALL_JUJU="y" && continue
904 [ "${OPTARG}" == "nojuju" ] && INSTALL_JUJU="" && continue
Mike Marchettib8420852018-09-13 13:45:06 -0400905 [ "${OPTARG}" == "nohostclient" ] && INSTALL_NOHOSTCLIENT="y" && continue
garciadeblasb5a630f2020-03-05 18:32:16 +0000906 [ "${OPTARG}" == "k8s_monitor" ] && INSTALL_K8S_MONITOR="y" && continue
garciadeblas4d89c372021-11-25 11:57:18 +0100907 [ "${OPTARG}" == "charmed" ] && CHARMED="y" && OSM_INSTALLATION_TYPE="Charmed" && continue
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100908 [ "${OPTARG}" == "bundle" ] && continue
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +0200909 [ "${OPTARG}" == "k8s" ] && continue
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +0200910 [ "${OPTARG}" == "lxd-cred" ] && continue
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100911 [ "${OPTARG}" == "microstack" ] && continue
David Garcia4bd2bf02021-05-05 19:01:43 +0200912 [ "${OPTARG}" == "overlay" ] && continue
David Garcia1bc71022021-05-03 18:27:18 +0200913 [ "${OPTARG}" == "only-vca" ] && continue
aticig5d19ac22022-05-06 13:46:22 +0300914 [ "${OPTARG}" == "small-profile" ] && continue
Dominik Fleischmannc63bed62020-09-25 12:17:54 +0200915 [ "${OPTARG}" == "vca" ] && continue
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200916 [ "${OPTARG}" == "ha" ] && continue
David Garcia69388c22020-05-07 12:14:19 +0200917 [ "${OPTARG}" == "tag" ] && continue
beierlmf2782c52020-11-05 17:04:05 -0500918 [ "${OPTARG}" == "registry" ] && continue
magnussonl1bbe9452020-02-25 13:43:17 +0100919 [ "${OPTARG}" == "pla" ] && INSTALL_PLA="y" && continue
garciadeblas836354f2023-05-10 18:12:00 +0200920 [ "${OPTARG}" == "old-sa" ] && INSTALL_NGSA="" && continue
garciadeblas7b53d262022-11-04 23:18:48 +0100921 [ "${OPTARG}" == "ng-sa" ] && INSTALL_NGSA="y" && continue
Antonio Marsicof4ce57c2020-04-23 12:06:19 +0200922 [ "${OPTARG}" == "volume" ] && OPENSTACK_ATTACH_VOLUME="true" && continue
garciadeblas0bc87522021-10-20 22:16:17 +0200923 [ "${OPTARG}" == "nocachelxdimages" ] && continue
924 [ "${OPTARG}" == "cachelxdimages" ] && INSTALL_CACHELXDIMAGES="--cachelxdimages" && continue
garciadeblasd8bc5c32018-05-09 17:37:56 +0200925 echo -e "Invalid option: '--$OPTARG'\n" >&2
926 usage && exit 1
927 ;;
garciadeblas25e87d22020-01-31 14:27:29 +0100928 :)
929 echo "Option -$OPTARG requires an argument" >&2
930 usage && exit 1
931 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200932 \?)
933 echo -e "Invalid option: '-$OPTARG'\n" >&2
934 usage && exit 1
935 ;;
garciadeblas25e87d22020-01-31 14:27:29 +0100936 h)
937 usage && exit 0
938 ;;
garciadeblasd8bc5c32018-05-09 17:37:56 +0200939 y)
940 ASSUME_YES="y"
941 ;;
942 *)
943 usage && exit 1
944 ;;
945 esac
946done
947
garciadeblas0bc87522021-10-20 22:16:17 +0200948source $OSM_DEVOPS/common/all_funcs
garciadeblas6c66abf2018-05-16 14:46:19 +0200949
garciadeblas0bc87522021-10-20 22:16:17 +0200950[ -z "${DEBUG_INSTALL}" ] || DEBUG Debug is on
951[ -n "$SHOWOPTS" ] && dump_vars && exit 0
952
953# Uninstall if "--uninstall"
954if [ -n "$UNINSTALL" ]; then
955 if [ -n "$CHARMED" ]; then
garciadeblas4d89c372021-11-25 11:57:18 +0100956 ${OSM_DEVOPS}/installers/charmed_uninstall.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D $OSM_DEVOPS -t $DOCKER_TAG "$@" || \
957 FATAL_TRACK charmed_uninstall "charmed_uninstall.sh failed"
garciadeblas0bc87522021-10-20 22:16:17 +0200958 else
garciadeblas4d89c372021-11-25 11:57:18 +0100959 ${OSM_DEVOPS}/installers/uninstall_osm.sh "$@" || \
960 FATAL_TRACK community_uninstall "uninstall_osm.sh failed"
garciadeblas0bc87522021-10-20 22:16:17 +0200961 fi
962 echo -e "\nDONE"
garciadeblasd8bc5c32018-05-09 17:37:56 +0200963 exit 0
964fi
965
garciadeblas28d71bd2023-06-07 23:06:50 +0200966# Installation starts here
967
968# Get README and create OSM_TRACK_INSTALLATION_ID
garciadeblase400dfd2023-12-12 21:53:43 +0100969wget -q -O- https://osm-download.etsi.org/ftp/osm-15.0-fifteen/README.txt &> /dev/null
garciadeblas28d71bd2023-06-07 23:06:50 +0200970export OSM_TRACK_INSTALLATION_ID="$(date +%s)-$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)"
971
972# Get OS info to be tracked
973os_distro=$(lsb_release -i 2>/dev/null | awk '{print $3}')
974echo $os_distro
975os_release=$(lsb_release -r 2>/dev/null | awk '{print $2}')
976echo $os_release
977os_info="${os_distro}_${os_release}"
978os_info="${os_info// /_}"
979
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100980if [ -n "$CHARMED" ]; then
garciadeblas250b0b62024-01-22 13:30:59 +0100981 # Charmed installation
Mark Beierl70d6f3a2022-12-12 09:00:59 -0500982 sudo snap install jq || FATAL "Could not install jq (snap package). Make sure that snap works"
beierlmce7b4602022-04-13 08:19:40 -0400983 ${OSM_DEVOPS}/installers/charmed_install.sh --tag $OSM_DOCKER_TAG "$@" || \
garciadeblas4d89c372021-11-25 11:57:18 +0100984 FATAL_TRACK charmed_install "charmed_install.sh failed"
garciadeblase400dfd2023-12-12 21:53:43 +0100985 wget -q -O- https://osm-download.etsi.org/ftp/osm-15.0-fifteen/README2.txt &> /dev/null
garciadeblas0bc87522021-10-20 22:16:17 +0200986 echo -e "\nDONE"
987 exit 0
garciadeblas250b0b62024-01-22 13:30:59 +0100988elif [ -n "$INSTALL_TO_OPENSTACK" ]; then
989 # Installation to Openstack
garciadeblas0bc87522021-10-20 22:16:17 +0200990 install_to_openstack $OPENSTACK_OPENRC_FILE_OR_CLOUD $OPENSTACK_PUBLIC_NET_NAME $OPENSTACK_ATTACH_VOLUME
991 echo -e "\nDONE"
992 exit 0
garciadeblas250b0b62024-01-22 13:30:59 +0100993else
994 # Community_installer
garciadeblas250b0b62024-01-22 13:30:59 +0100995 # Special cases go first
garciadeblas9bae86f2024-05-31 17:15:18 +0200996 if [ -n "$INSTALL_ONLY" ]; then
garciadeblasef3f37c2024-05-31 17:30:48 +0200997 [ -n "$INSTALL_ONLY_DOCKER_CE" ] && install_docker_ce
998 [ -n "$INSTALL_ONLY_K8S_CLUSTER" ] && install_k8s_cluster
garciadeblas9bae86f2024-05-31 17:15:18 +0200999 [ -n "$INSTALL_K8S_MONITOR" ] && install_k8s_monitoring
garciadeblasef3f37c2024-05-31 17:30:48 +02001000 [ -n "$INSTALL_ONLY_DEPLOY_OSM" ] && deploy_osm
1001 [ -n "$INSTALL_ONLY_NGSA" ] && install_osm_ngsa_service
garciadeblas9bae86f2024-05-31 17:15:18 +02001002 echo -e "\nDONE" && exit 0
1003 fi
garciadeblas250b0b62024-01-22 13:30:59 +01001004 # This is where installation starts
1005 install_osm
1006 echo -e "\nDONE"
1007 exit 0
garciadeblas0bc87522021-10-20 22:16:17 +02001008fi