[COMMON] Fix more and more array bashisms step 2
[oom.git] / kubernetes / helm / plugins / deploy / deploy.sh
index 51438ad..347c768 100755 (executable)
@@ -67,22 +67,24 @@ generate_overrides() {
     fi
   done
 }
+
+
 resolve_deploy_flags() {
-  flags=($1)
-  n=${#flags[*]}
-  i=0 ; while [ "$i" -lt "$n" ]; do
-    PARAM=${flags[i]}
-    if [ "$PARAM" = "-f" ] || \
-       [ "$PARAM" = "--values" ] || \
-       [ "$PARAM" = "--set" ] || \
-       [ "$PARAM" = "--set-string" ] || \
-       [ "$PARAM" = "--version" ]; then
-       # skip param and its value
-       i=$((i + 1))
+  skip="false"
+  for param in $1; do
+    if [ "$skip" = "false" ]; then
+      if [ "$param" = "-f" ] || \
+         [ "$param" = "--values" ] || \
+         [ "$param" = "--set" ] || \
+         [ "$param" = "--set-string" ] || \
+         [ "$param" = "--version" ]; then
+        skip="true"
+      else
+        DEPLOY_FLAGS="$DEPLOY_FLAGS $param"
+      fi
     else
-      DEPLOY_FLAGS="$DEPLOY_FLAGS $PARAM"
+      skip="false"
     fi
-    i=$((i+1))
   done
   echo "$DEPLOY_FLAGS"
 }
@@ -90,11 +92,12 @@ resolve_deploy_flags() {
 
 check_for_dep() {
     try=0
-    retries=30
-    until (kubectl get deployment -n $RELEASE | grep -P "\b$1\b") &>/dev/null; do
-        (( ++try > retries )) && exit 1
+    retries=60
+    until (kubectl get deployment -n $HELM_NAMESPACE | grep -P "\b$1\b") >/dev/null 2>&1; do
+        try=$(($try + 1))
+        [ $try -gt $retries ] && exit 1
         echo "$1 not found. Retry $try/$retries"
-        sleep 5
+        sleep 10
     done
     echo "$1 found. Waiting for pod intialisation"
     sleep 15
@@ -125,7 +128,7 @@ deploy_subchart() {
         # Add annotation last-applied-configuration if set-last-applied flag is set
         if [ "$SET_LAST_APPLIED" = "true" ]; then
           helm get manifest "${RELEASE}-${subchart}" \
-          | kubectl apply set-last-applied --create-annotation -n onap -f - \
+          | kubectl apply set-last-applied --create-annotation -n $HELM_NAMESPACE -f - \
           > $LOG_FILE.log 2>&1
         fi
       fi
@@ -257,7 +260,7 @@ deploy() {
     # Add annotation last-applied-configuration if set-last-applied flag is set
     if [ "$SET_LAST_APPLIED" = "true" ]; then
       helm get manifest ${RELEASE} \
-      | kubectl apply set-last-applied --create-annotation -n onap -f - \
+      | kubectl apply set-last-applied --create-annotation -n $HELM_NAMESPACE -f - \
       > $LOG_FILE.log 2>&1
     fi
   fi
@@ -282,14 +285,19 @@ deploy() {
       if [ $SUBCHART_ENABLED -eq 1 ]; then
         deploy_subchart
       else
-        array=($(echo "$ALL_HELM_RELEASES" | grep "${RELEASE}-${subchart}"))
-        n=${#array[*]}
-        for i in $(seq $(($n-1)) -1 0); do
-          helm del "${array[i]}"
+        reverse_list=
+        for item in $(echo "$ALL_HELM_RELEASES" | grep "${RELEASE}-${subchart}")
+        do
+          reverse_list="$item $reverse_list"
+        done
+        for item in $reverse_list
+        do
+          helm del $item
         done
       fi
     done
 
+
     for subchart in * ; do
       SUBCHART_OVERRIDES=$CACHE_SUBCHART_DIR/$subchart/subchart-overrides.yaml
 
@@ -304,10 +312,14 @@ deploy() {
       if [ $SUBCHART_ENABLED -eq 1 ]; then
         deploy_subchart
       else
-        array=($(echo "$ALL_HELM_RELEASES" | grep "${RELEASE}-${subchart}"))
-        n=${#array[*]}
-        for i in $(seq $(($n-1)) -1 0); do
-          helm del "${array[i]}"
+        reverse_list=
+        for item in $(echo "$ALL_HELM_RELEASES" | grep "${RELEASE}-${subchart}")
+        do
+          reverse_list="$item $reverse_list"
+        done
+        for item in $reverse_list
+        do
+          helm del $item
         done
       fi
     done