X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=kubernetes%2Fhelm%2Fplugins%2Fdeploy%2Fdeploy.sh;h=a8d134ba92c36eb34c459c7ffb99dac9cfc870dc;hb=20d6797d16645fdec94b330283860185d24d916e;hp=0d434ad877d0e7f31720455c9a217c53d132a9b7;hpb=f4527b94897c02c763f11e4013dbbe9b3a821061;p=oom.git diff --git a/kubernetes/helm/plugins/deploy/deploy.sh b/kubernetes/helm/plugins/deploy/deploy.sh index 0d434ad877..a8d134ba92 100755 --- a/kubernetes/helm/plugins/deploy/deploy.sh +++ b/kubernetes/helm/plugins/deploy/deploy.sh @@ -22,13 +22,13 @@ You can specify the '--values'/'-f' flag multiple times. The priority will be gi last (right-most) file specified. For example, if both myvalues.yaml and override.yaml contained a key called 'Test', the value set in override.yaml would take precedence: - $ helm deploy demo ./onap --namespace onap -f openstack.yaml -f overrides.yaml + $ helm deploy demo ./onap --namespace onap -f openstack.yaml -f overrides.yaml You can specify the '--set' flag multiple times. The priority will be given to the last (right-most) set specified. For example, if both 'bar' and 'newbar' values are set for a key called 'foo', the 'newbar' value would take precedence: - $ helm deploy demo local/onap --namespace onap -f overrides.yaml --set log.enabled=false --set vid.enabled=false + $ helm deploy demo local/onap --namespace onap -f overrides.yaml --set log.enabled=false --set vid.enabled=false Usage: helm deploy [RELEASE] [CHART] [flags] @@ -49,14 +49,14 @@ generate_overrides() { for index in "${!SUBCHART_NAMES[@]}"; do START=${SUBCHART_NAMES[index]} END=${SUBCHART_NAMES[index+1]} - if [[ $START = "global:" ]]; then + if [ "$START" = "global:" ]; then echo "global:" > $GLOBAL_OVERRIDES cat $COMPUTED_OVERRIDES | sed '/common:/,/consul:/d' \ | sed -n '/^'"$START"'/,/'log:'/p' | sed '1d;$d' >> $GLOBAL_OVERRIDES else SUBCHART_DIR="$CACHE_SUBCHART_DIR/$(echo "$START" |cut -d':' -f1)" - if [[ -d "$SUBCHART_DIR" ]]; then - if [[ -z "$END" ]]; then + if [ -d "$SUBCHART_DIR" ]; then + if [ -z "$END" ]; then cat $COMPUTED_OVERRIDES | sed -n '/^'"$START"'/,/'"$END"'/p' \ | sed '1d;$d' | cut -c3- > $SUBCHART_DIR/subchart-overrides.yaml else @@ -67,16 +67,18 @@ 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 + if [ "$PARAM" = "-f" ] || \ + [ "$PARAM" = "--values" ] || \ + [ "$PARAM" = "--set" ] || \ + [ "$PARAM" = "--set-string" ] || \ + [ "$PARAM" = "--version" ]; then # skip param and its value i=$((i + 1)) else @@ -87,23 +89,69 @@ 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 2>&1; do + try=$(($try + 1)) + [ $try -gt $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 + if [ -z "$1" ] || [ -z "$2" ]; then usage - exit 0 + exit 1 fi RELEASE=$1 CHART_URL=$2 - FLAGS=${@:3} - CHART_REPO="$(echo "$CHART_URL" |cut -d'/' -f1)" - CHART_NAME="$(echo "$CHART_URL" |cut -d'/' -f2)" - if [[ $HELM_VER = "v3."* ]]; then - CACHE_DIR=~/.local/share/helm/plugins/deploy/cache - else - CACHE_DIR=~/.helm/plugins/deploy/cache - fi + FLAGS=$(echo ${@} | sed 's/^ *[^ ]* *[^ ]* *//') + CHART_REPO="$(echo "$CHART_URL" | cut -d'/' -f1)" + CHART_NAME="$(echo "$CHART_URL" | cut -d'/' -f2)" + + 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 @@ -111,23 +159,23 @@ deploy() { # determine if verbose output is enabled VERBOSE="false" - if [[ $FLAGS = *"--verbose"* ]]; then + if expr "$FLAGS" : ".*--verbose.*" ; then FLAGS="$(echo $FLAGS| sed -n 's/--verbose//p')" VERBOSE="true" fi # determine if delay for deployment is enabled DELAY="false" - if [[ $FLAGS = *"--delay"* ]]; then + if expr "$FLAGS" : ".*--delay.*" ; then FLAGS="$(echo $FLAGS| sed -n 's/--delay//p')" DELAY="true" fi # determine if set-last-applied flag is enabled SET_LAST_APPLIED="false" - if [[ $FLAGS = *"--set-last-applied"* ]]; then + if expr "$FLAGS" : ".*--set-last-applied.*" ; then FLAGS="$(echo $FLAGS| sed -n 's/--set-last-applied//p')" SET_LAST_APPLIED="true" fi - if [[ $FLAGS = *"--dry-run"* ]]; then + if expr "$FLAGS" : ".*--dry-run.*" ; then VERBOSE="true" FLAGS="$FLAGS --debug" fi @@ -150,7 +198,7 @@ deploy() { SUBCHART_RELEASE="$(echo "$RELEASE" |cut -d'-' -f2)" # update specified subchart without parent RELEASE="$(echo "$RELEASE" |cut -d'-' -f1)" - if [[ $SUBCHART_RELEASE = $RELEASE ]]; then + if [ "$SUBCHART_RELEASE" = "$RELEASE" ]; then SUBCHART_RELEASE= fi @@ -158,7 +206,7 @@ deploy() { rm -rf $CACHE_DIR # fetch umbrella chart (parent chart containing subcharts) - if [[ -d "$CHART_URL" ]]; then + if [ -d "$CHART_URL" ]; then mkdir -p $CHART_DIR cp -R $CHART_URL/* $CHART_DIR/ @@ -181,9 +229,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 @@ -195,22 +245,22 @@ deploy() { generate_overrides $COMPUTED_OVERRIDES $GLOBAL_OVERRIDES # upgrade/install parent chart first - if [[ -z "$SUBCHART_RELEASE" ]]; then + if [ -z "$SUBCHART_RELEASE" ]; then LOG_FILE=$LOG_DIR/${RELEASE}.log :> $LOG_FILE helm upgrade -i $RELEASE $CHART_DIR $DEPLOY_FLAGS -f $COMPUTED_OVERRIDES \ > $LOG_FILE.log 2>&1 - if [[ $VERBOSE = "true" ]]; then + if [ "$VERBOSE" = "true" ]; then cat $LOG_FILE else echo "release \"$RELEASE\" deployed" fi # Add annotation last-applied-configuration if set-last-applied flag is set - if [[ $SET_LAST_APPLIED = "true" ]]; then + 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 +270,62 @@ 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 + 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 - 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 + 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 - if [[ $DELAY = "true" ]]; then - echo sleep 3m - sleep 3m - fi - else - array=($(echo "$ALL_HELM_RELEASES" | grep "${RELEASE}-${subchart}")) - n=${#array[*]} - for i in $(seq $(($n-1)) -1 0); do - if [[ $HELM_VER = "v3."* ]]; then - helm del "${array[i]}" - else - helm del "${array[i]}" --purge - fi - done - fi - done + if [ "${subchart}" = "strimzi" ] || [ "${subchart}" = "cassandra" ] || [ "${subchart}" = "mariadb-galera" ] || [ "${subchart}" = "postgres" ]; then + SUBCHART_ENABLED=0 + fi + # Deploy the others + if [ $SUBCHART_ENABLED -eq 1 ]; then + deploy_subchart + else + 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 # report on success/failures of installs/upgrades - if [[ $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 @@ -287,7 +341,7 @@ case "${1:-"help"}" in usage ;; *) - deploy $1 $2 ${@:3} + deploy $1 $2 $(echo ${@} | sed 's/^ *[^ ]* *[^ ]* *//') ;; esac