X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=kubernetes%2Fhelm%2Fplugins%2Fdeploy%2Fdeploy.sh;h=36853baa1f17d03ec1f5472c4e2738c9a850f0f0;hb=3684d47f120b5fdbdf163cede536334d37852181;hp=5820e7752135d5d1172c23e5d9cfbf5928744518;hpb=c191f3850b7d96779df16fec59c59f55a994e226;p=oom.git diff --git a/kubernetes/helm/plugins/deploy/deploy.sh b/kubernetes/helm/plugins/deploy/deploy.sh index 5820e77521..36853baa1f 100755 --- a/kubernetes/helm/plugins/deploy/deploy.sh +++ b/kubernetes/helm/plugins/deploy/deploy.sh @@ -67,6 +67,8 @@ generate_overrides() { fi done } + + resolve_deploy_flags() { flags=($1) n=${#flags[*]} @@ -87,6 +89,54 @@ resolve_deploy_flags() { echo "$DEPLOY_FLAGS" } + +check_for_dep() { + try=0 + retries=60 + until (kubectl get deployment -n $HELM_NAMESPACE | grep -P "\b$1\b") &>/dev/null; do + (( ++try > retries )) && exit 1 + echo "$1 not found. Retry $try/$retries" + sleep 10 + done + echo "$1 found. Waiting for pod intialisation" + 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 $HELM_NAMESPACE -f - \ + > $LOG_FILE.log 2>&1 + fi + fi + if [ "$DELAY" = "true" ]; then + echo sleep 3m + sleep 180 + fi +} + deploy() { # validate params if [ -z "$1" ] || [ -z "$2" ]; then @@ -99,11 +149,8 @@ deploy() { FLAGS=$(echo ${@} | sed 's/^ *[^ ]* *[^ ]* *//') CHART_REPO="$(echo "$CHART_URL" | cut -d'/' -f1)" CHART_NAME="$(echo "$CHART_URL" | cut -d'/' -f2)" - if expr "$HELM_VER" : "v3\..*" ; then - CACHE_DIR=~/.local/share/helm/plugins/deploy/cache - else - CACHE_DIR=~/.helm/plugins/deploy/cache - fi + + CACHE_DIR=~/.local/share/helm/plugins/deploy/cache echo "Use cache dir: $CACHE_DIR" CHART_DIR=$CACHE_DIR/$CHART_NAME CACHE_SUBCHART_DIR=$CHART_DIR-subcharts @@ -181,9 +228,11 @@ deploy() { # temp hack - parent chart needs common subchart mv $CACHE_SUBCHART_DIR/common $CHART_DIR/charts/ - # disable dependencies - rm $CHART_DIR/requirements.lock - mv $CHART_DIR/requirements.yaml $CHART_DIR/requirements.deploy + # disable dependencies + rm $CHART_DIR/Chart.lock + sed -n '1,/dependencies:/p;/description:/,$p' $CHART_DIR/Chart.yaml | grep -v dependencies > $CHART_DIR/deploy_Chart.yaml + mv $CHART_DIR/Chart.yaml $CHART_DIR/Chart.deploy + mv $CHART_DIR/deploy_Chart.yaml $CHART_DIR/Chart.yaml # compute overrides for parent and all subcharts COMPUTED_OVERRIDES=$CACHE_DIR/$CHART_NAME/computed-overrides.yaml @@ -210,7 +259,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 @@ -220,58 +269,53 @@ deploy() { #“helm ls” is an expensive command in that it can take a long time to execute. #So cache the results to prevent repeated execution. ALL_HELM_RELEASES=$(helm ls -q) - 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 - if expr "$HELM_VER" : "v3\..*" ; then + # 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]}" - else - helm del "${array[i]}" --purge - fi - done - fi - done + done + fi + done # report on success/failures of installs/upgrades - if expr "$HELM_VER" : "v3\..*" ; then - helm ls --all-namespaces | grep -i FAILED | grep $RELEASE - else - helm ls | grep FAILED | grep $RELEASE - fi + helm ls --all-namespaces | grep -i FAILED | grep $RELEASE } HELM_VER=$(helm version --template "{{.Version}}") echo $HELM_VER