Remove unneeded mysql interface in PLA, fix osm-ha bundle, and add README.md to bundles
[osm/devops.git] / installers / charmed_install.sh
index d215608..e8eda63 100755 (executable)
@@ -16,6 +16,7 @@
 # set -eux
 
 K8S_CLOUD_NAME="k8s-cloud"
+KUBECTL="microk8s.kubectl"
 IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
 function check_arguments(){
     while [ $# -gt 0 ] ; do
@@ -41,15 +42,40 @@ function install_snaps(){
 
 function bootstrap_k8s_lxd(){
     [ -v CONTROLLER ] && ADD_K8S_OPTS="--controller ${CONTROLLER}" && CONTROLLER_NAME=$CONTROLLER
-    [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="controller"
+    [ ! -v CONTROLLER ] && ADD_K8S_OPTS="--client" && BOOTSTRAP_NEEDED="yes" && CONTROLLER_NAME="osm-vca"
+
+    if [ -v BOOTSTRAP_NEEDED ]; then
+        CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
+        if [ $CONTROLLER_PRESENT -ge 1 ]; then
+            cat << EOF
+Threre is already a VCA present with the installer reserved name of "${CONTROLLER_NAME}".
+You may either explicitly use this VCA with the "--vca ${CONTROLLER_NAME}" option, or remove it
+using this command:
+
+   juju destroy-controller --release-storage --destroy-all-models -y ${CONTROLLER_NAME}
+
+Please retry the installation once this conflict has been resolved.
+EOF
+            exit 1
+        fi
+    fi
 
     if [ -v KUBECFG ]; then
         cat $KUBECFG | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
-        [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME
+        [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME --config controller-service-type=loadbalancer
     else
+        sg microk8s -c "echo ${DEFAULT_IP}-${DEFAULT_IP} | microk8s.enable metallb"
         sg microk8s -c "microk8s.enable storage dns"
+        TIME_TO_WAIT=30
+        start_time="$(date -u +%s)"
         while true
         do
+            now="$(date -u +%s)"
+            if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
+                echo "Microk8s storage failed to enable"
+                sg microk8s -c "microk8s.status"
+                exit 1
+            fi
             sg microk8s -c "microk8s.status" | grep 'storage: enabled'
             if [ $? -eq 0 ]; then
                 break
@@ -58,7 +84,7 @@ function bootstrap_k8s_lxd(){
         done
 
         [ ! -v BOOTSTRAP_NEEDED ] && sg microk8s -c "microk8s.config" | juju add-k8s $K8S_CLOUD_NAME $ADD_K8S_OPTS
-        [ -v BOOTSTRAP_NEEDED ] && sg microk8s -c "juju bootstrap microk8s $CONTROLLER_NAME" && K8S_CLOUD_NAME=microk8s
+        [ -v BOOTSTRAP_NEEDED ] && sg microk8s -c "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer" && K8S_CLOUD_NAME=microk8s
     fi
 
     if [ -v LXD_CLOUD ]; then
@@ -117,7 +143,7 @@ EOF
     juju add-cloud -c $CONTROLLER_NAME lxd-cloud $LXD_CLOUD --force
     juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
     sg lxd -c "lxd waitready"
-    juju add-model test lxd-cloud || true
+    #juju add-model test lxd-cloud || true
     juju controller-config features=[k8s-operators]
 }
 
@@ -130,12 +156,11 @@ function deploy_charmed_osm(){
         sg microk8s -c "juju add-model osm $K8S_CLOUD_NAME"
     fi
     echo "Deploying OSM with charms"
-    # echo $BUNDLE
+    images_overlay=""
+    [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
     if [ -v BUNDLE ]; then
-        juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml
+        juju deploy $BUNDLE --overlay ~/.osm/vca-overlay.yaml $images_overlay
     else
-        images_overlay=""
-        [ -v TAG ] && generate_images_overlay && images_overlay="--overlay $IMAGES_OVERLAY_FILE"
         juju deploy osm --overlay ~/.osm/vca-overlay.yaml $images_overlay
     fi
     echo "Waiting for deployment to finish..."
@@ -168,16 +193,15 @@ function create_overlay() {
     local HOME=/home/$USER
     local vca_user=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].user')
     local vca_password=$(cat $HOME/.local/share/juju/accounts.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME].password')
-    local vca_host=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints"][0]' | cut -d ":" -f 1 | cut -d "\"" -f 2)
-    local vca_port=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["api-endpoints"][0]' | cut -d ":" -f 2 | cut -d "\"" -f 1)
+    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)
+    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)
     local vca_pubkey=\"$(cat $HOME/.local/share/juju/ssh/juju_id_rsa.pub)\"
     local vca_cloud="lxd-cloud"
     # Get the VCA Certificate
-    local vca_cacert=$(cat $HOME/.local/share/juju/controllers.yaml | yq --arg CONTROLLER_NAME $CONTROLLER_NAME '.controllers[$CONTROLLER_NAME]["ca-cert"]' | base64 | tr -d \\n)
+    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)
 
     # Calculate the default route of this machine
     local DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
-    local vca_apiproxy=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
 
     # Generate a new overlay.yaml, overriding any existing one
     cat << EOF > /tmp/vca-overlay.yaml
@@ -190,7 +214,6 @@ applications:
       vca_port: $vca_port
       vca_pubkey: $vca_pubkey
       vca_cacert: $vca_cacert
-      vca_apiproxy: $vca_apiproxy
       vca_cloud: $vca_cloud
       vca_k8s_cloud: $K8S_CLOUD_NAME
   mon-k8s:
@@ -225,6 +248,12 @@ applications:
   ui-k8s:
     options:
       image: opensourcemano/light-ui:$TAG
+  pla:
+    options:
+      image: opensourcemano/pla:$TAG
+  ng-ui:
+    options:
+      image: opensourcemano/ng-ui:$TAG
 
 EOF
     mv /tmp/images-overlay.yaml $IMAGES_OVERLAY_FILE
@@ -235,24 +264,6 @@ function install_osmclient() {
     sudo snap alias osmclient.osm osm
 }
 
-function create_iptables() {
-    check_install_iptables_persistent
-
-    if ! sudo iptables -t nat -C PREROUTING -p tcp -m tcp -d $DEFAULT_IP --dport 17070 -j DNAT --to-destination $OSM_VCA_HOST; then
-        sudo iptables -t nat -A PREROUTING -p tcp -m tcp -d $DEFAULT_IP --dport 17070 -j DNAT --to-destination $OSM_VCA_HOST
-        sudo netfilter-persistent save
-    fi
-}
-
-function check_install_iptables_persistent(){
-    echo -e "\nChecking required packages: iptables-persistent"
-    if ! dpkg -l iptables-persistent &>/dev/null; then
-        echo -e "    Not installed.\nInstalling iptables-persistent requires root privileges"
-        echo iptables-persistent iptables-persistent/autosave_v4 boolean true | sudo debconf-set-selections
-        echo iptables-persistent iptables-persistent/autosave_v6 boolean true | sudo debconf-set-selections
-        sudo apt-get -yq install iptables-persistent
-    fi
-}
 
 function install_microstack() {
     sudo snap install microstack --classic --beta
@@ -289,10 +300,26 @@ DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
 check_arguments $@
 mkdir -p ~/.osm
 install_snaps
+sleep 5
 bootstrap_k8s_lxd
 deploy_charmed_osm
-[ ! -v CONTROLLER ] && create_iptables
 install_osmclient
 if [ -v MICROSTACK ]; then
     install_microstack
 fi
+
+echo "Your installation is now complete, follow these steps for configuring the osmclient:"
+echo
+echo "1. Get the NBI IP with the following command:"
+echo
+echo NBI_IP='`juju status --format json | jq -rc '"'"'.applications."nbi-k8s".address'"'"'`'
+echo
+echo "2. Create the OSM_HOSTNAME environment variable with the NBI IP"
+echo
+echo "export OSM_HOSTNAME=\$NBI_IP"
+echo
+echo "3. Add the previous command to your .bashrc for other Shell sessions"
+echo
+echo "echo \"export OSM_HOSTNAME=\$NBI_IP\" >> ~/.bashrc"
+echo
+echo "DONE"