VOL-3164 - add support for release name

Change-Id: I0ee72bdd50f953c3a02aa762e614aff35e850b8b
diff --git a/scripts/etcd-db-size.sh b/scripts/etcd-db-size.sh
index befb6a8..81f0765 100755
--- a/scripts/etcd-db-size.sh
+++ b/scripts/etcd-db-size.sh
@@ -17,11 +17,11 @@
 
 set -o pipefail
 
-ETCD=$(kubectl -n voltha get pods 2>&1 | grep etcd-cluster | awk '{print $1}' | head -1)
+ETCD=$(kubectl -n "$INFRA_NS" get pods 2>&1 | grep etcd | awk '{print $1}' | head -1)
 if [ -z  "$ETCD" ]; then
     echo "N/A"
 else
-    VALUE=$(kubectl -n voltha exec -ti $ETCD -- sh -c 'ETCDCTL_API=3 etcdctl --command-timeout=10s endpoint status -w json' 2>/dev/null | tr -d '\r\n' | jq .[].Status.dbSize 2>/dev/null)
+    VALUE=$(kubectl -n "$INFRA_NS" exec -ti $ETCD -- sh -c 'ETCDCTL_API=3 etcdctl --command-timeout=10s endpoint status -w json' 2>/dev/null | tr -d '\r\n' | jq .[].Status.dbSize 2>/dev/null)
     if [ -z "$VALUE" ]; then
         echo "N/A"
     else
diff --git a/scripts/monitor.sh b/scripts/monitor.sh
index 487b71b..2ad2d77 100755
--- a/scripts/monitor.sh
+++ b/scripts/monitor.sh
@@ -15,14 +15,39 @@
 
 # This script sets up a watch with information that is valuable when
 # developing voltha with k8s
-SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
+SCRIPTPATH="$( cd "$(dirname "$0")" || return  >/dev/null 2>&1 ; pwd -P )"
 
-CMD_KEY=cmd
-if [ "$ARCH" == "Darwin" ]; then
-    CMD_KEY=command
+if ! command -v kubectl >/dev/null 2>&1; then
+    >&2 echo "ERROR: 'kubectl' not in \$PATH"
+    exit 1
 fi
 
-kubectl get --all-namespaces pods,svc,configmap | grep -v kube-system  && echo "" \
-    &&  kubectl  describe --all-namespaces  pods | grep Image: | grep '\(voltha\|bbsim\)' | sed -e "s/^ *//g" -e "s/: */: /g"  && echo "" \
-    && echo "DB SIZE: $($SCRIPTPATH/etcd-db-size.sh)" && echo "" \
-    && echo "RSS SIZE: $(ps -eo rss,pid,$CMD_KEY | grep /usr/local/bin/etcd | grep -v grep | cut -d\  -f1 | numfmt --to=iec | tr '\n' ' ' )"
+echo "Kind (client): $(kind version)"
+kubectl version -o json | jq -r '"Kubernetes (client/server): "+.clientVersion.gitVersion+"/"+.serverVersion.gitVersion'
+helm version --template 'Helm: (client/server): {{ (index . "Client").SemVer }}/{{ (index . "Server").SemVer }}{{ printf "\n"}}'
+
+echo -n "Voltctl: (client/server): "
+if ! command -v voltctl >/dev/null 2>&1; then
+    echo "'voltctl' not in \$PATH"
+else
+    CLIENT=$(voltctl version --clientonly -o json | jq -r '"v"+.version')
+    JSON=$(voltctl version -o json 2>&1)
+    if [ "$?" -eq 0 ]; then
+        echo "$CLIENT/$(echo "$JSON" | jq -r '"/v"+.cluster.version' 2>&1)"
+    else
+        echo "$CLIENT/$JSON"
+    fi
+fi
+echo
+kubectl get --all-namespaces pods,svc,configmap | grep -v kube-system
+echo
+kubectl  describe --all-namespaces  pods | grep Image: | grep '\(voltha\|bbsim\)' | sed -e "s/^ *//g" -e "s/: */: /g"
+echo
+echo "DB SIZE: $("$SCRIPTPATH/etcd-db-size.sh")"
+echo
+PIDS=$(pgrep -f "etcd --name etcd")
+if [ -z "$PIDS" ]; then
+    echo "RSS SIZE: N/A"
+else
+    echo "RSS SIZE: $(ps -ho rss $PIDS | xargs numfmt --to=iec | tr '\n' ' ' )"
+fi
diff --git a/voltha b/voltha
index ff3897c..e85aaa1 100755
--- a/voltha
+++ b/voltha
@@ -819,32 +819,56 @@
     local PORTS="$*"
     local TAG=$SVC-$NAME
 
-    (set -x; _TAG="$TAG" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n $NS service/$SVC $PORTS; done" >>"$LOG" 2>&1 &) >>"$LOG" 2>&1
+    (set -x; _TAG="$TAG" bash -c "while true; do kubectl port-forward --address 0.0.0.0 -n $NS service/$SVC $PORTS; done" >>"$PFLOG" 2>&1 &) >>"$PFLOG" 2>&1
 }
 
 kill_port_forward() {
-    local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID
-    TAG=
-    if [ "$1" != "__ALL__" ]; then
-        TAG="$1-$NAME"
-    fi
-    # shellcheck disable=SC2009
-    P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
-    if [ -n "$P_IDS" ]; then
-        for P_ID in $P_IDS; do
-            PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
-            if [ -n "$PP_ID" ]; then
-                if [ "$PP_ID" -eq 1 ]; then
-                    PARENTS="$PARENTS $P_ID"
+    local TAG P_IDS PARENTS KIDS UNKNOWN PP_ID PF
+
+    while [ $# -gt 0 ]; do
+        PF=$1; shift
+        TAG=
+        if [ "$PF" != "__ALL__" ]; then
+            TAG="$PF-$NAME"
+        fi
+        PARENTS=
+        KIDS=
+        UNKNOWN=
+        # shellcheck disable=SC2009
+        P_IDS="$(ps e -ww -A | grep "_TAG=$TAG" | grep -v grep | awk '{print $1}')"
+        if [ -n "$P_IDS" ]; then
+            for P_ID in $P_IDS; do
+                PP_ID="$(ps -o ppid "$P_ID" | tail -n +2)"
+                if [ -n "$PP_ID" ]; then
+                    if [ "$PP_ID" -eq 1 ]; then
+                        PARENTS="$PARENTS $P_ID"
+                    else
+                        KIDS="$KIDS $P_ID"
+                    fi
                 else
-                    KIDS="$KIDS $P_ID"
+                    UNKNOWN="$UNKNOWN $P_ID"
                 fi
-            else
-                UNKNOWN="$UNKNOWN $P_ID"
+            done
+            if [ -n "$PARENTS" ]; then
+                # shellcheck disable=SC2086
+                while ps -h $PARENTS >/dev/null 2>&1; do
+                    (set -x; eval "kill -9 $PARENTS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
+                done
             fi
-        done
-        (set -x; eval "kill -9 $PARENTS $KIDS $UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
-    fi
+            if [ -n "$KIDS" ]; then
+                # shellcheck disable=SC2086
+                while ps -h $KIDS >/dev/null 2>&1; do
+                    (set -x; eval "kill -9 $KIDS" >>"$LOG" 2>&1) >>"$LOG" 2>&1
+                done
+            fi
+            if [ -n "$UNKNOWN" ]; then
+                # shellcheck disable=SC2086
+                while ps -h $UNKNOWN >/dev/null 2>&1; do
+                    (set -x; eval "kill -9 $UNKNOWN" >>"$LOG" 2>&1) >>"$LOG" 2>&1
+                done
+            fi
+        fi
+    done
 }
 
 resolve_chart_version() {
@@ -875,7 +899,7 @@
         kill_port_forward onos-onos-classic-hs
     fi
     sspin "Remove port-forwards: voltha-api-$NAME$CEOL"
-    kill_port_forward voltha-api
+    kill_port_forward voltha-api voltha-voltha-api
     if is_in "$WITH_ETCD" "yes,external"; then
         sspin "Remove port-forwards: etcd-$NAME$CEOL"
         kill_port_forward "etcd"
@@ -887,10 +911,10 @@
 
     if [ "$WITH_PPROF" == "yes" ]; then
         sspin "Remove port-forwards: *-profiler$CEOL"
-        kill_port_forward voltha-rw-core-profiler
-        kill_port_forward voltha-of-agent-profiler
+        kill_port_forward voltha-rw-core-profiler voltha-voltha-rw-core-profiler
+        kill_port_forward voltha-of-agent-profiler voltha-voltha-of-agent-profiler
         if [ "$WITH_OPEN_ADAPTERS" == "yes" ]; then
-            kill_port_forward adapter-open-olt-profiler
+            kill_port_forward adapter-open-olt-profiler open-olt-adapter-open-olt-profiler
         fi
     fi
 
@@ -1048,6 +1072,7 @@
 fi
 
 LOG="install-$NAME.log"
+PFLOG="port-forward-$NAME.log"
 date > "$LOG"
 echo "PORTS=$ONOS_API_PORT,$ONOS_SSH_PORT,$VOLTHA_API_PORT,$VOLTHA_SSH_PORT,$VOLTHA_ETCD_PORT" >> "$LOG"
 
@@ -1388,7 +1413,11 @@
         espin "$VERIFIED"
     fi
 
-    KUBECONFIG="$(kind get kubeconfig-path --name="voltha-$NAME")"; export KUBECONFIG
+    export KUBECONFIG="./kube-config-$NAME"
+    kind get kubeconfig --name="voltha-$NAME" >"$KUBECONFIG"
+    # For backward compatibility also copy to old location
+    cp "KUBECONFIG" "$HOME/.kube/kind-config-voltha-$NAME"
+
     P="coredns-.* \
         etcd-voltha-$NAME-control-plane \
         kindnet-.* \
@@ -2115,8 +2144,13 @@
 if [ "$WITH_PORT_FORWARDS" == "yes" ]; then
     STIME="$(date +%s)"
     bspin - "Forward VOLTHA API port $FORWARD"
-    kill_port_forward voltha-api
-    port_forward "$VOLTHA_NS"  voltha-api "$VOLTHA_API_PORT:55555"
+    kill_port_forward voltha-api voltha-voltha-api
+    VOLTHA_PREFIX=
+    if kubectl get -n "$VOLTHA_NS" "svc/voltha-voltha-api" >/dev/null 2>&1; then
+        VOLTHA_PREFIX="voltha-"
+    fi
+    
+    port_forward "$VOLTHA_NS"  "${VOLTHA_PREFIX}voltha-api" "$VOLTHA_API_PORT:55555"
     espin - "$VERIFIED"
     if is_in "$WITH_ETCD" "yes,external"; then
         bspin - "Forward VOLTHA ETCD port $FORWARD"
@@ -2131,13 +2165,17 @@
         espin - "$VERIFIED"
     fi
     if [ "$WITH_PPROF" == "yes" ]; then
+        VOLTHA_OPENOLT_PREFIX=
+        if kubectl get -n "$ADAPTER_NS" "svc/open-olt-adapter-open-olt-profiler" >/dev/null 2>&1; then
+            VOLTHA_OPENOLT_PREFIX="open-olt-"
+        fi
       bspin - "Forward PProf ports port $FORWARD"
-      kill_port_forward voltha-rw-core-profiler
-      kill_port_forward adapter-open-olt-profiler
-      kill_port_forward voltha-of-agent-profiler
-      port_forward "$VOLTHA_NS" voltha-rw-core-profiler "$VOLTHA_PPROF_PORT:6060"
-      port_forward "$VOLTHA_NS" adapter-open-olt-profiler "$OPENOLT_PPROF_PORT:6060"
-      port_forward "$VOLTHA_NS" voltha-of-agent-profiler "$OFAGENT_PPROF_PORT:6060"
+      kill_port_forward voltha-rw-core-profiler voltha-voltha-rw-core-profiler
+      kill_port_forward adapter-open-olt-profiler open-olt-adapter-open-olt-profiler
+      kill_port_forward voltha-of-agent-profiler voltha-voltha-of-agent-profiler
+      port_forward "$VOLTHA_NS" "${VOLTHA_PREFIX}voltha-rw-core-profiler" "$VOLTHA_PPROF_PORT:6060"
+      port_forward "$ADAPTER_NS" "${VOLTHA_OPENOLT_PREFIX}adapter-open-olt-profiler" "$OPENOLT_PPROF_PORT:6060"
+      port_forward "$VOLTHA_NS" "${VOLTHA_PREFIX}voltha-of-agent-profiler" "$OFAGENT_PPROF_PORT:6060"
       espin - "$VERIFIED"
     fi
     if [ "$WITH_TIMINGS" == "yes" ]; then