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