diff options
author | Mike Elliott <mike.elliott@amdocs.com> | 2018-10-15 16:21:36 -0400 |
---|---|---|
committer | Mike Elliott <mike.elliott@amdocs.com> | 2018-10-15 16:32:18 -0400 |
commit | 8e7491b86ae54873b3178b0f03a9cdbecddd58cf (patch) | |
tree | 3cce381ad055d660dc399b4a2e9ba6951c83fa31 | |
parent | b81745ce6dffd4880a2983d8521b8ad4a08cb194 (diff) |
Update (un)deploy helm plugins
- Added support for deploying and undeploying individual releases.
- Added support for a --verbose flag to output details during a deploy. By
default, verbose output will be supressed.
- Fixed issues preventng some flags from propagating to helm commands.
- Fixed issue where by --set <chartname>.enabled=false was not removing disabled Helm Charts.
Change-Id: I8e407808a9946f316d035efd503316f96723223d
Issue-ID: OOM-1344
Signed-off-by: Mike Elliott <mike.elliott@amdocs.com>
-rwxr-xr-x | kubernetes/helm/plugins/deploy/deploy.sh | 115 | ||||
-rwxr-xr-x | kubernetes/helm/plugins/undeploy/undeploy.sh | 2 |
2 files changed, 100 insertions, 17 deletions
diff --git a/kubernetes/helm/plugins/deploy/deploy.sh b/kubernetes/helm/plugins/deploy/deploy.sh index 07455d7db4..41873b97e2 100755 --- a/kubernetes/helm/plugins/deploy/deploy.sh +++ b/kubernetes/helm/plugins/deploy/deploy.sh @@ -38,6 +38,7 @@ Flags: --set stringArray set values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) --set-string stringArray set STRING values on the command line (can specify multiple or separate values with commas: key1=val1,key2=val2) -f, --values valueFiles specify values in a YAML file or a URL(can specify multiple) (default []) + --verbose enables full helm install/upgrade output during deploy EOF } @@ -77,7 +78,34 @@ generate_overrides() { done } +resolve_deploy_flags() { + DEPLOY_FLAGS=$1 + for flag in -f --values --set --set-string + do + while true ; do + # extract value of flag + length=${#flag} + length=$((length+1)) + FLAG_VALUE="$(echo $DEPLOY_FLAGS | sed -n 's/.*\('$flag'\).\s*/\1/p' | cut -c$length- | cut -d' ' -f1)" + + # purge flag and value from + DEPLOY_FLAGS="${DEPLOY_FLAGS//$flag $FLAG_VALUE/}" + DEPLOY_FLAGS=$(echo $DEPLOY_FLAGS | awk '{$1=$1};1') + if [ -z "$FLAG_VALUE" ] ; then + break + fi + done + done + echo "$DEPLOY_FLAGS" +} + deploy() { + # validate params + if [[ -z "$1" || -z "$2" ]]; then + usage + exit 0 + fi + RELEASE=$1 CHART_URL=$2 FLAGS=${@:3} @@ -86,23 +114,50 @@ deploy() { CACHE_DIR=~/.helm/plugins/deploy/cache CHART_DIR=$CACHE_DIR/$CHART_NAME CACHE_SUBCHART_DIR=$CHART_DIR-subcharts + LOG_DIR=$CHART_DIR/logs + + # determine if verbose output is enabled + VERBOSE="false" + if [[ $FLAGS = *"--verbose"* ]]; then + FLAGS="$(echo $FLAGS| sed -n 's/--verbose//p')" + VERBOSE="true" + fi + # should pass all flags instead - NAMESPACE="$(echo $FLAGS | sed -n 's/.*\(namespace\).\s*/\1/p' | cut -c10-)" - + NAMESPACE="$(echo $FLAGS | sed -n 's/.*\(namespace\).\s*/\1/p' | cut -c10- | cut -d' ' -f1)" + + # Remove all override values passed in as arguments. These will be used during dry run + # to resolve computed override values. Remaining flags will be passed on during + # actual upgrade/install of parent and subcharts. + DEPLOY_FLAGS=$(resolve_deploy_flags "$FLAGS") + + # determine if upgrading individual subchart or entire parent + subcharts + SUBCHART_RELEASE="$(cut -d'-' -f2 <<<"$RELEASE")" + if [[ ! -d "$CACHE_SUBCHART_DIR/$SUBCHART_RELEASE" ]]; then + SUBCHART_RELEASE= + else + # update specified subchart without parent + RELEASE="$(cut -d'-' -f1 <<<"$RELEASE")" + fi + # clear previously cached charts rm -rf $CACHE_DIR + # create log driectory + mkdir -p $LOG_DIR + # fetch umbrella chart (parent chart containing subcharts) if [[ -d "$CHART_URL" ]]; then mkdir -p $CHART_DIR cp -R $CHART_URL/* $CHART_DIR/ - cd $CHART_DIR/charts/ - for subchart in * ; do - tar xzf ${subchart} + charts=$CHART_DIR/charts/* + for subchart in $charts ; do + tar xzf ${subchart} -C $CHART_DIR/charts/ done - rm -rf *.tgz + rm -rf $CHART_DIR/charts/*.tgz else + echo "fetching $CHART_URL" helm fetch $CHART_URL --untar --untardir $CACHE_DIR fi @@ -126,29 +181,57 @@ deploy() { generate_overrides $COMPUTED_OVERRIDES $GLOBAL_OVERRIDES # upgrade/install parent chart first - helm upgrade -i $RELEASE $CHART_DIR --namespace $NAMESPACE -f $COMPUTED_OVERRIDES + 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 + + echo "release $RELEASE deployed" + + if [[ $VERBOSE == "true" ]]; then + cat $LOG_FILE + fi + fi # parse computed overrides - will use to determine if a subchart is "enabled" eval $(parse_yaml $COMPUTED_OVERRIDES "computed_") # upgrade/install each "enabled" subchart - cd $CACHE_SUBCHART_DIR + cd $CACHE_SUBCHART_DIR/ for subchart in * ; do VAR="computed_${subchart}_enabled" COMMAND="$"$VAR eval "SUBCHART_ENABLED=$COMMAND" if [[ $SUBCHART_ENABLED == "true" ]]; then - SUBCHART_OVERRIDES=$CACHE_SUBCHART_DIR/$subchart/subchart-overrides.yaml - helm upgrade -i "${RELEASE}-${subchart}" $CACHE_SUBCHART_DIR/$subchart \ - --namespace $NAMESPACE -f $GLOBAL_OVERRIDES -f $SUBCHART_OVERRIDES + if [[ -z "$SUBCHART_RELEASE" || $SUBCHART_RELEASE == "$subchart" ]]; then + LOG_FILE=$LOG_DIR/"${RELEASE}-${subchart}".log + :> $LOG_FILE + + SUBCHART_OVERRIDES=$CACHE_SUBCHART_DIR/$subchart/subchart-overrides.yaml + helm upgrade -i "${RELEASE}-${subchart}" $CACHE_SUBCHART_DIR/$subchart \ + $DEPLOY_FLAGS -f $GLOBAL_OVERRIDES -f $SUBCHART_OVERRIDES \ + > $LOG_FILE 2>&1 + + echo "release ${RELEASE}-${subchart} deployed" + + if [[ $VERBOSE == "true" ]]; then + cat $LOG_FILE + fi + fi + else + array=($(helm ls -q | grep "${RELEASE}-${subchart}")) + n=${#array[*]} + for (( i = n-1; i >= 0; i-- )); do + helm del "${array[i]}" --purge + done fi done -} -if [[ $# < 2 ]]; then - usage - exit 0 -fi + # report on success/failures of installs/upgrades + helm ls | grep FAILED | grep $RELEASE +} case "${1:-"help"}" in "help") diff --git a/kubernetes/helm/plugins/undeploy/undeploy.sh b/kubernetes/helm/plugins/undeploy/undeploy.sh index 02b5d34c65..8191174314 100755 --- a/kubernetes/helm/plugins/undeploy/undeploy.sh +++ b/kubernetes/helm/plugins/undeploy/undeploy.sh @@ -21,7 +21,7 @@ undeploy() { RELEASE=$1 FLAGS=$2 - array=($(helm ls -q | grep $RELEASE)) + array=($(helm ls -q --all | grep $RELEASE)) n=${#array[*]} for (( i = n-1; i >= 0; i-- )) do |