3
votes

I'm new to Helm.

I have a default value in parent chart. I want to use this value in each subchart by default, but also to have a possibility to override the value for a specific subchart.

Example:

# Parent-chart values.yaml

global:
  schedule: 10m

All the subcharts will use this value by default. But if I run something like this:

helm install --set subchart-A.schedule="20m"

Subchart-A will use value "20m".

I'm thinking about two possibilities:

  1. Maybe I can somehow link subchart-value to global value:
# Subchart values.yaml

schedule: {{ .Values.global.schedule }} # it doesn't work

In that case, it would be possible to override a specific value for the single subchart.

  1. Maybe I can write a function
# Pseudocode:

if subchart.schedule is null
  printf global.schedule
else
  printf subchart.schedule

What would you do and what is generally possible?

1
Can you use default? something like {{ .Values.global.schedule | default subchart-A.schedule }} helm.sh/docs/topics/chart_template_guide/variableshmatt1
Values yaml files cannot take variables. So, option 1 is ruled out. As you have mentioned, option 2 is the better option.droidbot
@hmatt1, thank you, it does exactly what I need (but upside down, global is default).Unfortunately it is not clear in documentation. You can add it as an answer, then I would close the question.Dennis Meissel

1 Answers

2
votes

Here is the documentation for reference.

You can specify defaults!

Example from the docs:

{{- with .Values.favorite }}
drink: {{ .drink | default "tea" | quote }}
food: {{ .food | upper | quote }}
release: {{ .Release.Name }}
{{- end }}

In your case, it would be something like:

{{ subchart-A.schedule | default .Values.global.schedule }}