I have structure similar to the following example:
values.yaml
config:
value: "unset"
values-dev.yaml
config:
value: "development"
values-prod.yaml
config:
value: "production"
I need to make sure that the value is set by the specific environment and, if we forget to add it to the values-*env*.yaml, the templating step should fail.
In other words, in the example above there should NEVER be "unset" in any enviornment and if we create a new values-**.yaml file with no value: "something"
inside, it should fail during templating.
I couldn't find a way to do it in the documentation
The most straightforward path to this is to use Helm's required
template function.
In your chart's values.yaml
, do not provide a value for the required-with-no-default setting. It may be helpful to include the containing value explicitly as a YAML mapping.
# values.yaml
config: {}
# value: not mentioned here
At the point where you go to use the value, include required
in a pipeline. That will fail if the value isn't present (more specifically if it's nil
or another "falsey" value).
# templates/deployment.yaml
env
- name: ENVIRONMENT
value: {{ .Values.config.value | required "config.value setting is required" }}
(You need more complex logic if it's possible the config
wrapper doesn't exist either. You need different logic if "falsey" values like zero or empty-string are legitimate values, probably containing the Sprig hasKey
function with Helm fail
and conditionals as shown in @RuiJarimba's answer.)