<p>I'm starting to write helm charts for our services.</p>
<p>There are two things I'm not sure how they are supposed to work or what to do with them.</p>
<p>First: the release name. When installing a chart, you specify a name which helm uses to create a release. This release name is often referenced within a chart to properly isolate chart installs from each other? For example the postgres chart contains:</p>
<pre><code>{{- define &quot;postgresql.fullname&quot; -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf &quot;%s-%s&quot; .Release.Name $name | trunc 63 | trimSuffix &quot;-&quot; -}}
{{- end -}}
</code></pre>
<p>Which is then used for the service:</p>
<pre><code>metadata:
  name: {{ template &quot;postgresql.fullname&quot; . }}
</code></pre>
<p>It does look like &quot;myrelease-postgresql&quot; in the end in kubernetes.
I wonder what a good release name is? What is typically used for this? A version? Or some code-name like the ubuntu releases?</p>
<p>Second: referencing values.</p>
<p>My chart uses postgresql as a sub-chart. I'd like to not duplicate the way the value for the name of the postgresql service is created (see snipped above).</p>
<p>Is there a way I can reference the service name of a sub-chart or that template define {{ template &quot;postgresql.fullname&quot; . }} in the parent chart? I need it to pass it into my service as database host (which works if I hardcode everything but that cannot be the meaning of this).</p>
<p>I tried:</p>
<pre><code>      env:
        - name: DB_HOST
          value: {{ template &quot;mychart.postgresql.fullname&quot; . }}
</code></pre>
<p>But that lead into an error message:</p>
<pre><code>template &quot;mychart.postgresql.fullname&quot; not defined
</code></pre>
<p>I've seen examples of Charts doing similar things, like the <a href="https://github.com/kubernetes/charts/blob/master/stable/odoo/templates/_helpers.tpl" rel="nofollow noreferrer">odoo</a> chart. But in here that logic how the postgresql host name is created is copied and an own define in the template is created.</p>
<p>So is there a way to access sub-chart names? Or values or template defines?</p>
<p>Thanks!</p>
<p><strong>Update after some digging:</strong>
According to <a href="https://helm.sh/docs/chart_template_guide/subcharts_and_globals/" rel="nofollow noreferrer">Subcharts and Globals</a> the templates are shared between charts.</p>
<p>So what I can do is this:</p>
<p>In my chart in _helpers.tpl I add (overwrite) the postgres block:</p>
<pre><code>{{- define &quot;postgresql.fullname&quot; -}}
{{- $name := .Values.global.name -}}
{{- printf &quot;%s-%s&quot; $name &quot;postgresql&quot; | trunc 63 | trimSuffix &quot;-&quot; -}}
{{- end -}}
</code></pre>
<p>So this value is used when the sub-chart is deployed. I cannot reference all values or the chart name in here as it will be different in the sub-chart - so I used a global value.</p>
<p>Like this I know the value of the service that is created in the sub-chart.</p>
<p>Not sure if this is the best way to do this :-/</p>

<p>Are you pulling in <code>postgresql</code> as a subchart of your chart (via your chart's <code>requirements.yaml</code>)?  If so, both the <code>postgresql</code> (sub) chart and your chart will have the <strong>same</strong> <code>.Release.Name</code> - thus, you could specify your container's environment as</p>

<pre><code>  env:
    - name: DB_HOST
      value: {{ printf "%s-postgresql" .Release.Name }}
</code></pre>

<p>if you override <code>postgresql</code>'s name by adding the following to your chart's <code>values.yaml</code>:</p>

<pre><code>postgresql:
  nameOverride: your-postgresql
</code></pre>

<p>then your container's env would be:</p>

<pre><code>  env:
    - name: DB_HOST
      value: {{ printf "%s-%s" .Release.Name .Values.postgresql.nameOverride }}
</code></pre>
