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