blob: 7b0c48f8192a3c0aaece0198e3beefff3514bb58 [file] [log] [blame]
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +01001#! /bin/bash
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
David Garcia42375212020-04-27 19:07:49 +020015
16# set -eux
17
garciadeblase38e8b12022-09-27 16:49:31 +020018LXD_VERSION=5.0
David Garciad68e0b42021-06-28 16:50:42 +020019JUJU_VERSION=2.9
Mark Beierl19038052022-10-13 09:03:04 -040020JUJU_AGENT_VERSION=2.9.34
David Garcia42375212020-04-27 19:07:49 +020021K8S_CLOUD_NAME="k8s-cloud"
beierlm3749e312020-07-02 14:21:09 -040022KUBECTL="microk8s.kubectl"
Patricia Reinoso57b89ae2023-03-14 16:06:32 +000023MICROK8S_VERSION=1.26
David Garcia53a09d82022-02-01 16:39:44 +010024OSMCLIENT_VERSION=latest
David Garcia69388c22020-05-07 12:14:19 +020025IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
aticig6eb39282022-02-24 00:34:52 +030026PASSWORD_OVERLAY_FILE=~/.osm/password-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -050027PATH=/snap/bin:${PATH}
beierlmce7b4602022-04-13 08:19:40 -040028OSM_DEVOPS="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. &> /dev/null && pwd )"
Patricia Reinoso58ac3a52022-09-01 15:18:13 +020029INSTALL_PLA=""
30PLA_OVERLAY_FILE=~/.osm/pla-overlay.yaml
31
beierlmce7b4602022-04-13 08:19:40 -040032if [ -f ${OSM_DEVOPS}/common/all_funcs ] ; then
33 source ${OSM_DEVOPS}/common/all_funcs
34else
35 function track(){
36 true
37 }
38 function FATAL_TRACK(){
39 exit 1
40 }
41fi
beierlmf2782c52020-11-05 17:04:05 -050042
David Garciaef349d92020-12-10 21:16:12 +010043MODEL_NAME=osm
44
David Garcia4a0db7c2022-02-21 11:48:11 +010045OSM_BUNDLE=ch:osm
46OSM_HA_BUNDLE=ch:osm-ha
aticigabef99c2022-08-23 15:13:23 +030047CHARMHUB_CHANNEL=latest/beta
David Garcia4a0db7c2022-02-21 11:48:11 +010048unset TAG
David Garciaab11f842020-12-16 17:25:15 +010049
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010050function check_arguments(){
51 while [ $# -gt 0 ] ; do
David Garcia42375212020-04-27 19:07:49 +020052 case $1 in
53 --bundle) BUNDLE="$2" ;;
David Garcia4bd2bf02021-05-05 19:01:43 +020054 --overlay) OVERLAY="$2" ;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020055 --k8s) KUBECFG="$2" ;;
56 --vca) CONTROLLER="$2" ;;
aticig5d19ac22022-05-06 13:46:22 +030057 --small-profile) INSTALL_NOLXD=y;;
Dominik Fleischmann7a97a4c2020-06-04 10:52:05 +020058 --lxd) LXD_CLOUD="$2" ;;
59 --lxd-cred) LXD_CREDENTIALS="$2" ;;
David Garcia69388c22020-05-07 12:14:19 +020060 --microstack) MICROSTACK=y ;;
David Garciaab11f842020-12-16 17:25:15 +010061 --ha) BUNDLE=$OSM_HA_BUNDLE ;;
David Garcia69388c22020-05-07 12:14:19 +020062 --tag) TAG="$2" ;;
beierlmf2782c52020-11-05 17:04:05 -050063 --registry) REGISTRY_INFO="$2" ;;
David Garcia1bc71022021-05-03 18:27:18 +020064 --only-vca) ONLY_VCA=y ;;
Patricia Reinoso58ac3a52022-09-01 15:18:13 +020065 --pla) INSTALL_PLA=y ;;
David Garcia42375212020-04-27 19:07:49 +020066 esac
67 shift
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010068 done
69
David Garcia42375212020-04-27 19:07:49 +020070 # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010071}
beierlma4a37f72020-06-26 12:55:01 -040072
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010073function install_snaps(){
beierlma4a37f72020-06-26 12:55:01 -040074 if [ ! -v KUBECFG ]; then
beierlmce7b4602022-04-13 08:19:40 -040075 KUBEGRP="microk8s"
76 sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable ||
77 FATAL_TRACK k8scluster "snap install microk8s ${MICROK8S_VERSION}/stable failed"
78 sudo usermod -a -G microk8s `whoami`
David Garcia9a59e3d2021-02-08 15:18:27 +010079 sudo cat /var/snap/microk8s/current/args/kube-apiserver | grep advertise-address || (
David Garcia107010b2021-01-15 12:58:59 +010080 echo "--advertise-address $DEFAULT_IP" | sudo tee -a /var/snap/microk8s/current/args/kube-apiserver
beierlmce7b4602022-04-13 08:19:40 -040081 sg ${KUBEGRP} -c microk8s.stop
82 sg ${KUBEGRP} -c microk8s.start
David Garcia107010b2021-01-15 12:58:59 +010083 )
beierlma4a37f72020-06-26 12:55:01 -040084 mkdir -p ~/.kube
85 sudo chown -f -R `whoami` ~/.kube
beierlmf2782c52020-11-05 17:04:05 -050086 sg ${KUBEGRP} -c "microk8s status --wait-ready"
beierlmdf6de3d2020-12-16 08:46:40 -050087 KUBECONFIG=~/.osm/microk8s-config.yaml
David Garcia107010b2021-01-15 12:58:59 +010088 sg ${KUBEGRP} -c "microk8s config" | tee ${KUBECONFIG}
beierlmce7b4602022-04-13 08:19:40 -040089 track k8scluster k8scluster_ok
beierlma4a37f72020-06-26 12:55:01 -040090 else
91 KUBECTL="kubectl"
92 sudo snap install kubectl --classic
93 export KUBECONFIG=${KUBECFG}
94 KUBEGRP=$(id -g -n)
95 fi
beierlmce7b4602022-04-13 08:19:40 -040096 sudo snap install juju --classic --channel=$JUJU_VERSION/stable ||
97 FATAL_TRACK juju "snap install juju ${JUJU_VERSION}/stable failed"
98 track juju juju_ok
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +010099}
100
101function bootstrap_k8s_lxd(){
David Garcia42375212020-04-27 19:07:49 +0200102 [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
beierlma4a37f72020-06-26 12:55:01 -0400103 [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
104
105 if [ -v BOOTSTRAP_NEEDED ]; then
106 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
107 if [ $CONTROLLER_PRESENT -ge 1 ]; then
108 cat << EOF
109Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
110You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
111using this command:
112
113 juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
114
115Please retry the installation once this conflict has been resolved.
116EOF
beierlmce7b4602022-04-13 08:19:40 -0400117 FATAL_TRACK bootstrap_k8s "VCA already present"
beierlma4a37f72020-06-26 12:55:01 -0400118 fi
beierlm9afb0ef2020-10-16 12:53:51 -0400119 else
120 CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
121 if [ $CONTROLLER_PRESENT -le 0 ]; then
122 cat << EOF
123Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA
124that exists, or remove the --vca ${CONTROLLER_NAME} option.
125
126Please retry the installation with one of the solutions applied.
127EOF
beierlmce7b4602022-04-13 08:19:40 -0400128 FATAL_TRACK bootstrap_k8s "Requested VCA not present"
beierlm9afb0ef2020-10-16 12:53:51 -0400129 fi
beierlma4a37f72020-06-26 12:55:01 -0400130 fi
David Garcia42375212020-04-27 19:07:49 +0200131
132 if [ -v KUBECFG ]; then
133 cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400134 [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \
135 --config controller-service-type=loadbalancer \
David Garciaa1376012020-10-19 15:42:42 +0200136 --agent-version=$JUJU_AGENT_VERSION
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100137 else
beierlma4a37f72020-06-26 12:55:01 -0400138 sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
beierlm9afb0ef2020-10-16 12:53:51 -0400139 sg ${KUBEGRP} -c "microk8s.enable ingress"
Patricia Reinoso57b89ae2023-03-14 16:06:32 +0000140 sg ${KUBEGRP} -c "microk8s.enable hostpath-storage dns"
beierlma4a37f72020-06-26 12:55:01 -0400141 TIME_TO_WAIT=30
142 start_time="$(date -u +%s)"
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200143 while true
144 do
beierlma4a37f72020-06-26 12:55:01 -0400145 now="$(date -u +%s)"
146 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
147 echo "Microk8s storage failed to enable"
148 sg ${KUBEGRP} -c "microk8s.status"
beierlmce7b4602022-04-13 08:19:40 -0400149 FATAL_TRACK bootstrap_k8s "Microk8s storage failed to enable"
beierlma4a37f72020-06-26 12:55:01 -0400150 fi
151 storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
152 if [[ $storage_status == "enabled" ]]; then
Dominik Fleischmannc57296f2020-06-09 11:45:08 +0200153 break
154 fi
155 sleep 1
156 done
David Garcia42375212020-04-27 19:07:49 +0200157
beierlma4a37f72020-06-26 12:55:01 -0400158 [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
beierlm2634cd32020-09-15 16:00:34 -0400159 [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \
David Garciaa1376012020-10-19 15:42:42 +0200160 "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
beierlm2634cd32020-09-15 16:00:34 -0400161 && K8S_CLOUD_NAME=microk8s
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100162 fi
beierlmce7b4602022-04-13 08:19:40 -0400163 track bootstrap_k8s bootstrap_k8s_ok
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100164
aticig5d19ac22022-05-06 13:46:22 +0300165 if [ ! -v INSTALL_NOLXD ]; then
166 if [ -v LXD_CLOUD ]; then
167 if [ ! -v LXD_CREDENTIALS ]; then
168 echo "The installer needs the LXD server certificate if the LXD is external"
169 FATAL_TRACK bootstrap_lxd "No LXD certificate supplied"
170 fi
171 else
172 LXDENDPOINT=$DEFAULT_IP
173 LXD_CLOUD=~/.osm/lxd-cloud.yaml
174 LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml
175 # Apply sysctl production values for optimal performance
176 sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf
177 sudo sysctl --system
178 # Install LXD snap
179 sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
garciadeblase38e8b12022-09-27 16:49:31 +0200180 snap info lxd | grep installed > /dev/null
181 if [ $? -eq 0 ]; then
182 sudo snap refresh lxd --channel $LXD_VERSION/stable
183 else
184 sudo snap install lxd --channel $LXD_VERSION/stable
185 fi
aticig5d19ac22022-05-06 13:46:22 +0300186 # Configure LXD
187 sudo usermod -a -G lxd `whoami`
188 cat /usr/share/osm-devops/installers/lxd-preseed.conf | sed 's/^config: {}/config:\n core.https_address: '$LXDENDPOINT':8443/' | sg lxd -c "lxd init --preseed"
189 sg lxd -c "lxd waitready"
190 DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
191 sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
192 sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100193
aticig5d19ac22022-05-06 13:46:22 +0300194 cat << EOF > $LXD_CLOUD
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100195clouds:
196 lxd-cloud:
197 type: lxd
198 auth-types: [certificate]
199 endpoint: "https://$LXDENDPOINT:8443"
200 config:
201 ssl-hostname-verification: false
202EOF
aticig5d19ac22022-05-06 13:46:22 +0300203 openssl req -nodes -new -x509 -keyout ~/.osm/client.key -out ~/.osm/client.crt -days 365 -subj "/C=FR/ST=Nice/L=Nice/O=ETSI/OU=OSM/CN=osm.etsi.org"
aticig5d19ac22022-05-06 13:46:22 +0300204 cat << EOF > $LXD_CREDENTIALS
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100205credentials:
206 lxd-cloud:
David Garcia42375212020-04-27 19:07:49 +0200207 lxd-cloud:
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100208 auth-type: certificate
David Garciaf82897c2022-06-01 13:01:43 +0200209 server-cert: /var/snap/lxd/common/lxd/server.crt
210 client-cert: ~/.osm/client.crt
211 client-key: ~/.osm/client.key
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100212EOF
aticig5d19ac22022-05-06 13:46:22 +0300213 lxc config trust add local: ~/.osm/client.crt
214 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100215
aticig5d19ac22022-05-06 13:46:22 +0300216 juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
217 juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
218 sg lxd -c "lxd waitready"
219 juju controller-config features=[k8s-operators]
220 track bootstrap_lxd bootstrap_lxd_ok
221 fi
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100222}
223
224function deploy_charmed_osm(){
beierlmf2782c52020-11-05 17:04:05 -0500225 if [ -v REGISTRY_INFO ] ; then
226 registry_parts=(${REGISTRY_INFO//@/ })
227 if [ ${#registry_parts[@]} -eq 1 ] ; then
228 # No credentials supplied
229 REGISTRY_USERNAME=""
230 REGISTRY_PASSWORD=""
231 REGISTRY_URL=${registry_parts[0]}
232 else
233 credentials=${registry_parts[0]}
234 credential_parts=(${credentials//:/ })
235 REGISTRY_USERNAME=${credential_parts[0]}
236 REGISTRY_PASSWORD=${credential_parts[1]}
237 REGISTRY_URL=${registry_parts[1]}
238 fi
239 # Ensure the URL ends with a /
240 case $REGISTRY_URL in
241 */) ;;
242 *) REGISTRY_URL=${REGISTRY_URL}/
243 esac
244 fi
245
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100246 echo "Creating OSM model"
David Garcia42375212020-04-27 19:07:49 +0200247 if [ -v KUBECFG ]; then
David Garciaef349d92020-12-10 21:16:12 +0100248 juju add-model $MODEL_NAME $K8S_CLOUD_NAME
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100249 else
David Garciaef349d92020-12-10 21:16:12 +0100250 sg ${KUBEGRP} -c "juju add-model $MODEL_NAME $K8S_CLOUD_NAME"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100251 fi
252 echo "Deploying OSM with charms"
beierlma4a37f72020-06-26 12:55:01 -0400253 images_overlay=""
beierlmf2782c52020-11-05 17:04:05 -0500254 if [ -v REGISTRY_URL ]; then
255 [ ! -v TAG ] && TAG='latest'
256 fi
beierlma4a37f72020-06-26 12:55:01 -0400257 [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
beierlmf2782c52020-11-05 17:04:05 -0500258
David Garcia4bd2bf02021-05-05 19:01:43 +0200259 if [ -v OVERLAY ]; then
260 extra_overlay="--overlay $OVERLAY"
261 fi
aticig6eb39282022-02-24 00:34:52 +0300262 echo "Creating Password Overlay"
263
264 generate_password_overlay && secret_overlay="--overlay $PASSWORD_OVERLAY_FILE"
David Garcia4bd2bf02021-05-05 19:01:43 +0200265
Patricia Reinoso58ac3a52022-09-01 15:18:13 +0200266 [ -n "$INSTALL_PLA" ] && create_pla_overlay && pla_overlay="--overlay $PLA_OVERLAY_FILE"
267
David Garcia42375212020-04-27 19:07:49 +0200268 if [ -v BUNDLE ]; then
Patricia Reinoso58ac3a52022-09-01 15:18:13 +0200269 juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $BUNDLE $images_overlay $extra_overlay $secret_overlay $pla_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100270 else
Patricia Reinoso58ac3a52022-09-01 15:18:13 +0200271 juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $OSM_BUNDLE $images_overlay $extra_overlay $secret_overlay $pla_overlay
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100272 fi
beierlma4a37f72020-06-26 12:55:01 -0400273
beierlma4a37f72020-06-26 12:55:01 -0400274 if [ ! -v KUBECFG ]; then
beierlma4a37f72020-06-26 12:55:01 -0400275 API_SERVER=${DEFAULT_IP}
276 else
277 API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
278 proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')"
279 url="$(echo ${API_SERVER/$proto/})"
280 user="$(echo $url | grep @ | cut -d@ -f1)"
281 hostport="$(echo ${url/$user@/} | cut -d/ -f1)"
282 API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
283 fi
aticigabef99c2022-08-23 15:13:23 +0300284 # Configure VCA Integrator
Guillermo Calvinoba6b4e52023-01-05 12:20:24 +0100285 if [ ! -v INSTALL_NOLXD ]; then
286 juju config vca \
287 k8s-cloud=microk8s \
288 lxd-cloud=lxd-cloud:lxd-cloud \
289 controllers="`cat ~/.local/share/juju/controllers.yaml`" \
290 accounts="`cat ~/.local/share/juju/accounts.yaml`" \
291 public-key="`cat ~/.local/share/juju/ssh/juju_id_rsa.pub`"
292 else
293 juju config vca \
294 k8s-cloud=microk8s \
295 controllers="`cat ~/.local/share/juju/controllers.yaml`" \
296 accounts="`cat ~/.local/share/juju/accounts.yaml`" \
297 public-key="`cat ~/.local/share/juju/ssh/juju_id_rsa.pub`"
298 fi
David Garciade5fc1d2020-09-02 11:40:12 +0200299 # Expose OSM services
aticigabef99c2022-08-23 15:13:23 +0300300 juju config -m $MODEL_NAME nbi external-hostname=nbi.${API_SERVER}.nip.io
301 juju config -m $MODEL_NAME ng-ui external-hostname=ui.${API_SERVER}.nip.io
David Garciac395a452021-05-05 14:22:26 +0200302 juju config -m $MODEL_NAME grafana site_url=https://grafana.${API_SERVER}.nip.io
303 juju config -m $MODEL_NAME prometheus site_url=https://prometheus.${API_SERVER}.nip.io
David Garciaef349d92020-12-10 21:16:12 +0100304
David Garcia49379ce2021-02-24 13:48:22 +0100305 echo "Waiting for deployment to finish..."
306 check_osm_deployed
David Garciac537fa62021-11-09 08:45:49 +0100307 grafana_leader=`juju status -m $MODEL_NAME grafana | grep "*" | cut -d "*" -f 1`
308 grafana_admin_password=`juju run -m $MODEL_NAME --unit $grafana_leader "echo \\$GF_SECURITY_ADMIN_PASSWORD"`
aticigabef99c2022-08-23 15:13:23 +0300309 juju config -m $MODEL_NAME mon grafana-password=$grafana_admin_password
David Garciac537fa62021-11-09 08:45:49 +0100310 check_osm_deployed
David Garcia49379ce2021-02-24 13:48:22 +0100311 echo "OSM with charms deployed"
beierlm9afb0ef2020-10-16 12:53:51 -0400312}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100313
314function check_osm_deployed() {
beierlma4a37f72020-06-26 12:55:01 -0400315 TIME_TO_WAIT=600
316 start_time="$(date -u +%s)"
Patricia Reinoso58ac3a52022-09-01 15:18:13 +0200317 total_service_count=15
318 [ -n "$INSTALL_PLA" ] && total_service_count=$((total_service_count + 1))
beierlm7e54dfc2020-09-24 15:27:53 -0400319 previous_count=0
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100320 while true
321 do
beierlm67a34472022-03-25 12:23:36 -0400322 service_count=$(juju status --format json -m $MODEL_NAME | jq '.applications[]."application-status".current' | grep active | wc -l)
beierlma4a37f72020-06-26 12:55:01 -0400323 echo "$service_count / $total_service_count services active"
324 if [ $service_count -eq $total_service_count ]; then
325 break
326 fi
beierlm7e54dfc2020-09-24 15:27:53 -0400327 if [ $service_count -ne $previous_count ]; then
328 previous_count=$service_count
329 start_time="$(date -u +%s)"
330 fi
beierlma4a37f72020-06-26 12:55:01 -0400331 now="$(date -u +%s)"
332 if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
333 echo "Timed out waiting for OSM services to become ready"
beierlmce7b4602022-04-13 08:19:40 -0400334 FATAL_TRACK deploy_osm "Timed out waiting for services to become ready"
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100335 fi
336 sleep 10
337 done
338}
339
aticig6eb39282022-02-24 00:34:52 +0300340function generate_password_overlay() {
341 # prometheus
David Garcia8fa78072022-04-27 13:43:42 +0200342 web_config_password=`openssl rand -hex 16`
aticig6eb39282022-02-24 00:34:52 +0300343 # keystone
David Garcia8fa78072022-04-27 13:43:42 +0200344 keystone_db_password=`openssl rand -hex 16`
345 keystone_admin_password=`openssl rand -hex 16`
346 keystone_service_password=`openssl rand -hex 16`
aticig6eb39282022-02-24 00:34:52 +0300347 # mariadb
348 mariadb_password=`openssl rand -hex 16`
349 mariadb_root_password=`openssl rand -hex 16`
350 cat << EOF > /tmp/password-overlay.yaml
351applications:
352 prometheus:
353 options:
354 web_config_password: $web_config_password
355 keystone:
356 options:
357 keystone-db-password: $keystone_db_password
358 admin-password: $keystone_admin_password
359 service-password: $keystone_service_password
360 mariadb:
361 options:
362 password: $mariadb_password
363 root_password: $mariadb_root_password
364EOF
365 mv /tmp/password-overlay.yaml $PASSWORD_OVERLAY_FILE
366}
367
Patricia Reinoso58ac3a52022-09-01 15:18:13 +0200368function create_pla_overlay(){
369 echo "Creating PLA Overlay"
370 [ $BUNDLE == $OSM_HA_BUNDLE ] && scale=3 || scale=1
371 cat << EOF > /tmp/pla-overlay.yaml
372applications:
373 pla:
374 charm: osm-pla
375 channel: latest/stable
376 scale: $scale
377 series: kubernetes
378 options:
379 log_level: DEBUG
380 resources:
381 image: opensourcemano/pla:testing-daily
382relations:
383 - - pla:kafka
384 - kafka:kafka
385 - - pla:mongodb
386 - mongodb:database
387EOF
388 mv /tmp/pla-overlay.yaml $PLA_OVERLAY_FILE
389}
390
David Garcia69388c22020-05-07 12:14:19 +0200391function generate_images_overlay(){
David Garcia49379ce2021-02-24 13:48:22 +0100392 echo "applications:" > /tmp/images-overlay.yaml
beierlmf2782c52020-11-05 17:04:05 -0500393
Patricia Reinoso58ac3a52022-09-01 15:18:13 +0200394 charms_with_resources="nbi lcm mon pol ng-ui ro"
395 [ -n "$INSTALL_PLA" ] && charms_with_resources+=" pla"
David Garcia49379ce2021-02-24 13:48:22 +0100396 for charm in $charms_with_resources; do
397 cat << EOF > /tmp/${charm}_registry.yaml
398registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
beierlmf2782c52020-11-05 17:04:05 -0500399EOF
David Garcia49379ce2021-02-24 13:48:22 +0100400 if [ ! -z "$REGISTRY_USERNAME" ] ; then
401 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
402 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
403 fi
beierlmf2782c52020-11-05 17:04:05 -0500404
David Garcia49379ce2021-02-24 13:48:22 +0100405 cat << EOF >> /tmp/images-overlay.yaml
406 ${charm}:
David Garciaef349d92020-12-10 21:16:12 +0100407 resources:
Mark Beierlefdc6d02022-10-12 13:05:21 -0400408 ${charm}-image: /tmp/${charm}_registry.yaml
David Garcia49379ce2021-02-24 13:48:22 +0100409
David Garcia69388c22020-05-07 12:14:19 +0200410EOF
David Garcia49379ce2021-02-24 13:48:22 +0100411 done
David Garcia53a09d82022-02-01 16:39:44 +0100412 ch_charms_with_resources="keystone"
413 for charm in $ch_charms_with_resources; do
414 cat << EOF > /tmp/${charm}_registry.yaml
415registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
416EOF
417 if [ ! -z "$REGISTRY_USERNAME" ] ; then
418 echo username: $REGISTRY_USERNAME >> /tmp/${charm}_registry.yaml
419 echo password: $REGISTRY_PASSWORD >> /tmp/${charm}_registry.yaml
420 fi
421
422 cat << EOF >> /tmp/images-overlay.yaml
423 ${charm}:
424 resources:
425 ${charm}-image: /tmp/${charm}_registry.yaml
426
427EOF
428 done
David Garcia49379ce2021-02-24 13:48:22 +0100429
David Garcia69388c22020-05-07 12:14:19 +0200430 mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
431}
432
David Garcia107010b2021-01-15 12:58:59 +0100433function refresh_osmclient_snap() {
434 osmclient_snap_install_refresh refresh
435}
436
437function install_osm_client_snap() {
438 osmclient_snap_install_refresh install
439}
440
441function osmclient_snap_install_refresh() {
442 channel_preference="stable candidate beta edge"
443 for channel in $channel_preference; do
444 echo "Trying to install osmclient from channel $OSMCLIENT_VERSION/$channel"
445 sudo snap $1 osmclient --channel $OSMCLIENT_VERSION/$channel 2> /dev/null && echo osmclient snap installed && break
446 done
447}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100448function install_osmclient() {
David Garcia107010b2021-01-15 12:58:59 +0100449 snap info osmclient | grep -E ^installed: && refresh_osmclient_snap || install_osm_client_snap
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100450}
451
beierlmdf6de3d2020-12-16 08:46:40 -0500452function add_local_k8scluster() {
453 osm --all-projects vim-create \
454 --name _system-osm-vim \
455 --account_type dummy \
456 --auth_url http://dummy \
457 --user osm --password osm --tenant osm \
458 --description "dummy" \
459 --config '{management_network_name: mgmt}'
460 tmpfile=$(mktemp --tmpdir=${HOME})
461 cp ${KUBECONFIG} ${tmpfile}
462 osm --all-projects k8scluster-add \
463 --creds ${tmpfile} \
464 --vim _system-osm-vim \
465 --k8s-nets '{"net1": null}' \
466 --version '1.19' \
467 --description "OSM Internal Cluster" \
468 _system-osm-k8s
469 rm -f ${tmpfile}
470}
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100471
472function install_microstack() {
beierlmb403f062021-12-09 08:47:59 -0500473 sudo snap install microstack --beta --devmode
474
475 CHECK=$(microstack.openstack server list)
476 if [ $? -ne 0 ] ; then
477 if [[ $CHECK == *"not initialized"* ]]; then
478 echo "Setting MicroStack dashboard to listen to port 8080"
479 sudo snap set microstack config.network.ports.dashboard=8080
480 echo "Initializing MicroStack. This can take several minutes"
481 sudo microstack.init --auto --control
482 fi
483 fi
484
485 sudo snap alias microstack.openstack openstack
486
487 echo "Updating default security group in MicroStack to allow all access"
488
489 for i in $(microstack.openstack security group list | awk '/default/{ print $2 }'); do
490 for PROTO in icmp tcp udp ; do
491 echo " $PROTO ingress"
492 CHECK=$(microstack.openstack security group rule create $i --protocol $PROTO --remote-ip 0.0.0.0/0 2>&1)
493 if [ $? -ne 0 ] ; then
494 if [[ $CHECK != *"409"* ]]; then
495 echo "Error creating ingress rule for $PROTO"
496 echo $CHECK
497 fi
498 fi
499 done
500 done
501
502 microstack.openstack network show osm-ext &>/dev/null
503 if [ $? -ne 0 ]; then
504 echo "Creating osm-ext network with router to bridge to MicroStack external network"
505 microstack.openstack network create --enable --no-share osm-ext
506 microstack.openstack subnet create osm-ext-subnet --network osm-ext --dns-nameserver 8.8.8.8 \
507 --subnet-range 172.30.0.0/24
508 microstack.openstack router create external-router
509 microstack.openstack router add subnet external-router osm-ext-subnet
510 microstack.openstack router set --external-gateway external external-router
511 fi
512
513 microstack.openstack image list | grep ubuntu20.04 &> /dev/null
514 if [ $? -ne 0 ] ; then
515 echo "Fetching Ubuntu 20.04 image and upLoading to MicroStack"
516 wget -q -O- https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img \
517 | microstack.openstack image create --public --container-format=bare \
518 --disk-format=qcow2 ubuntu20.04 | grep status
519 fi
520
521 if [ ! -f ~/.ssh/microstack ]; then
522 ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
523 microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
524 fi
525
526 echo "Creating VIM microstack-site in OSM"
527 . /var/snap/microstack/common/etc/microstack.rc
528
529 osm vim-create \
530 --name microstack-site \
531 --user "$OS_USERNAME" \
532 --password "$OS_PASSWORD" \
533 --auth_url "$OS_AUTH_URL" \
534 --tenant "$OS_USERNAME" \
535 --account_type openstack \
536 --config='{use_floating_ip: True,
537 insecure: True,
538 keypair: microstack,
539 management_network_name: osm-ext}'
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100540}
541
beierlm4aad47b2021-12-07 16:15:53 -0500542DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5; exit}'`
543DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]; exit}'`
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100544
545check_arguments $@
David Garcia42375212020-04-27 19:07:49 +0200546mkdir -p ~/.osm
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100547install_snaps
548bootstrap_k8s_lxd
David Garcia1bc71022021-05-03 18:27:18 +0200549if [ -v ONLY_VCA ]; then
550 HOME=/home/$USER
aticigabef99c2022-08-23 15:13:23 +0300551 k8scloud=microk8s
552 lxdcloud=lxd-cloud:lxd-cloud
553 controllers="`cat $HOME/.local/share/juju/controllers.yaml`"
554 accounts="`cat $HOME/.local/share/juju/accounts.yaml`"
555 publickey="`cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub`"
556 echo "Use the following command to register the installed VCA to your OSM VCA integrator charm"
557 echo -e " juju config vca \\\n k8s-cloud=$k8scloud \\\n lxd-cloud=$lxdcloud \\\n controllers=$controllers \\\n accounts=$accounts \\\n public-key=$publickey"
beierlmce7b4602022-04-13 08:19:40 -0400558 track deploy_osm deploy_vca_only_ok
David Garcia1bc71022021-05-03 18:27:18 +0200559else
560 deploy_charmed_osm
beierlmce7b4602022-04-13 08:19:40 -0400561 track deploy_osm deploy_osm_services_k8s_ok
David Garcia1bc71022021-05-03 18:27:18 +0200562 install_osmclient
beierlmce7b4602022-04-13 08:19:40 -0400563 track osmclient osmclient_ok
aticigabef99c2022-08-23 15:13:23 +0300564 export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi external-hostname):443
aticig6eb39282022-02-24 00:34:52 +0300565 export OSM_PASSWORD=$keystone_admin_password
David Garcia1bc71022021-05-03 18:27:18 +0200566 sleep 10
567 add_local_k8scluster
beierlmce7b4602022-04-13 08:19:40 -0400568 track final_ops add_local_k8scluster_ok
David Garcia1bc71022021-05-03 18:27:18 +0200569 if [ -v MICROSTACK ]; then
570 install_microstack
beierlmce7b4602022-04-13 08:19:40 -0400571 track final_ops install_microstack_ok
David Garcia1bc71022021-05-03 18:27:18 +0200572 fi
573
574 echo "Your installation is now complete, follow these steps for configuring the osmclient:"
575 echo
576 echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP"
577 echo
578 echo "export OSM_HOSTNAME=$OSM_HOSTNAME"
aticig6eb39282022-02-24 00:34:52 +0300579 echo "export OSM_PASSWORD=$OSM_PASSWORD"
David Garcia1bc71022021-05-03 18:27:18 +0200580 echo
aticig6eb39282022-02-24 00:34:52 +0300581 echo "2. Add the previous commands to your .bashrc for other Shell sessions"
David Garcia1bc71022021-05-03 18:27:18 +0200582 echo
583 echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
aticig6eb39282022-02-24 00:34:52 +0300584 echo "echo \"export OSM_PASSWORD=$OSM_PASSWORD\" >> ~/.bashrc"
585 echo
586 echo "3. Login OSM GUI by using admin password: $OSM_PASSWORD"
David Garcia1bc71022021-05-03 18:27:18 +0200587 echo
588 echo "DONE"
beierlmce7b4602022-04-13 08:19:40 -0400589 track end
Dominik Fleischmann5e4a7512020-03-06 14:05:06 +0100590fi
beierlma4a37f72020-06-26 12:55:01 -0400591