[DEPLOY] Improve deploy.sh 58/128258/8
authorefiacor <fiachra.corcoran@est.tech>
Fri, 1 Apr 2022 16:41:48 +0000 (17:41 +0100)
committerefiacor <fiachra.corcoran@est.tech>
Tue, 5 Apr 2022 12:35:39 +0000 (13:35 +0100)
Add logic to deploy required components up front
Fix storage deleteClaim on kafka

Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Change-Id: I6dd820a40691ba3c7e3a93510d0e5eaa9f356f9b
Issue-ID: OOM-2954

kubernetes/helm/plugins/deploy/deploy.sh
kubernetes/strimzi/templates/strimzi-kafka.yaml

index f32281d..51438ad 100755 (executable)
@@ -100,6 +100,40 @@ check_for_dep() {
     sleep 15
 }
 
+deploy_strimzi() {
+  #Deploy the srtimzi-kafka chart in advance. Dependent charts require the entity-operator
+  #for management of the strimzi crds
+  deploy_subchart
+  echo "waiting for ${RELEASE}-strimzi-entity-operator to be deployed"
+  check_for_dep ${RELEASE}-strimzi-entity-operator
+}
+
+deploy_subchart() {
+  if [ -z "$SUBCHART_RELEASE" ] || [ "$SUBCHART_RELEASE" = "$subchart" ]; then
+        LOG_FILE=$LOG_DIR/"${RELEASE}-${subchart}".log
+        :> $LOG_FILE
+
+        helm upgrade -i "${RELEASE}-${subchart}" $CACHE_SUBCHART_DIR/$subchart \
+         $DEPLOY_FLAGS -f $GLOBAL_OVERRIDES -f $SUBCHART_OVERRIDES \
+         > $LOG_FILE 2>&1
+
+        if [ "$VERBOSE" = "true" ]; then
+          cat $LOG_FILE
+        else
+          echo "release \"${RELEASE}-${subchart}\" deployed"
+        fi
+        # 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 - \
+          > $LOG_FILE.log 2>&1
+        fi
+      fi
+      if [ "$DELAY" = "true" ]; then
+        echo sleep 3m
+        sleep 180
+      fi
+}
 
 deploy() {
   # validate params
@@ -234,53 +268,49 @@ deploy() {
   #So cache the results to prevent repeated execution.
   ALL_HELM_RELEASES=$(helm ls -q)
 
-  #Deploy the srtimzi-kafka chart in advance. Dependent charts require the entity-operator
-  #for management of the strimzi crds
-  helm upgrade -i "${RELEASE}-strimzi" $CACHE_SUBCHART_DIR/strimzi
-  echo "waiting for ${RELEASE}-strimzi-entity-operator to be deployed"
-  check_for_dep ${RELEASE}-strimzi-entity-operator
-
-  for subchart in * ; do
-    SUBCHART_OVERRIDES=$CACHE_SUBCHART_DIR/$subchart/subchart-overrides.yaml
-
-    SUBCHART_ENABLED=0
-    if [ -f $SUBCHART_OVERRIDES ]; then
-      SUBCHART_ENABLED=$(cat $SUBCHART_OVERRIDES | grep -c "^enabled: true")
-    fi
+    for subchart in strimzi cassandra mariadb-galera postgres ; do
+      SUBCHART_OVERRIDES=$CACHE_SUBCHART_DIR/$subchart/subchart-overrides.yaml
 
-    if [ $SUBCHART_ENABLED -eq 1 ]; then
-      if [ -z "$SUBCHART_RELEASE" ] || [ "$SUBCHART_RELEASE" = "$subchart" ]; then
-        LOG_FILE=$LOG_DIR/"${RELEASE}-${subchart}".log
-        :> $LOG_FILE
+      SUBCHART_ENABLED=0
+      if [ -f $SUBCHART_OVERRIDES ]; then
+        SUBCHART_ENABLED=$(cat $SUBCHART_OVERRIDES | grep -c "^enabled: true")
+      fi
+      if [ "${subchart}" = "strimzi" ] && [ $SUBCHART_ENABLED -eq 1 ]; then
+        deploy_strimzi
+      fi
+      # Deploy them at first
+      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]}"
+        done
+      fi
+    done
 
-        helm upgrade -i "${RELEASE}-${subchart}" $CACHE_SUBCHART_DIR/$subchart \
-         $DEPLOY_FLAGS -f $GLOBAL_OVERRIDES -f $SUBCHART_OVERRIDES \
-         > $LOG_FILE 2>&1
+    for subchart in * ; do
+      SUBCHART_OVERRIDES=$CACHE_SUBCHART_DIR/$subchart/subchart-overrides.yaml
 
-        if [ "$VERBOSE" = "true" ]; then
-          cat $LOG_FILE
-        else
-          echo "release \"${RELEASE}-${subchart}\" deployed"
-        fi
-        # 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 - \
-          > $LOG_FILE.log 2>&1
-        fi
+      SUBCHART_ENABLED=0
+      if [ -f $SUBCHART_OVERRIDES ]; then
+        SUBCHART_ENABLED=$(cat $SUBCHART_OVERRIDES | grep -c "^enabled: true")
       fi
-      if [ "$DELAY" = "true" ]; then
-        echo sleep 3m
-        sleep 180
+      if [ "${subchart}" = "strimzi" ] || [ "${subchart}" = "cassandra" ] || [ "${subchart}" = "mariadb-galera" ] || [ "${subchart}" = "postgres" ]; then
+        SUBCHART_ENABLED=0
       fi
-    else
-      array=($(echo "$ALL_HELM_RELEASES" | grep "${RELEASE}-${subchart}"))
-      n=${#array[*]}
-      for i in $(seq $(($n-1)) -1 0); do
-        helm del "${array[i]}"
-      done
-    fi
-  done
+      # Deploy the others
+      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]}"
+        done
+      fi
+    done
 
   # report on success/failures of installs/upgrades
   helm ls --all-namespaces | grep -i FAILED | grep $RELEASE
index 4ca53a2..cfd2ef1 100644 (file)
@@ -68,7 +68,7 @@ spec:
       - id: 0
         type: persistent-claim
         size: {{ .Values.persistenceKafka.size }}
-        deleteClaim: false
+        deleteClaim: true
         class: {{ include "common.storageClass" (dict "dot" . "suffix" "kafka" "persistenceInfos" .Values.persistenceKafka) }}
   zookeeper:
     template:
@@ -82,7 +82,7 @@ spec:
     storage:
       type: persistent-claim
       size: {{ .Values.persistenceZk.size }}
-      deleteClaim: false
+      deleteClaim: true
       class: {{ include "common.storageClass" (dict "dot" . "suffix" "zk" "persistenceInfos" .Values.persistenceZk) }}
   entityOperator:
     topicOperator: {}