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