Full Blog TOC

Full Blog Table Of Content with Keywords Available HERE

Wednesday, June 9, 2021

Sending Parameters to Helm Named Template



 

Somehow, sending parameters to an Helm named template is poorly documented, so I give some clear example below. This is based on the Helm documentation functions in this page.


Assuming we have the following sample Helm named template:


{{- define "myNamedTemplate" }}
- name: {{ .Values.myParam1 }}
value: {{ .Values.myValue1 | quote }}
- name: {{ .Values.myParam2 }}
value: {{ .Values.myValue2 | quote }}
{{- end }}


To send flat parameters to Helm named template, use should use dict, for example:


{{- $myValues := dict "myParam1" "myValue1" "myParam2" "myValue2" -}}
{{- $myParameters := dict "Values" $myValues -}}
{{- include "myNamedTemplate" $myParameters }}


Or if hierarchical parameters is required, you can use the following:


{{- $myValues := dict -}}
{{- $myInnerValues := dict "innerVariable" "innerValue" -}}
{{- $_ := set $myValues "inner" $myInnerValues -}}
{{- $myParameters := dict "Values" $myValues -}}
{{- include "myNamedTemplate" $myParameters }}

 


If case the named template uses a .Values.global.VARIABLE , add the global dictionary as well:


{{- $myValues := dict "myParam1" "myValue1" "myParam2" "myValue2" -}}
{{- $_ := set $myValues "global" .Values.global -}}
{{- $myParameters := dict "Values" $myValues -}}
{{- include "myNamedTemplate" $myParameters }}


To override existing parameters, only for a specific activation, use the following:


{{- $myValues := .Values | deepCopy -}}
{{- $_ := set $myValues "myOverrideParam" "overridenValue" -}}
{{- $myParameters := dict "Values" $myValues -}}
{{- include "myNamedTemplate" $myParameters }}


To override just a single global variable, use the following:


{{- $myValues := .Values | deepCopy -}}
{{- $_ := set $myValues "global" .Values.global -}}
{{- $_ := set $myValues.global.OVERRIDE_GLOBAL_PARAMETER_NAME "OVERRIDE_GLOBAL_PARAMETER_VALUE" -}}
{{- $myParameters := dict "Values" $myValues -}}




2 comments:

  1. I don't get it = where is the template definition itself in your example?
    never mind - i figured it out

    ReplyDelete
    Replies
    1. I have added a sample template to clarify this

      Delete