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