<p>I was trying to implement the Helm Kubernetes deployment using helm chart. I would to give the deployment,app and service name using the helm release name dynamically.</p>

<p>I have implemented the below approach which help me to create the dynamic name based upon the helm file.</p>

<p><strong>Written the below method inside the _helper.tpl</strong></p>

<pre><code>{{- define "sample-chart-getServiceName" -}}
{{- $arg1 := index . "arg1" -}}
{{- $fullName := include "sample-chart.fullname" . -}}
{{- printf "%s-%s" $fullName $arg1 -}}
{{- end -}} 
</code></pre>

<p>and below ways to calling the function inside the yaml file</p>

<pre><code>name: {{ include "sample-chart-getServiceName" (dict "arg1" "service") }}
</code></pre>

<p>A Helm template takes a single parameter, and it's assigned to the special variable <code>.</code>.  In your example you're trying to use <code>.</code> as both the parameter holding the service name and also the top-level context to pass to the downstream <code>sample-chart.fullname</code> template.</p>

<p>To work around this, you can pack the two parameters into a list:</p>

<pre class="lang-none prettyprint-override"><code>{{ include "sample-chart-getServiceName" (list . (dict "arg1" "service")) }}
</code></pre>

<pre class="lang-none prettyprint-override"><code>{{- define "sample-chart-getServiceName" -}}
{{- $top := index . 0 -}}
{{- $arg1 := index . 1 "arg1" -}}
{{- $fullName := include "sample-chart.fullname" $top -}}
...
</code></pre>

<p>Or, if you were intending to pass multiple values by name, include the top-level context as one of those parameters</p>

<pre class="lang-none prettyprint-override"><code>{{ include "sample-chart-getServiceName" (dict "top" . "arg1" "service") }}
</code></pre>

<pre class="lang-none prettyprint-override"><code>{{- $top := index . "top" -}}
{{- $arg1 := index . "arg1" -}}
</code></pre>
