Move lcm certificate to lcm folder in OSM helm chart
[osm/devops.git] / installers / charmed_install.sh
index 844e646..1e406dd 100755 (executable)
 
 # set -eux
 
-LXD_VERSION=4.0
+LXD_VERSION=5.0
 JUJU_VERSION=2.9
-JUJU_AGENT_VERSION=2.9.33
+JUJU_AGENT_VERSION=2.9.43
 K8S_CLOUD_NAME="k8s-cloud"
 KUBECTL="microk8s.kubectl"
-MICROK8S_VERSION=1.23
+MICROK8S_VERSION=1.26
 OSMCLIENT_VERSION=latest
 IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
 PASSWORD_OVERLAY_FILE=~/.osm/password-overlay.yaml
 PATH=/snap/bin:${PATH}
 OSM_DEVOPS="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. &> /dev/null && pwd )"
+INSTALL_PLA=""
+PLA_OVERLAY_FILE=~/.osm/pla-overlay.yaml
+
 if [ -f ${OSM_DEVOPS}/common/all_funcs ] ; then
     source ${OSM_DEVOPS}/common/all_funcs
 else
@@ -59,6 +62,7 @@ function check_arguments(){
             --tag) TAG="$2" ;;
             --registry) REGISTRY_INFO="$2" ;;
             --only-vca) ONLY_VCA=y ;;
+            --pla) INSTALL_PLA=y ;;
         esac
         shift
     done
@@ -72,6 +76,11 @@ function install_snaps(){
         sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable ||
           FATAL_TRACK k8scluster "snap install microk8s ${MICROK8S_VERSION}/stable failed"
         sudo usermod -a -G microk8s `whoami`
+        # Workaround bug in calico MTU detection
+        if [ ${DEFAULT_IF_MTU} -ne 1500 ] ; then
+            sudo mkdir -p /var/lib/calico
+            sudo ln -sf /var/snap/microk8s/current/var/lib/calico/mtu /var/lib/calico/mtu
+        fi
         sudo cat /var/snap/microk8s/current/args/kube-apiserver | grep advertise-address || (
                 echo "--advertise-address $DEFAULT_IP" | sudo tee -a /var/snap/microk8s/current/args/kube-apiserver
                 sg ${KUBEGRP} -c microk8s.stop
@@ -133,7 +142,7 @@ EOF
     else
         sg ${KUBEGRP} -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
         sg ${KUBEGRP} -c "microk8s.enable ingress"
-        sg ${KUBEGRP} -c "microk8s.enable storage dns"
+        sg ${KUBEGRP} -c "microk8s.enable hostpath-storage dns"
         TIME_TO_WAIT=30
         start_time="$(date -u +%s)"
         while true
@@ -173,14 +182,16 @@ EOF
               sudo sysctl --system
               # Install LXD snap
               sudo apt-get remove --purge -y liblxc1 lxc-common lxcfs lxd lxd-client
-              sudo snap install lxd --channel $LXD_VERSION/stable
+              snap info lxd | grep installed > /dev/null
+              if [ $? -eq 0 ]; then
+                sudo snap refresh lxd --channel $LXD_VERSION/stable
+              else
+                sudo snap install lxd --channel $LXD_VERSION/stable
+              fi
               # Configure LXD
               sudo usermod -a -G lxd `whoami`
               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"
               sg lxd -c "lxd waitready"
-              DEFAULT_MTU=$(ip addr show $DEFAULT_IF | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
-              sg lxd -c "lxc profile device set default eth0 mtu $DEFAULT_MTU"
-              sg lxd -c "lxc network set lxdbr0 bridge.mtu $DEFAULT_MTU"
 
               cat << EOF > $LXD_CLOUD
 clouds:
@@ -254,10 +265,12 @@ function deploy_charmed_osm(){
 
     generate_password_overlay && secret_overlay="--overlay $PASSWORD_OVERLAY_FILE"
 
+    [ -n "$INSTALL_PLA" ] && create_pla_overlay && pla_overlay="--overlay $PLA_OVERLAY_FILE"
+
     if [ -v BUNDLE ]; then
-        juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $BUNDLE $images_overlay $extra_overlay $secret_overlay
+        juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $BUNDLE $images_overlay $extra_overlay $secret_overlay $pla_overlay
     else
-        juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $OSM_BUNDLE $images_overlay $extra_overlay $secret_overlay
+        juju deploy --trust --channel $CHARMHUB_CHANNEL -m $MODEL_NAME $OSM_BUNDLE $images_overlay $extra_overlay $secret_overlay $pla_overlay
     fi
 
     if [ ! -v KUBECFG ]; then
@@ -271,12 +284,20 @@ function deploy_charmed_osm(){
         API_SERVER="$(echo $hostport | sed -e 's,:.*,,g')"
     fi
     # Configure VCA Integrator
-    juju config vca \
-      k8s-cloud=microk8s \
-      lxd-cloud=lxd-cloud:lxd-cloud \
-      controllers="`cat ~/.local/share/juju/controllers.yaml`" \
-      accounts="`cat ~/.local/share/juju/accounts.yaml`" \
-      public-key="`cat ~/.local/share/juju/ssh/juju_id_rsa.pub`"
+    if [ ! -v INSTALL_NOLXD ]; then
+        juju config vca \
+          k8s-cloud=microk8s \
+          lxd-cloud=lxd-cloud:lxd-cloud \
+          controllers="`cat ~/.local/share/juju/controllers.yaml`" \
+          accounts="`cat ~/.local/share/juju/accounts.yaml`" \
+          public-key="`cat ~/.local/share/juju/ssh/juju_id_rsa.pub`"
+    else
+        juju config vca \
+          k8s-cloud=microk8s \
+          controllers="`cat ~/.local/share/juju/controllers.yaml`" \
+          accounts="`cat ~/.local/share/juju/accounts.yaml`" \
+          public-key="`cat ~/.local/share/juju/ssh/juju_id_rsa.pub`"
+    fi
     # Expose OSM services
     juju config -m $MODEL_NAME nbi external-hostname=nbi.${API_SERVER}.nip.io
     juju config -m $MODEL_NAME ng-ui external-hostname=ui.${API_SERVER}.nip.io
@@ -295,7 +316,8 @@ function deploy_charmed_osm(){
 function check_osm_deployed() {
     TIME_TO_WAIT=600
     start_time="$(date -u +%s)"
-    total_service_count=16
+    total_service_count=15
+    [ -n "$INSTALL_PLA" ] && total_service_count=$((total_service_count + 1))
     previous_count=0
     while true
     do
@@ -345,10 +367,34 @@ EOF
     mv /tmp/password-overlay.yaml $PASSWORD_OVERLAY_FILE
 }
 
+function create_pla_overlay(){
+    echo "Creating PLA Overlay"
+    [ $BUNDLE == $OSM_HA_BUNDLE ] && scale=3 || scale=1
+    cat << EOF > /tmp/pla-overlay.yaml
+applications:
+  pla:
+    charm: osm-pla
+    channel: latest/stable
+    scale: $scale
+    series: kubernetes
+    options:
+      log_level: DEBUG
+    resources:
+      image: opensourcemano/pla:testing-daily
+relations:
+  - - pla:kafka
+    - kafka:kafka
+  - - pla:mongodb
+    - mongodb:database
+EOF
+     mv /tmp/pla-overlay.yaml $PLA_OVERLAY_FILE
+}
+
 function generate_images_overlay(){
     echo "applications:" > /tmp/images-overlay.yaml
 
-    charms_with_resources="nbi lcm mon pol ng-ui ro pla"
+    charms_with_resources="nbi lcm mon pol ng-ui ro"
+    [ -n "$INSTALL_PLA" ] && charms_with_resources+=" pla"
     for charm in $charms_with_resources; do
         cat << EOF > /tmp/${charm}_registry.yaml
 registrypath: ${REGISTRY_URL}opensourcemano/${charm}:$TAG
@@ -361,7 +407,7 @@ EOF
         cat << EOF >> /tmp/images-overlay.yaml
   ${charm}:
     resources:
-      image: /tmp/${charm}_registry.yaml
+      ${charm}-image: /tmp/${charm}_registry.yaml
 
 EOF
     done
@@ -497,6 +543,7 @@ function install_microstack() {
 
 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5; exit}'`
 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]; exit}'`
+DEFAULT_IF_MTU=`ip a show ${DEFAULT_IF} | grep mtu | awk '{print $5}'`
 
 check_arguments $@
 mkdir -p ~/.osm