From 3ea990a84a9aa92d7dc19c7dca58373fcaf3559d Mon Sep 17 00:00:00 2001 From: Vadim Zabolotniy Date: Thu, 25 Aug 2022 16:54:59 +0300 Subject: [PATCH] Release upgrade command. --- README.md | 35 ++++++++++++++++++++++++++++--- lib/api/upgrade.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++ lib/main.sh | 2 ++ 3 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 lib/api/upgrade.sh diff --git a/README.md b/README.md index 373c0c0..0609b77 100644 --- a/README.md +++ b/README.md @@ -47,22 +47,51 @@ release 0.3.2 Update values of a releases, pull charts from releases ### Usage + ``` $ helm release -usage: helm release [ pull ] +usage: helm release [ pull upgrade ] +``` Available Commands: - pull Pulls (re-create) a Helm chart from a deployed Helm release +* __pull__ - Pulls (re-create) a Helm chart from a deployed Helm release +* __upgrade__ - Behaves same as `helm upgrade`, but doesn't require providing of helm chart. Chart pulled by `helm release pull`. + + +#### helm release pull +``` $ helm release pull usage: helm release pull [-d | --destination ] [-o | --output [yaml | json | text]] +``` Example: -$ helm --namespace nginx release pull nginx --destination /home/me/helm-charts +``` +$ helm --namespace nginx release pull nginx --destination /home/me/helm-charts Chart saved to nginx-ingress-0.13.2 $ ls /home/me/helm-charts/nginx-ingress-0.13.2/ Chart.yaml crds README.md templates values-icp.yaml values-nsm.yaml values-plus.yaml values.yaml +``` + +#### helm release upgrade +This command accepts same parameters as `helm upgrade` except no need to provide chart. As optional parameter you can pass `--destination` directory where chart will be dumped, by default chart dumped to `/tmp`. After release update chart will be deleted. +``` +$ helm release upgrade +Helper for helm upgrade, that doesn't require to provide original helm chart. Usage: helm release upgrade [RELEASE NAME] [-d | --destination ] [helm upgrade arguments] +``` + +Example: +``` +helm release upgrade rabbitmq --namespace=rabbitmq --set=key1=value1 --reuse-values +Hang tight while we grab the latest from your chart repositories... +...Successfully got an update from the "bitnami" chart repository +Update Complete. ⎈Happy Helming!⎈ +Saving 1 charts +Downloading common from repo https://charts.bitnami.com/bitnami +Deleting outdated charts +Release "rabbitmq" has been upgraded. Happy Helming! +... standard helm upgrade output ... ``` ## Contributing diff --git a/lib/api/upgrade.sh b/lib/api/upgrade.sh new file mode 100644 index 0000000..dc502ab --- /dev/null +++ b/lib/api/upgrade.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +help_text="Helper for helm upgrade, that doesn't require to provide original helm chart. +Usage: helm release upgrade [RELEASE NAME] [-d | --destination ] [helm upgrade arguments]" + +function upgrade_release() { + RELEASE=$1 + shift + if [[ -z $RELEASE ]]; then + printf '%s\n' 'No release was provided.' + exit_with_help "$help_text" + fi + chart_destination='/tmp' + update_arguments=() + for (( i=1; i<=$#; i++ )); + do + case "${!i}" in + (-d|--destination) + next=$((i+1)) + if [[ -z "${!next}" ]]; then + printf '%s\n' 'No destination was provided.' + exit_with_help "$help_text" + fi + chart_destination="${!next}" + ;; + (--destination*) + chart_destination=`echo "${!i}" | sed -e 's/^[^=]*=//g'` + ;; + (-h|--help) + exit_with_help "$help_text" + ;; + (*) + update_arguments[${#update_arguments[@]}]="${!i}" + ;; + esac + done + + chart_directory=$(helm release pull $RELEASE --destination=$chart_destination --output=json | jq -r .chart_directory) + if [[ -z $chart_directory ]]; then + printf '%s\n' 'Failed to get release chart.' + return 1; + fi + chart_path="$chart_destination/$chart_directory" + + helm dependency build $chart_path + helm upgrade "$RELEASE" "$chart_path" "${update_arguments[@]}" + + rm -rf $chart_path + + return 0; +} \ No newline at end of file diff --git a/lib/main.sh b/lib/main.sh index 57610ae..f282693 100644 --- a/lib/main.sh +++ b/lib/main.sh @@ -2,6 +2,7 @@ source $(dirname -- "$0")/lib/config.sh source $(dirname -- "$0")/lib/utility.sh source $(dirname -- "$0")/lib/api/helm-ops.sh +source $(dirname -- "$0")/lib/api/upgrade.sh function main() { @@ -11,6 +12,7 @@ function main() { declare -A -x command_table=( ['pull']="pull_chart_from_release" + ['upgrade']="upgrade_release" ) local commands="${!command_table[@]}"