DBaaS standalone and HA version update

This version of the helm charts combine the DBAAS SA and HA charts.
Client applications should include the appconfig configmap as environment variables.
Server host kernel optimization has been included in the ric-dep bin deployment scripts.

Note:
 - SDL library will automatically recognize whether it is using HA or SA version of DBAAS.
 - The client should make sure that it uses the upgraded SDL library that supports dbaasha.

Change-Id: I40f05ec8bdf7ade68029ecb64fc6a8413c34a247
Signed-off-by: knowpd <knowpd@research.att.com>
diff --git a/bin/install b/bin/install
index e705e5e..bc9a4ba 100755
--- a/bin/install
+++ b/bin/install
@@ -15,6 +15,53 @@
 #   See the License for the specific language governing permissions and        #
 #   limitations under the License.                                             #
 ################################################################################
+
+function wait_for_pods() {
+  echo -n "waiting for $1 pods to run"
+
+  STILL_WAITING=true
+  while $STILL_WAITING; do
+      STILL_WAITING=false
+      PODS=$(kubectl get pods -n $2 2>/dev/null | grep $1 | awk '{print $1}')
+      if [ -z $PODS ]; then
+        STILL_WAITING=true
+        sleep 1
+        echo -n "."
+      fi
+      for POD in ${PODS}; do
+        if [[ $(kubectl get pod ${POD} -n $2 -o go-template --template "{{.status.phase}}") != "Running" ]]; then
+	    STILL_WAITING=true
+	    sleep 1
+            echo -n "."
+	    break
+	fi
+      done 
+  done
+
+  echo
+}
+
+function wait_for_cats() {
+  echo -n "waiting for $1 daemonset to complete"
+
+  STILL_WAITING=true
+  while $STILL_WAITING; do
+      STILL_WAITING=false
+      PODS=$(kubectl get pods -n $2 | grep $1 | awk '{print $1}')
+      for POD in ${PODS}; do
+        if [[ $(kubectl logs ${POD} -n $2 --tail 1) != "done" ]]; then
+	    STILL_WAITING=true
+	    sleep 1
+            echo -n "."
+	    break
+	fi
+      done 
+  done
+
+  echo
+}
+
+
 while [ -n "$1" ]; do # while loop starts
 
     case "$1" in
@@ -53,25 +100,17 @@
     exit 1
 fi
 
-
-
-
-
-
-
-
-
-
-
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
-COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
-NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^  namespace:/{getline; while ($0 ~ /^    .*|^ *$/) {print $0; if (getline == 0) {break}}}')
+COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *|^ *#.*$/) {print $0; if (getline == 0) {break}}}')
+NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^  namespace:/{getline; while ($0 ~ /^ +.*|^ *|^ *#.*$/) {print $0; if (getline == 0) {break}}}')
 PLTNAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *platform:/{print $2}')
 INFRANAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *infra:/{print $2}')
 XAPPNAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *xapp:/{print $2}')
 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
+LOCAL_REPOSITORY=$(echo "$COMMON_BLOCK" | awk '/^ *localregistry:/{print $2}')
+
 # replace the dbaasha with dbaas1 if deploying non HA DBaaS
-COMPONENTS=${LIST_OF_COMPONENTS:-"infrastructure xapp-onboarder appmgr rtmgr dbaas1 e2mgr e2term a1mediator submgr vespamgr jaegeradapter o1mediator alarmadapter"}
+COMPONENTS=${LIST_OF_COMPONENTS:-"infrastructure dbaas xapp-onboarder appmgr rtmgr e2mgr e2term a1mediator submgr vespamgr jaegeradapter o1mediator alarmadapter"}
 echo "Deploying RIC infra components [$COMPONENTS]"
 
 
@@ -84,12 +123,75 @@
 if ! kubectl get ns ${XAPPNAMESPACE:-ricxapp}> /dev/null 2>&1; then
     kubectl create ns ${XAPPNAMESPACE:-ricxapp}
 fi
-
+FOUND_RECIPE=$(kubectl get configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe 2>/dev/null )
+if [ ! -z "$FOUND_RECIPE" ]; then
+    kubectl delete configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe
+fi
 kubectl create configmap -n ${PLTNAMESPACE:-ricplt} ricplt-recipe --from-file=recipe=$OVERRIDEYAML
 
+if [ ! -z "$LOCAL_REPOSITORY" ]; then
+    LOCAL_REPOSITORY="$LOCAL_REPOSITORY/"
+fi
+
+
+# Add kernel optimization for radis services
+    cat >kernel_optimizer.yaml <<EOF
+apiVersion: apps/v1
+kind: DaemonSet
+metadata:
+  namespace: ${INFRANAMESPACE:-ricinfra}
+  name: redis-kernel-optimizer
+spec:
+  selector:
+    matchLabels:
+      app: redis-kernel-optimizer
+  template:
+    metadata:
+      labels:
+        app: redis-kernel-optimizer
+    spec:
+      volumes:
+      - name: sys
+        hostPath:
+          path: /sys
+      containers:
+      - name: disable-thp
+        image: ${LOCAL_REPOSITORY}busybox
+        securityContext:
+          runAsNonRoot: false
+          privileged: true
+          runAsUser: 0
+        command: ["sh", "-c"]
+        args:
+        - |-
+          set -e
+          set -o pipefail
+          trap 'exit' TERM
+          echo never > /rootfs/sys/kernel/mm/transparent_hugepage/enabled
+          echo never > /rootfs/sys/kernel/mm/transparent_hugepage/defrag
+          sysctl -w net.core.somaxconn=511
+          grep -q -F [never] /sys/kernel/mm/transparent_hugepage/enabled
+          grep -q -F [never] /sys/kernel/mm/transparent_hugepage/defrag
+          sysctl -n net.core.somaxconn | grep 511 -q
+          echo "done"
+          while true; do sleep 1; done
+        volumeMounts:
+        - name: sys
+          mountPath: /rootfs/sys
+EOF
+kubectl apply -f kernel_optimizer.yaml
+wait_for_pods redis-kernel-optimizer ${INFRANAMESPACE:-ricinfra}
+wait_for_cats redis-kernel-optimizer ${INFRANAMESPACE:-ricinfra}
+kubectl delete -f kernel_optimizer.yaml
+rm kernel_optimizer.yaml
+
 
 for component in $COMPONENTS; do
     helm dep up $DIR/../helm/$component
     helm install -f $OVERRIDEYAML --namespace "${PLTNAMESPACE:-ricplt}" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
     sleep 3
 done
+
+
+
+
diff --git a/bin/uninstall b/bin/uninstall
index bb3091b..51db408 100755
--- a/bin/uninstall
+++ b/bin/uninstall
@@ -16,7 +16,7 @@
 #   limitations under the License.                                             #
 ################################################################################
 
-COMPONENTS="xapp-onboarder appmgr rtmgr dbaas1 dbaasha e2mgr e2term a1mediator submgr vespamgr jaegeradapter infrastructure o1mediator alarmadapter"
+COMPONENTS="xapp-onboarder appmgr rtmgr e2mgr e2term a1mediator submgr vespamgr jaegeradapter dbaas infrastructure o1mediator alarmadapter"
 RECIPE_NAMESPACE=$(kubectl get cm --all-namespaces | grep ricplt-recipe | awk '{print $1}')
 kubectl get configmap  -n $RECIPE_NAMESPACE ricplt-recipe  -o jsonpath='{.data.recipe}' > /tmp/recipe.yaml