| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 1 | #! /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 Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 15 | |
| 16 | # set -eux |
| 17 | |
| 18 | K8S_CLOUD_NAME="k8s-cloud" |
| beierlm | dfd4288 | 2020-07-02 14:21:09 -0400 | [diff] [blame] | 19 | KUBECTL="microk8s.kubectl" |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 20 | IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 21 | function check_arguments(){ |
| 22 | while [ $# -gt 0 ] ; do |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 23 | case $1 in |
| 24 | --bundle) BUNDLE="$2" ;; |
| Dominik Fleischmann | 7a97a4c | 2020-06-04 10:52:05 +0200 | [diff] [blame] | 25 | --k8s) KUBECFG="$2" ;; |
| 26 | --vca) CONTROLLER="$2" ;; |
| 27 | --lxd) LXD_CLOUD="$2" ;; |
| 28 | --lxd-cred) LXD_CREDENTIALS="$2" ;; |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 29 | --microstack) MICROSTACK=y ;; |
| beierlm | 7e54dfc | 2020-09-24 15:27:53 -0400 | [diff] [blame] | 30 | --ha) BUNDLE="cs:osm-ha-39" ;; |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 31 | --tag) TAG="$2" ;; |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 32 | esac |
| 33 | shift |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 34 | done |
| 35 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 36 | # echo $BUNDLE $KUBECONFIG $LXDENDPOINT |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 37 | } |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 38 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 39 | function install_snaps(){ |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 40 | if [ ! -v KUBECFG ]; then |
| 41 | sudo snap install microk8s --classic |
| 42 | sudo usermod -a -G microk8s `whoami` |
| 43 | mkdir -p ~/.kube |
| 44 | sudo chown -f -R `whoami` ~/.kube |
| 45 | KUBEGRP="microk8s" |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 46 | microk8s status --wait-ready |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 47 | else |
| 48 | KUBECTL="kubectl" |
| 49 | sudo snap install kubectl --classic |
| 50 | export KUBECONFIG=${KUBECFG} |
| 51 | KUBEGRP=$(id -g -n) |
| 52 | fi |
| Dominik Fleischmann | 71997c1 | 2020-06-30 14:25:19 +0200 | [diff] [blame] | 53 | sudo snap install juju --classic --channel=2.8/stable |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | function bootstrap_k8s_lxd(){ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 57 | [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 58 | [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca" |
| 59 | |
| 60 | if [ -v BOOTSTRAP_NEEDED ]; then |
| 61 | CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l) |
| 62 | if [ $CONTROLLER_PRESENT -ge 1 ]; then |
| 63 | cat << EOF |
| 64 | Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}". |
| 65 | You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it |
| 66 | using this command: |
| 67 | |
| 68 | juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME} |
| 69 | |
| 70 | Please retry the installation once this conflict has been resolved. |
| 71 | EOF |
| 72 | exit 1 |
| 73 | fi |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 74 | else |
| 75 | CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l) |
| 76 | if [ $CONTROLLER_PRESENT -le 0 ]; then |
| 77 | cat << EOF |
| 78 | Threre is no VCA present with the name "${CONTROLLER_NAME}". Please specify a VCA |
| 79 | that exists, or remove the --vca ${CONTROLLER_NAME} option. |
| 80 | |
| 81 | Please retry the installation with one of the solutions applied. |
| 82 | EOF |
| 83 | exit 1 |
| 84 | fi |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 85 | fi |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 86 | |
| 87 | if [ -v KUBECFG ]; then |
| 88 | cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS |
| beierlm | 62e6044 | 2020-09-15 16:00:34 -0400 | [diff] [blame] | 89 | [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME \ |
| 90 | --config controller-service-type=loadbalancer \ |
| beierlm | c784e7c | 2020-09-30 06:03:45 -0400 | [diff] [blame] | 91 | --agent-version=2.8.1 |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 92 | else |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 93 | sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb" |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 94 | sg ${KUBEGRP} -c "microk8s.enable ingress" |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 95 | sg ${KUBEGRP} -c "microk8s.enable storage dns" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 96 | TIME_TO_WAIT=30 |
| 97 | start_time="$(date -u +%s)" |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 98 | while true |
| 99 | do |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 100 | now="$(date -u +%s)" |
| 101 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| 102 | echo "Microk8s storage failed to enable" |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 103 | sg ${KUBEGRP} -c "microk8s.status" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 104 | exit 1 |
| 105 | fi |
| calvinosanc1 | 698b5b3 | 2020-08-21 12:12:52 +0200 | [diff] [blame] | 106 | storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"` |
| 107 | if [[ $storage_status == "enabled" ]]; then |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 108 | break |
| 109 | fi |
| 110 | sleep 1 |
| 111 | done |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 112 | |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 113 | [ ! -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS |
| beierlm | 62e6044 | 2020-09-15 16:00:34 -0400 | [diff] [blame] | 114 | [ -v BOOTSTRAP_NEEDED ] && sg ${KUBEGRP} -c \ |
| 115 | "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=2.8.1" \ |
| 116 | && K8S_CLOUD_NAME=microk8s |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 117 | fi |
| 118 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 119 | if [ -v LXD_CLOUD ]; then |
| 120 | if [ ! -v LXD_CREDENTIALS ]; then |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 121 | echo "The installer needs the LXD server certificate if the LXD is external" |
| 122 | exit 1 |
| 123 | fi |
| 124 | else |
| 125 | LXDENDPOINT=$DEFAULT_IP |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 126 | LXD_CLOUD=~/.osm/lxd-cloud.yaml |
| 127 | LXD_CREDENTIALS=~/.osm/lxd-credentials.yaml |
| 128 | # Apply sysctl production values for optimal performance |
| 129 | sudo cp /usr/share/osm-devops/installers/60-lxd-production.conf /etc/sysctl.d/60-lxd-production.conf |
| 130 | sudo sysctl --system |
| 131 | # Install LXD snap |
| 132 | sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client |
| 133 | sudo snap install lxd |
| 134 | sudo apt-get install zfsutils-linux -y |
| 135 | # Configure LXD |
| 136 | sudo usermod -a -G lxd `whoami` |
| 137 | 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" |
| 138 | sg lxd -c "lxd waitready" |
| 139 | DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') |
| 140 | sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU" |
| David Garcia | d00e49c | 2020-06-19 10:33:37 +0200 | [diff] [blame] | 141 | sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 142 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 143 | cat << EOF > $LXD_CLOUD |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 144 | clouds: |
| 145 | lxd-cloud: |
| 146 | type: lxd |
| 147 | auth-types: [certificate] |
| 148 | endpoint: "https://$LXDENDPOINT:8443" |
| 149 | config: |
| 150 | ssl-hostname-verification: false |
| 151 | EOF |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 152 | 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" |
| 153 | local server_cert=`cat /var/snap/lxd/common/lxd/server.crt | sed 's/^/ /'` |
| 154 | local client_cert=`cat ~/.osm/client.crt | sed 's/^/ /'` |
| 155 | local client_key=`cat ~/.osm/client.key | sed 's/^/ /'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 156 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 157 | cat << EOF > $LXD_CREDENTIALS |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 158 | credentials: |
| 159 | lxd-cloud: |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 160 | lxd-cloud: |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 161 | auth-type: certificate |
| 162 | server-cert: | |
| 163 | $server_cert |
| 164 | client-cert: | |
| 165 | $client_cert |
| 166 | client-key: | |
| 167 | $client_key |
| 168 | EOF |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 169 | lxc config trust add local: ~/.osm/client.crt |
| 170 | fi |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 171 | |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 172 | juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force |
| 173 | juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS |
| 174 | sg lxd -c "lxd waitready" |
| Dominik Fleischmann | 71997c1 | 2020-06-30 14:25:19 +0200 | [diff] [blame] | 175 | juju controller-config features=[k8s-operators] |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 178 | function wait_for_port(){ |
| 179 | SERVICE=$1 |
| 180 | INDEX=$2 |
| 181 | TIME_TO_WAIT=30 |
| 182 | start_time="$(date -u +%s)" |
| 183 | while true |
| 184 | do |
| 185 | now="$(date -u +%s)" |
| 186 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| 187 | echo "Failed to expose external ${SERVICE} interface port" |
| 188 | exit 1 |
| 189 | fi |
| 190 | |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 191 | if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 192 | break |
| 193 | fi |
| 194 | sleep 1 |
| 195 | done |
| 196 | } |
| 197 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 198 | function deploy_charmed_osm(){ |
| 199 | create_overlay |
| 200 | echo "Creating OSM model" |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 201 | if [ -v KUBECFG ]; then |
| 202 | juju add-model osm $K8S_CLOUD_NAME |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 203 | else |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 204 | sg ${KUBEGRP} -c "juju add-model osm $K8S_CLOUD_NAME" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 205 | fi |
| 206 | echo "Deploying OSM with charms" |
| beierlm | b5332cf | 2020-07-08 11:43:59 -0400 | [diff] [blame] | 207 | images_overlay="" |
| 208 | [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE" |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 209 | if [ -v BUNDLE ]; then |
| beierlm | b5332cf | 2020-07-08 11:43:59 -0400 | [diff] [blame] | 210 | juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 211 | else |
| beierlm | 7e54dfc | 2020-09-24 15:27:53 -0400 | [diff] [blame] | 212 | juju deploy cs:osm-49 --overlay ~/.osm/vca-overlay.yaml $images_overlay |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 213 | fi |
| beierlm | 51b7128 | 2020-08-14 09:26:27 -0400 | [diff] [blame] | 214 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 215 | echo "Waiting for deployment to finish..." |
| beierlm | 51b7128 | 2020-08-14 09:26:27 -0400 | [diff] [blame] | 216 | check_osm_deployed |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 217 | echo "OSM with charms deployed" |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 218 | if [ ! -v KUBECFG ]; then |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 219 | API_SERVER=${DEFAULT_IP} |
| 220 | else |
| 221 | API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ") |
| 222 | proto="$(echo $API_SERVER | grep :// | sed -e's,^\(.*://\).*,\1,g')" |
| 223 | url="$(echo ${API_SERVER/$proto/})" |
| 224 | user="$(echo $url | grep @ | cut -d@ -f1)" |
| 225 | hostport="$(echo ${url/$user@/} | cut -d/ -f1)" |
| 226 | API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')" |
| 227 | fi |
| 228 | |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 229 | # Expose OSM services |
| 230 | # Expose Grafana |
| 231 | juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io |
| 232 | juju expose grafana-k8s |
| 233 | wait_for_port grafana-k8s 0 |
| 234 | |
| 235 | # Expose NBI |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 236 | juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io |
| 237 | juju expose nbi-k8s |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 238 | wait_for_port nbi-k8s 1 |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 239 | |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 240 | # Expose NG UI |
| beierlm | 51b7128 | 2020-08-14 09:26:27 -0400 | [diff] [blame] | 241 | juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 242 | juju expose ng-ui |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 243 | wait_for_port ng-ui 2 |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 244 | |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 245 | # Expose Prometheus |
| 246 | juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io |
| 247 | juju expose prometheus-k8s |
| 248 | wait_for_port prometheus-k8s 3 |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 249 | |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 250 | # Expose UI |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 251 | juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 252 | juju expose ui-k8s |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 253 | wait_for_port ui-k8s 4 |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 254 | |
| beierlm | c523396 | 2020-10-16 12:53:51 -0400 | [diff] [blame] | 255 | # Apply annotations |
| 256 | sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/backend-protocol=HTTPS -n osm -l juju-app=nbi-k8s" |
| 257 | sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=nbi-k8s" |
| 258 | sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ng-ui" |
| 259 | sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ui-k8s" |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | function check_osm_deployed() { |
| beierlm | 51b7128 | 2020-08-14 09:26:27 -0400 | [diff] [blame] | 263 | TIME_TO_WAIT=600 |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 264 | start_time="$(date -u +%s)" |
| beierlm | 7e54dfc | 2020-09-24 15:27:53 -0400 | [diff] [blame] | 265 | total_service_count=15 |
| 266 | previous_count=0 |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 267 | while true |
| 268 | do |
| beierlm | 51b7128 | 2020-08-14 09:26:27 -0400 | [diff] [blame] | 269 | service_count=$(juju status | grep kubernetes | grep active | wc -l) |
| 270 | echo "$service_count / $total_service_count services active" |
| 271 | if [ $service_count -eq $total_service_count ]; then |
| 272 | break |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 273 | fi |
| beierlm | 7e54dfc | 2020-09-24 15:27:53 -0400 | [diff] [blame] | 274 | if [ $service_count -ne $previous_count ]; then |
| 275 | previous_count=$service_count |
| 276 | start_time="$(date -u +%s)" |
| 277 | fi |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 278 | now="$(date -u +%s)" |
| 279 | if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then |
| beierlm | 51b7128 | 2020-08-14 09:26:27 -0400 | [diff] [blame] | 280 | echo "Timed out waiting for OSM services to become ready" |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 281 | exit 1 |
| 282 | fi |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 283 | sleep 10 |
| 284 | done |
| 285 | } |
| 286 | |
| 287 | function create_overlay() { |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 288 | sudo snap install jq |
| 289 | sudo apt install python3-pip -y |
| 290 | python3 -m pip install yq |
| 291 | PATH=$PATH:$HOME/.local/bin # make yq command available |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 292 | local HOME=/home/$USER |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 293 | local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user') |
| 294 | local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password') |
| beierlm | dfd4288 | 2020-07-02 14:21:09 -0400 | [diff] [blame] | 295 | local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints"][0]' --raw-output | cut -d ":" -f 1) |
| 296 | local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints"][0]' --raw-output | cut -d ":" -f 2) |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 297 | local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\" |
| 298 | local vca_cloud="lxd-cloud" |
| 299 | # Get the VCA Certificate |
| beierlm | dfd4288 | 2020-07-02 14:21:09 -0400 | [diff] [blame] | 300 | local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["ca-cert"]' --raw-output | base64 | tr -d \\n) |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 301 | |
| 302 | # Calculate the default route of this machine |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 303 | local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 304 | |
| 305 | # Generate a new overlay.yaml, overriding any existing one |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 306 | cat << EOF > /tmp/vca-overlay.yaml |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 307 | applications: |
| 308 | lcm-k8s: |
| 309 | options: |
| 310 | vca_user: $vca_user |
| 311 | vca_password: $vca_password |
| 312 | vca_host: $vca_host |
| 313 | vca_port: $vca_port |
| 314 | vca_pubkey: $vca_pubkey |
| 315 | vca_cacert: $vca_cacert |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 316 | vca_cloud: $vca_cloud |
| Dominik Fleischmann | 71997c1 | 2020-06-30 14:25:19 +0200 | [diff] [blame] | 317 | vca_k8s_cloud: $K8S_CLOUD_NAME |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 318 | mon-k8s: |
| 319 | options: |
| 320 | vca_user: $vca_user |
| 321 | vca_password: $vca_password |
| 322 | vca_host: $vca_host |
| 323 | vca_cacert: $vca_cacert |
| 324 | EOF |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 325 | mv /tmp/vca-overlay.yaml ~/.osm/ |
| 326 | OSM_VCA_HOST=$vca_host |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 327 | } |
| 328 | |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 329 | function generate_images_overlay(){ |
| 330 | cat << EOF > /tmp/images-overlay.yaml |
| 331 | applications: |
| 332 | lcm-k8s: |
| 333 | options: |
| 334 | image: opensourcemano/lcm:$TAG |
| 335 | mon-k8s: |
| 336 | options: |
| 337 | image: opensourcemano/mon:$TAG |
| 338 | ro-k8s: |
| 339 | options: |
| 340 | image: opensourcemano/ro:$TAG |
| 341 | nbi-k8s: |
| 342 | options: |
| 343 | image: opensourcemano/nbi:$TAG |
| 344 | pol-k8s: |
| 345 | options: |
| 346 | image: opensourcemano/pol:$TAG |
| 347 | ui-k8s: |
| 348 | options: |
| 349 | image: opensourcemano/light-ui:$TAG |
| David Garcia | 5863d3e | 2020-07-09 13:14:13 +0200 | [diff] [blame] | 350 | pla: |
| 351 | options: |
| 352 | image: opensourcemano/pla:$TAG |
| David Garcia | fa55bd7 | 2020-07-07 11:14:19 +0200 | [diff] [blame] | 353 | ng-ui: |
| 354 | options: |
| 355 | image: opensourcemano/ng-ui:$TAG |
| David Garcia | 69388c2 | 2020-05-07 12:14:19 +0200 | [diff] [blame] | 356 | |
| 357 | EOF |
| 358 | mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE |
| 359 | } |
| 360 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 361 | function install_osmclient() { |
| 362 | sudo snap install osmclient |
| 363 | sudo snap alias osmclient.osm osm |
| 364 | } |
| 365 | |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 366 | |
| 367 | function install_microstack() { |
| 368 | sudo snap install microstack --classic --beta |
| 369 | sudo microstack.init --auto |
| 370 | wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/ |
| 371 | microstack.openstack image create \ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 372 | --public \ |
| 373 | --disk-format qcow2 \ |
| 374 | --container-format bare \ |
| 375 | --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \ |
| 376 | ubuntu1604 |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 377 | ssh-keygen -t rsa -N "" -f ~/.ssh/microstack |
| 378 | microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 379 | export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s".address'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 380 | osm vim-create --name microstack-site \ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 381 | --user admin \ |
| 382 | --password keystone \ |
| 383 | --auth_url http://10.20.20.1:5000/v3 \ |
| 384 | --tenant admin \ |
| 385 | --account_type openstack \ |
| 386 | --config='{security_groups: default, |
| 387 | keypair: microstack, |
| 388 | project_name: admin, |
| 389 | user_domain_name: default, |
| 390 | region_name: microstack, |
| 391 | insecure: True, |
| 392 | availability_zone: nova, |
| 393 | version: 3}' |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 394 | } |
| 395 | |
| Dominik Fleischmann | c57296f | 2020-06-09 11:45:08 +0200 | [diff] [blame] | 396 | DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'` |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 397 | DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'` |
| 398 | |
| 399 | check_arguments $@ |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 400 | mkdir -p ~/.osm |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 401 | install_snaps |
| 402 | bootstrap_k8s_lxd |
| 403 | deploy_charmed_osm |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 404 | install_osmclient |
| David Garcia | 4237521 | 2020-04-27 19:07:49 +0200 | [diff] [blame] | 405 | if [ -v MICROSTACK ]; then |
| Dominik Fleischmann | 5e4a751 | 2020-03-06 14:05:06 +0100 | [diff] [blame] | 406 | install_microstack |
| 407 | fi |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 408 | |
| beierlm | 7e54dfc | 2020-09-24 15:27:53 -0400 | [diff] [blame] | 409 | OSM_HOSTNAME=$(juju config nbi-k8s juju-external-hostname):443 |
| 410 | |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 411 | echo "Your installation is now complete, follow these steps for configuring the osmclient:" |
| 412 | echo |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 413 | echo "1. Create the OSM_HOSTNAME environment variable with the NBI IP" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 414 | echo |
| beierlm | 7e54dfc | 2020-09-24 15:27:53 -0400 | [diff] [blame] | 415 | echo "export OSM_HOSTNAME=$OSM_HOSTNAME" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 416 | echo |
| beierlm | 838e3fd | 2020-07-28 09:21:07 -0400 | [diff] [blame] | 417 | echo "2. Add the previous command to your .bashrc for other Shell sessions" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 418 | echo |
| beierlm | 7e54dfc | 2020-09-24 15:27:53 -0400 | [diff] [blame] | 419 | echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc" |
| beierlm | 9425dd2 | 2020-07-16 16:57:09 -0400 | [diff] [blame] | 420 | echo |
| 421 | echo "DONE" |