vipin
vipin

Reputation: 55

Dynamic variables in Helm values.yaml file

I have a use case where i want to have dynamic value for given attribute in helm values.yaml.For example I have below version file

version=123

I want to dynamically parse and consume this version into helm values.yaml version attribute.

Expected values.yaml

name: abc
version: 123

Upvotes: 3

Views: 3955

Answers (1)

xdhmoore
xdhmoore

Reputation: 9915

There are many options depending on what goes best with your toolset, but what I've done/seen done in the past is to create your own template of the yaml file, values.yaml.template, and substitute the desired values in.

So, for example your values.yaml.template, would be something like:

name: abc
version: {{version}}

And you would pass both the template filename and the version filename to a templating engine to do the substitution.

Some ways to do this:

  • sed - a little hacky but already installed. Here's an example.
  • jinja2-cli - I've used this effectively to substitute values into a template file
  • mustache - I've never used but it seems to be built with the CLI in mind
  • confd - Seems geared towards this situation, though I've never used it.
  • Make/use a CLI tool some other template language you are already using - I've seen someone make a Freemarker CLI tool, for example.

There are obviously a large number of templating languages, so it's a matter of what is the least effort given your stack. But maybe a more difficult question is, how do you hook into the helm provisioning or startup so that you can generate the config yaml file from your template. This also depends on your stack.

[UPDATE] I'm not familiar with helm, but it may also be possible to get config values dynamically (ie, using a helm plugin that retrieves the helm config from a config server at helm startup).

Upvotes: 2

Related Questions