Add HA option and minor fixes 59/9059/8
authorDominik Fleischmann <dominik.fleischmann@canonical.com>
Tue, 9 Jun 2020 09:45:08 +0000 (11:45 +0200)
committerbeierlm <mark.beierl@canonical.com>
Fri, 12 Jun 2020 20:44:55 +0000 (22:44 +0200)
This commit adds the --ha option which will
install the osm-ha bundle instead of the standard
osm bundle.

Additionally this commit includes the following
fixes:
- change the use of route to ip route which is
preinstalled in Ubuntu Desktop also.
- Change final command of post install osmclient
message
- Change post install osmclient message to be
only shown during install and not uninstall.
- Fix the deletion of the wrong model in uninstall
- Pining Juju snap to 2.7/stable

Change-Id: Iccf3bda7ec2f9a2279e5535d819e2a1968a59687
Signed-off-by: Dominik Fleischmann <dominik.fleischmann@canonical.com>
installers/charmed_install.sh
installers/charmed_uninstall.sh
installers/full_install_osm.sh
installers/install_osm.sh

index 62fa547..c2108d6 100755 (executable)
@@ -26,6 +26,7 @@ function check_arguments(){
             --lxd) LXD_CLOUD="$2" ;;
             --lxd-cred) LXD_CREDENTIALS="$2" ;;
             --microstack) MICROSTACK=y ;;
+            --ha) BUNDLE="osm-ha" ;;
             --tag) TAG="$2" ;;
         esac
         shift
@@ -34,8 +35,8 @@ function check_arguments(){
     # echo $BUNDLE $KUBECONFIG $LXDENDPOINT
 }
 function install_snaps(){
-    sudo snap install juju --classic
-    [ ! -v KUBECFG ] && sudo snap install microk8s --classic && sudo usermod -a -G microk8s ubuntu && mkdir -p ~/.kube && sudo chown -f -R `whoami` ~/.kube
+    sudo snap install juju --classic --channel=2.7/stable
+    [ ! -v KUBECFG ] && sudo snap install microk8s --classic && sudo usermod -a -G microk8s `whoami` && mkdir -p ~/.kube && sudo chown -f -R `whoami` ~/.kube
 }
 
 function bootstrap_k8s_lxd(){
@@ -47,6 +48,14 @@ function bootstrap_k8s_lxd(){
         [ -v BOOTSTRAP_NEEDED ] && juju bootstrap $K8S_CLOUD_NAME $CONTROLLER_NAME
     else
         sg microk8s -c "microk8s.enable storage dns"
+        while true
+        do
+            sg microk8s -c "microk8s.status" | grep 'storage: enabled'
+            if [ $? -eq 0 ]; then
+                break
+            fi
+            sleep 1
+        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
@@ -138,7 +147,8 @@ function deploy_charmed_osm(){
 function check_osm_deployed() {
     while true
     do
-        pod_name=`sg microk8s -c "microk8s.kubectl -n osm get pods | grep ui-k8s | grep -v operator" | awk '{print $1}'`
+        pod_name=`sg microk8s -c "microk8s.kubectl -n osm get pods | grep ui-k8s | grep -v operator" | awk '{print $1; exit}'`
+
         if [[ `sg microk8s -c "microk8s.kubectl -n osm wait pod $pod_name --for condition=Ready"` ]]; then
             if [[ `sg microk8s -c "microk8s.kubectl -n osm wait pod lcm-k8s-0 --for condition=Ready"` ]]; then
                 break
@@ -164,7 +174,7 @@ function create_overlay() {
     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)
 
     # Calculate the default route of this machine
-    local DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
+    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
@@ -253,7 +263,7 @@ function install_microstack() {
     ubuntu1604
     ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
     microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
-    export OSM_HOSTNAME=`juju status --format yaml | yq r - applications.nbi-k8s.address`
+    export OSM_HOSTNAME=`juju status --format json | jq -rc '.applications."nbi-k8s".address'`
     osm vim-create --name microstack-site \
     --user admin \
     --password keystone \
@@ -270,7 +280,7 @@ function install_microstack() {
     version: 3}'
 }
 
-DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
+DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
 DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
 
 check_arguments $@
index 6cee999..a310177 100755 (executable)
@@ -33,7 +33,7 @@ function remove_iptables() {
 }
 
 remove_iptables
-juju destroy-model osm-on-k8s --destroy-storage
-juju destroy-model test --destroy-storage
+juju destroy-model osm --destroy-storage -y
+juju destroy-model test --destroy-storage -y
 sudo snap unalias osm
 sudo snap remove osmclient
index 364a6cc..9999926 100755 (executable)
@@ -63,10 +63,11 @@ function usage(){
     echo -e "     --charmed:                   Deploy and operate OSM with Charms on k8s"
     echo -e "     [--bundle <bundle path>]:    Specify with which bundle to deploy OSM with charms (--charmed option)"
     echo -e "     [--k8s <kubeconfig path>]:   Specify with which kubernetes to deploy OSM with charms (--charmed option)"
-    echo -e "     [--vca <name>]:              Specifies the name of the controller to use - The controller must be already bootstrapped (--charmed option)" 
-    echo -e "     [--lxd <yaml path>]:         Takes a YAML file as a parameter with the LXD Cloud information (--charmed option)" 
+    echo -e "     [--vca <name>]:              Specifies the name of the controller to use - The controller must be already bootstrapped (--charmed option)"
+    echo -e "     [--lxd <yaml path>]:         Takes a YAML file as a parameter with the LXD Cloud information (--charmed option)"
     echo -e "     [--lxd-cred <yaml path>]:    Takes a YAML file as a parameter with the LXD Credentials information (--charmed option)"
     echo -e "     [--microstack]:              Installs microstack as a vim. (--charmed option)"
+    echo -e "     [--ha]:                      Installs High Availability bundle. (--charmed option)"
     echo -e "     [--tag]:                     Docker image tag"
 
 }
@@ -250,7 +251,7 @@ function check_install_iptables_persistent(){
 #Configure NAT rules, based on the current IP addresses of containers
 function nat(){
     check_install_iptables_persistent
-    
+
     echo -e "\nConfiguring NAT rules"
     echo -e "   Required root privileges"
     sudo $OSM_DEVOPS/installers/nat_osm
@@ -396,7 +397,7 @@ function install_docker_compose() {
 
 function install_juju() {
     echo "Installing juju"
-    sudo snap install juju --classic
+    sudo snap install juju --classic --channel=2.7/stable
     [[ ":$PATH": != *":/snap/bin:"* ]] && PATH="/snap/bin:${PATH}"
     echo "Finished installation of juju"
     return 0
@@ -527,7 +528,7 @@ function generate_docker_images() {
 
     if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q PROMETHEUS ; then
         sg docker -c "docker pull google/cadvisor:${PROMETHEUS_CADVISOR_TAG}" || FATAL "cannot get prometheus cadvisor docker image"
-    fi    
+    fi
 
     echo "Finished generation of docker images"
 }
@@ -1417,6 +1418,7 @@ while getopts ":b:r:c:k:u:R:D:o:m:H:S:s:w:t:U:P:A:l:L:K:-: hy" o; do
             [ "${OPTARG}" == "lxd" ] && continue
             [ "${OPTARG}" == "lxd-cred" ] && continue
             [ "${OPTARG}" == "microstack" ] && continue
+            [ "${OPTARG}" == "ha" ] && continue
             [ "${OPTARG}" == "tag" ] && continue
             [ "${OPTARG}" == "pla" ] && INSTALL_PLA="y" && continue
             echo -e "Invalid option: '--$OPTARG'\n" >&2
@@ -1455,23 +1457,23 @@ if [ -n "$CHARMED" ]; then
         /usr/share/osm-devops/installers/charmed_uninstall.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D /usr/share/osm-devops -t $DOCKER_TAG "$@"
      else
         /usr/share/osm-devops/installers/charmed_install.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D /usr/share/osm-devops -t $DOCKER_TAG "$@"
-     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 "juju status --format yaml | yq r - 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 "export OSM_HOSTNAME=<previous-IP> >> ~/.bashrc"
-     echo
-     echo "DONE"
+        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"
+     fi
 
      exit 0
 fi
index 4ede419..3659354 100755 (executable)
@@ -75,6 +75,7 @@ function usage(){
     echo -e "     [--lxd <yaml path>]:         Takes a YAML file as a parameter with the LXD Cloud information (--charmed option)" 
     echo -e "     [--lxd-cred <yaml path>]:    Takes a YAML file as a parameter with the LXD Credentials information (--charmed option)"
     echo -e "     [--microstack]:              Installs microstack as a vim. (--charmed option)"
+    echo -e "     [--ha]:                      Installs High Availability bundle. (--charmed option)"
     echo -e "     [--tag]:                     Docker image tag"
 
 }