Fixes bug 1254 and bug 1247

Update the ingress rules to be explicit about version to avoid
extensions/v1beta1 Ingress is deprecated in v1.14+ message.
Use kubectl annotate instead of kubectl replace.
Ensure microk8s is in ready state before installing juju.
Report error if non-existing vca is requested.
Expose prometheus and grafana.

Change-Id: I0a8aa78c5c9be3163918c0b08b38b4c47d8fae6c
Signed-off-by: beierlm <mark.beierl@canonical.com>
diff --git a/installers/charmed_install.sh b/installers/charmed_install.sh
index 45a38c1..d0418a8 100755
--- a/installers/charmed_install.sh
+++ b/installers/charmed_install.sh
@@ -43,6 +43,7 @@
         mkdir -p ~/.kube
         sudo chown -f -R `whoami` ~/.kube
         KUBEGRP="microk8s"
+        microk8s status --wait-ready
     else
         KUBECTL="kubectl"
         sudo snap install kubectl --classic
@@ -70,6 +71,17 @@
 EOF
             exit 1
         fi
+    else
+        CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
+        if [ $CONTROLLER_PRESENT -le 0 ]; then
+            cat << EOF
+Threre is no VCA present with the name "${CONTROLLER_NAME}".  Please specify a VCA
+that exists, or remove the --vca ${CONTROLLER_NAME} option.
+
+Please retry the installation with one of the solutions applied.
+EOF
+            exit 1
+        fi
     fi
 
     if [ -v KUBECFG ]; then
@@ -79,6 +91,7 @@
             --agent-version=2.8.1
     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"
         TIME_TO_WAIT=30
         start_time="$(date -u +%s)"
@@ -158,7 +171,6 @@
     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 controller-config features=[k8s-operators]
 }
 
@@ -175,7 +187,7 @@
             exit 1
         fi
 
-        if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingress -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
+        if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
             break
         fi
         sleep 1
@@ -203,7 +215,6 @@
     check_osm_deployed
     echo "OSM with charms deployed"
     if [ ! -v KUBECFG ]; then
-        sg ${KUBEGRP} -c "microk8s.enable ingress"
         API_SERVER=${DEFAULT_IP}
     else
         API_SERVER=$(kubectl config view --minify | grep server | cut -f 2- -d ":" | tr -d " ")
@@ -215,29 +226,37 @@
     fi
 
     # Expose OSM services
+    # Expose Grafana
+    juju config grafana-k8s juju-external-hostname=grafana.${API_SERVER}.xip.io
+    juju expose grafana-k8s
+    wait_for_port grafana-k8s 0
+
     # Expose NBI
     juju config nbi-k8s juju-external-hostname=nbi.${API_SERVER}.xip.io
     juju expose nbi-k8s
+    wait_for_port nbi-k8s 1
 
     # Expose NG UI
     juju config ng-ui juju-external-hostname=ui.${API_SERVER}.xip.io
     juju expose ng-ui
+    wait_for_port ng-ui 2
+
+    # Expose Prometheus
+    juju config prometheus-k8s juju-external-hostname=prometheus.${API_SERVER}.xip.io
+    juju expose prometheus-k8s
+    wait_for_port prometheus-k8s 3
 
     # Expose UI
     juju config ui-k8s juju-external-hostname=osm.${API_SERVER}.xip.io
     juju expose ui-k8s
-
-    # Wait for ingress resources to be applied
-    wait_for_port nbi-k8s 0
-    wait_for_port ng-ui 1
-    wait_for_port ui-k8s 2
+    wait_for_port ui-k8s 4
 
     # Apply annotations
-    sg ${KUBEGRP} -c "${KUBECTL} annotate ingress nginx.ingress.kubernetes.io/backend-protocol=HTTPS -n osm -l juju-app=nbi-k8s"
-    sg ${KUBEGRP} -c "${KUBECTL} annotate ingress nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=nbi-k8s"
-    sg ${KUBEGRP} -c "${KUBECTL} annotate ingress nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ng-ui"
-    sg ${KUBEGRP} -c "${KUBECTL} annotate ingress nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ui-k8s"
-
+    sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/backend-protocol=HTTPS -n osm -l juju-app=nbi-k8s"
+    sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=nbi-k8s"
+    sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ng-ui"
+    sg ${KUBEGRP} -c "${KUBECTL} annotate ingresses.networking nginx.ingress.kubernetes.io/proxy-body-size=0 -n osm -l juju-app=ui-k8s"
+}
 
 function check_osm_deployed() {
     TIME_TO_WAIT=600