Use template to define sub-chart values with Helm
The PR 6876 "feat(helm): Adding values templates in order to customize values with go-template, for the chart and its dependencies" could be of interest:
There have been many requests for a way to use templates for chart values.yaml (#2492, #2133, ...).
The main reason being that it's currently impossible to derive the values of the subcharts from templates.However, having templates in
values.yaml
make them unparsable and create a "chicken or the egg" problem when rendering them.This merge request creates an intuitive solution without such a problem: an optional
values/
directory which templates are rendered usingvalues.yaml
, and then merge them with it.
Thosevalues/
templates are only required for specific cases, work the same way astemplates/
templates, andvalues.yaml
will remain the main parsable source of value.The rendering order has also been changed to allow those new values to enable or disable dependencies, and to avoid rendering values templates of disabled dependencies.
New possibilities:
Can now customize dependencies values, which was previously totally impossible
values/subchart.yaml
subchart: fullnameOverride: subchart-{{ .Relese.Name }} debug: {{ default "false" .Values.debug }}
Can derive dependencies conditions from values
Chart.yaml
dependencies:- name: subchart condition: subchart.enabled
values/subchart.yaml
subchart:{{- if eq .Values.environment "production" -}} enabled: true{{- else -}} enabled: false{{- end -}}
Similarly, PR 8580 "Added support to pass values to sub-charts via map.yaml
" is of interest
This PR allows developers to declare a
map.yaml
file on their chart, which can be used to map values invalues.yaml
to derived values that are used in templating, including sub-charts (see #8576 for the long explanation).This allows developers to write e.g.
apiVersion: v1description: Chart with map and subchartsname: chart-with-mapversion: 0.0.1dependencies: - name: backend version: 0.0.1 - name: frontend version: 0.0.1
values.yaml
domain: example.com
map.yaml
backend: uri: {{ printf "https://api.%s" .Values.domain }}frontend: uri: {{ printf "https://app.%s" .Values.domain }}other_uri: {{ printf "https://blabla.%s" .Values.domain }}
thereby not having to expose backend: uri, frontend: uri in values.yaml (for the subchart), nor ask chart users to have to pass the same value in multiple keys for consistency (or use global names that lead to naming collisions).
I.e. it allows subcharts to be populated with derived (or maped) values without exposing these values to values.yaml (the public interface of the chart).
This is being implemented/evaluated in:
- PR 8677: "fix: limit the usage of chartutil.Values to avoid conversion bugs"
- PR 8679: "fix: do not merge and import values from disabled dependencies"
- PR 8690: "feat: add values templates to customize values with go-template"
But that will likely require an HIP (Helm Improvement Proposal).
Update Feb. 2021: PR 6876 confirms in this comment a formal proposal is needed.
I had almost the same problem and found no appropriate solution. I only found this issue. They suggested using Lua in an upcoming helm release. But Lua is still not available with helm 3.0.
Therefore, I decided to implement a tool which is mostly helm compatible and is able to configure sub charts by a sandboxed Pythonic language.
For your problem it should be sufficient to put a Chart.star
file in the root folder (parallel to Chart.yaml
) with the following content
def init(self, cluster="clustername"): self.elastic = chart("charts/elasticsearch-7.4.0.tgz") self.kibana = chart("charts/kibana-7.4.0.tgz") self.elastic.cluster = cluster # Please use the right name here (from elastic../values.yaml self.kibana.elasticsearchHosts = cluster
and run
shalm apply data-viz --set cluster=toto