#kubernetes #helm

app helm-templexer

Render Kubernetes Helm charts for multiple environments with explicit config while keeping the overhead at ease

17 releases (2 stable)

2.0.0 Sep 9, 2021
1.0.0 Aug 24, 2021
0.3.0 Aug 23, 2021
0.2.11 Aug 23, 2021
0.1.1-alpha Jul 27, 2020

#100 in Command line utilities

Download history 24/week @ 2021-06-07 1/week @ 2021-06-14 1/week @ 2021-06-21 1/week @ 2021-07-05 10/week @ 2021-07-19 10/week @ 2021-07-26 22/week @ 2021-08-02 18/week @ 2021-08-16 99/week @ 2021-08-23 16/week @ 2021-09-06 12/week @ 2021-09-13

54 downloads per month

MIT license

52KB
894 lines

⎈ Helm Templexer

Render Helm charts for multiple environments with explicit config while keeping the overhead at ease.

The helm-templexer wraps Helm v3+, please ensure that it is installed and in the PATH.

cat > my-app.yaml <<EOF
version: v2
chart: tests/data/nginx-chart
release_name: my-app
output_path: manifests
deployments:
  - name: edge
  - name: stage
  - name: prod
EOF

helm-templexer render my-app.yaml

Outcome:

❯ exa -T manifests
manifests
├── edge
│  └── my-app
│     └── manifest.yaml
├── prod
│  └── my-app
│     └── manifest.yaml
└── stage
   └── my-app
      └── manifest.yaml

Configuration

Configuration can be provided as YAML format.

All paths are evaluated relative to the configuration file during execution.

Looking for schema v1? Please see helm-templexer 1.x.

Parameter Description Condition Default Example
version Schema version to use required "v2"
enabled Whether to render deployments or not optional true
chart Path to the chart to render required "path/to/some-chart"
namespace Namespace to pass on to helm; when omitted, no namespace is passed optional ""
release_name Release name to pass to helm required "some-release"
output_path Base path to use for writing the manifests to disk.

The fully-qualified output path is built as follows (config refers to the top-level):
config.output_path/deployment.name/<[config/deployment].release_name>/manifest.yaml
required
additional_options Pass additional options to helm template; you can use all supported options of the tool.

Common use case: use --set-string to provide a container tag to use.
This can be achieved by modifying the configuration file in your build pipeline using mikefarah/yq
optional [] ["--set-string image.tag=42"]
values A list of base value files which are passed to each helm template call.
This is commonly used to provide a sane base config.
optional []
deployments The list of deployments to render. required [[deployments]]
name = "edge"

Deployments can override several top-level fields:

Parameter Description Condition Default Example
name Name of the deployment; only used in the output path required "edge-eu-w4"
enabled Allows for disabling individual deployments optional true
release_name Override the release name optional ""
additional_options Additional options, as seen above, but specific to this deployment optional []
values Value files to use for this deployment optional []

Additional Options to The Render Command

Extending The helm template Call

Use --additional-options to pass data to the underlying helm template call. Beware that these additional options get added to every call, i.e. to each deployment.

A common use case we found was to provide the container tag:

helm-templexer render --additional-options="--set-string image.tag=${revision}" my-app.yaml

Render a Subset of Deployments

Use --filter to render a specific deployment. Example: To render only the prod, pass the regex to the filter option.

helm-templexer render --filter="prod" my-app.yaml

Update Helm Dependencies Before Rendering

Use --update-dependencies to run helm dependencies update once before starting to render the deployments.

helm-templexer render --update-dependencies my-app.yaml

Pipe Manifest Output Through Tool(s) Before Writing to Disk

Use --pipe to pass the manifest output through a tool or set of tools before writing to a file.

Please mind that this option requires an equal sign (=), i.e. `--pipe="".

helm-templexer render --pipe="kbld -f -" my-app.yaml

You can define the argument multiple times; the commands will be added in order of appearance to the final command.

helm-templexer render --pipe="kbld -f -" --pipe="tee /dev/stdout" my-app.yaml

If anything unexpected happens, you can use -v, -vv and -vvv to increase the log level and see the underlying command.

Installation

Docker

# create the directory where helm-templexer will render to
mkdir -p tests/data/manifests

# let helm-templexer's user id (1001) own the directory
sudo chown -R 1001 tests/data/manifests

# pull and run the image
docker pull ghcr.io/hendrikmaus/helm-templexer
docker run --rm --volume $(pwd):/srv --workdir /srv/tests/data ghcr.io/hendrikmaus/helm-templexer render config_example.yaml 

Include helm-templexer in your Dockerfile:

FROM ghcr.io/hendrikmaus/helm-templexer AS helm-templexer-provider
COPY --from=helm-templexer-provider /usr/bin/helm-templexer /usr/bin
COPY --from=helm-templexer-provider /usr/bin/helm /usr/bin

Homebrew

brew tap hendrikmaus/tap
brew install helm-templexer

Cargo Install

Helm Templexer is written in Rust. You will need rustc version 1.35.0 or higher. The recommended way to install Rust is from the official download page. Once you have it set up, a simple make install will compile helm-templexer and install it into $HOME/.cargo/bin.

If you’re using a recent version of Cargo (0.5.0 or higher), you can use the cargo install command:

cargo install helm-templexer

Cargo will build the binary and place it in $HOME/.cargo/bin (this location can be overridden by setting the --root option).

Dependencies

~5–7MB
~139K SLoC