From b3af1b0c6ccf7513c4a949971737d743d5e17a96 Mon Sep 17 00:00:00 2001 From: Arthur Berezin <2787296+rtpro@users.noreply.github.com> Date: Thu, 25 Aug 2022 20:56:16 +0300 Subject: [PATCH] Vadim zabolotniy main (#20) * Release upgrade command. * Update README * Update contributing guide and plugin version Co-authored-by: Vadim Zabolotniy --- CONTRIBUTING.md | 9 ++++++++ README.md | 45 ++++++++++++++++++++++++++++++---------- lib/api/upgrade.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++ lib/main.sh | 2 ++ plugin.yaml | 2 +- 5 files changed, 97 insertions(+), 12 deletions(-) create mode 100644 lib/api/upgrade.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c0820d8..ed11360 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,6 +18,15 @@ Pull requests are the best way to propose changes to the codebase (we use [Githu 1. Update the documentation according the change. 1. Issue that pull request! + +## Developmnet environmnet +To debug and test in developmnet, run command: +``` +cd +HELM_PLUGINS=$(pwd)/.. helm release +``` + + ## Any contributions you make will be under the Apache 2.0 Software License In short, when you submit code changes, your submissions are understood to be under the same [Apache License]([http://choosealicense.com/licenses/mit/](https://github.com/JovianX/helm-release-plugin/blob/main/LICENSE)) that covers the project. Feel free to contact the maintainers if that's a concern. diff --git a/README.md b/README.md index 373c0c0..e13d33b 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,19 @@ [![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/helm-release)](https://artifacthub.io/packages/helm-plugin/helm-release/release) [![GitHub license](https://img.shields.io/github/license/JovianX/helm-release-plugin)](https://github.com/JovianX/helm-release-plugin) ![GitHub contributors](https://img.shields.io/github/contributors/JovianX/helm-release-plugin) -[![GitHub stars](https://img.shields.io/github/stars/JovianX/helm-release-plugin)](https://github.com/JovianX/helm-release-plugin/stargazers) **Please star ⭐ the repo if you find it useful.** +[![GitHub stars](https://img.shields.io/github/stars/JovianX/helm-release-plugin)](https://github.com/JovianX/helm-release-plugin/stargazers) >> **Please star ⭐ the repo if you find it useful.** -`helm-release` is a Helm 3 plugin that allows running operatins on Helm releases (deployed Helm charts). +`helm-release` is a Helm 3 plugin that allows running operations on Helm releases (deployed Helm charts). Features: * Pull (re-create) Helm charts from a deployed helm release. - * Update values of a deployed release (without the chart package or path). + * Update values of a deployed release, without providing the chart used for release deployment. Common use-Cases: - * Redeploy a release on another cluster or namespace with the exact same helm chart. - * Update values of a release without the original helm chart, when you are not sure what exact version was used, or you have no access to the original helm chart (helm upgrade command requires the chart `helm upgrade [RELEASE] [CHART] [flags]`). + * Redeploy a release on another cluster or namespace with the same helm chart. + * Update values of a release, when you are not sure what exact chart version was used, or you don't have access to the original helm chart (Contrary to the `helm upgrade` command which requires the chart). ## Getting started ### Installation @@ -32,37 +32,60 @@ helm plugin install https://github.com/JovianX/helm-release-plugin >> Install: https://stedolan.github.io/jq/download/ > -Update to latest: +Update to the latest version: ```shell $ helm plugin update release ``` Verify it's been installed: ```shell $ helm plugin list -NAME VERSION DESCRIPTION +NAME VERSION DESCRIPTION ... -release 0.3.2 Update values of a releases, pull charts from releases +release 0.3.2 Update values of a release, 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 the same as `helm upgrade`, but doesn't require the helm chart. The Chart is pulled from the release (`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 the same parameters as `helm upgrade` except specifying the helm chart. As an optional parameter you can pass `--destination` directory where the 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 +... +... standard helm upgrade output ... +Update Complete. ⎈Happy Helming!⎈ ``` ## Contributing diff --git a/lib/api/upgrade.sh b/lib/api/upgrade.sh new file mode 100644 index 0000000..10b3c47 --- /dev/null +++ b/lib/api/upgrade.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +help_text="helm release upgrade - Update release values without specifying the Helm Chart used for deployment. +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[@]}" diff --git a/plugin.yaml b/plugin.yaml index 1265552..447cb82 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ Name: release -version: 0.3.2 +version: 0.3.2-dev usage: pull or update Helm Releases description: Update values of a releases, pull charts from releases command: $HELM_PLUGIN_DIR/release.sh