Search code examples
kuberneteskubernetes-helm

How to get values dynamically based on parameters in Helm Chart


I did Helm Chart helper file as follows:

{{- define "logging.log_path" -}}
{{- if and .Values.log_path (eq .Values.app_type "sales") }}
{{- join "," .Values.log_path.sales }}
{{ else if and .Values.log_path (eq .Values.app_type "inventory") }}
{{- join "," .Values.log_path.inventory }}
{{ else if and .Values.log_path (eq .Values.app_type "order") }}
{{- join "," .Values.log_path.order }}
{{ else if and .Values.log_path (eq .Values.app_type "warehouse") }}
{{- join "," .Values.log_path.warehouse }}
{{ else }}
{{- join "," .Values.log_path.sales }}
{{- end }}
{{- end }}

The problem is whenever it's required to add new app_type, I need to add app_type in that file manually. I think it's difficult to maintain and time consuming either.

Is there anyway that I could do like that .Values.log_path[".Values.app_type"] or any solution similar to that one? Thanks.


Solution

  • Helm includes a dictionary helper get

    get $myDict "key1"

    {{ define "logging.log_path" }}
    {{- $path := get .Values.log_path .Values.app_type | default .Values.log_path.sales -}}
    {{- join "," $path -}}
    {{ end }}