I'd like to impement the following scenario.
Global variable
global:
env:
name: prod
Chart specific variable
env:
name: dev
I want to have precedence of chart specific > global variable
eg: In my chart, I want to use something like
containers:
- name: "{{- include "tester.getValueWithPrecedence" (list . "env.name") -}}"
And this is the _helpers.tpl function
{{- define "tester.getValueWithPrecedence" -}}
{{- $top := index . 0 }}
{{- $var := index . 1 }}
{{- if hasKey $top.Values $var -}}
{{- index $top.Values $var -}}
{{- else if hasKey $top.Values.global $var -}}
{{- index $top.Values.global $var -}}
{{- end -}}
{{- end -}}
I think the problem is env.name key is not interpreted as subkey, but a string.
Is there any way to achieve this?
Any help is much appreciated.
I figured out a simpler approach.
and the input will be
Values.yaml