Setting Override Values in Helm-based Operators
Sometimes it is useful to pass down environment variables from the Operators all the way to the helm charts templates. This allows the Operator to be configured at a global level at runtime. This is new compared to dealing with the helm CLI as they usually don’t have access to any environment variables in the context of Tiller (helm v2) or the helm binary (helm v3) for security reasons.
With the helm Operator this becomes possible by override values. This enforces that certain template values provided by the chart’s default values.yaml
or by a CR spec are always set when rendering the chart. If the value is set by a CR it gets overridden by the global override value. The override value can be static but can also refer to an environment variable. To pass down environment variables to the chart override values is currently the only way.
An example use case of this is when your helm chart references container images by chart variables, which is a good practice. If your Operator is deployed in a disconnected environment (no network access to the default images location) you can use this mechanism to set them globally at the Operator level using environment variables versus individually per CR / chart release.
To configure your operator with override values, add an overrideValues
map to your watches.yaml
file for the GVK and chart you need to override. For example, to change the repository used by the nginx chart, you would update your to the following:
By setting image.repository
to quay.io/mycustomrepo
you are ensuring that quay.io/mycustomrepo
will always be used instead of the chart’s default repository (). If the CR attempts to set this value, it will be ignored.
It is now possible to reference environment variables in the overrideValues
section:
If an environment variable reference is listed in , but is not present in the environment when the operator runs, it will resolve to an empty string and override all other values. Therefore, these environment variables should always be set. It is suggested to update the Dockerfile to set these environment variables to the same defaults that are defined by the chart.
To warn users that their CR settings may be ignored, the Helm operator creates events on the CR that include the name and value of each overridden value. For example:
Last modified July 28, 2020: website: fix typo in helm override_values.md (#3588) (9a781dce)