This Helm plugin allows you to substitute the environment variables specified in your helm values file with their respective values in the environment from within a CICD pipeline.
The installation itself is simple as:
helm plugin install https://github.com/hydeenoble/helm-subenv.git
You can install a specific release version:
helm plugin install https://github.com/hydeenoble/helm-subenv.git --version <release version>
To use the plugin, you do not need any special dependencies. The installer will download the latest release with prebuilt binary from GitHub releases.
helm subenv -f <path to values file>
helm subenv -f <path to values file> -f <path to values file> -f <path to values file>
The plugin can also be used to recursively substitute environment variables in all the files in a specified directory.
helm subenv -f <path to directory>
You can also decide to mix files and directories:
helm subenv -f <path to values file> -f <path to directory>
Sample helm values file:
# values.yaml
image:
repository: $REGISTRY/$IMAGE_NAME
tag: $IMAGE_TAG
Environment variables configured in your environment (this should most likely be configured with your CI environment):
REGISTRY => docker.com
IMAGE_NAME => helm-subenv
IMAGE_TAG => test
Substitute Env:
helm subenv -f values.yaml
Result:
image:
repository: docker.com/helm-subenv
tag: test
Note: If the value of the environment variable does not exist, it will be replaced with an empty string. For instance, from the above example, if IMAGE_TAG
does not exist as an environment variable in the environment the result would have been:
image:
repository: docker.com/helm-subenv
tag:
helm plugin remove subenv
To test locally, run the command below to build and run the binary:
You need to have Go installed. Make sure to set
$GOPATH
go build -o subenv && ./subenv -f </path/to/values/file>