Skip to content

Commit

Permalink
Vadim zabolotniy main (#20)
Browse files Browse the repository at this point in the history
* Release upgrade command.

* Update README

* Update contributing guide and plugin version

Co-authored-by: Vadim Zabolotniy <zabolotniy.v.y@gmail.com>
  • Loading branch information
rtpro and vadim-zabolotniy authored Aug 25, 2022
1 parent edce4ab commit b3af1b0
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 12 deletions.
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 </PATH/TO/helm-release-plugin>
HELM_PLUGINS=$(pwd)/.. helm release <COMMAND>
```


## 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.

Expand Down
45 changes: 34 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <RELEASE NAME> [-d | --destination <TARGET CHART DIRECTORY>] [-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 <TARGET CHART DIRECTORY>] [helm upgrade arguments]
```

Example:
```
helm release upgrade rabbitmq --namespace=rabbitmq --set=key1=value1 --reuse-values
...
... standard helm upgrade output ...
Update Complete. ⎈Happy Helming!⎈
```

## Contributing
Expand Down
51 changes: 51 additions & 0 deletions lib/api/upgrade.sh
Original file line number Diff line number Diff line change
@@ -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 <TARGET CHART DIRECTORY>] [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;
}
2 changes: 2 additions & 0 deletions lib/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -11,6 +12,7 @@ function main() {

declare -A -x command_table=(
['pull']="pull_chart_from_release"
['upgrade']="upgrade_release"
)

local commands="${!command_table[@]}"
Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b3af1b0

Please sign in to comment.