I am new in helm and currently come up with a situation where I need to test the existence of 2 parameters defined in values.yaml and if present, use the value of the same in sample.yaml.
Note - This is sure that one of them will be present.
For example:
I am testing for these 2 values:
1 - {{ .Values.probes.xyz.readiness.initialDelaySeconds }}
2 - {{ .Values.readiness.xyz.initialDelaySeconds }}
And inside sample.yaml, I have to implement one of the above parameter based on existence:
initialDelaySeconds: <one of the above values needs to be implemented based on the existence>
I understand it's a simple if else
condition, but I am unable to implement.
Any help would be appreciated.
For logic where you want to use some value if it's set and some other value if not, the Helm default
function is usually a good match.
{{- $v1 := .Values.probes.xyz.readiness.initialDelaySeconds }}
{{- $v2 := .Values.readiness.xyz.initialDelaySeconds }}
initialDelaySeconds: {{ $v1 | default $v2 }}
If you have multiple settings like this, you can also do things like merge
the two values-item dictionaries together.
{{- $readiness := merge dict .Values.probes.xyz.readiness .Values.readiness.xyz }}
initialDelaySeconds: {{ $readiness.initialDelaySeconds }}