<p><strong>Use case</strong></p>

<p>"I want to deploy elasticsearch + kibana, by using elastic official helm charts. I want to create a helm chart called data-viz with these charts as dependency."</p>

<p>Running <code>helm install data-viz --set cluster=toto</code> must create an elasticsearch cluster "toto", and a kibana configured with <code>elasticsearchHosts</code> = toto.</p>

<p><strong>Problem</strong></p>

<p>I see here <a href="https://github.com/helm/helm/blob/master/docs/chart_template_guide/subcharts_and_globals.md" rel="noreferrer">https://github.com/helm/helm/blob/master/docs/chart_template_guide/subcharts_and_globals.md</a> it's possible to configure sub-chart from main-chart <code>values.yml</code>. But I would like templatize sub-chart values.yml from main-chart values.yaml, is it possible?</p>

<p>I was thinking to something simple as:</p>

<pre><code>.
├── Chart.yaml
├── charts
│   ├── elasticsearch
│   │   ├── Chart.yaml
│   │   └── templates
│   │       └── values.yaml
│   ├── elasticsearch-7.4.0.tgz
│   └── kibana-7.4.0.tgz
├── requirements.lock
├── requirements.yaml
└── values.yaml
</code></pre>

<p><strong>Hack solution</strong></p>

<p>A small Python script that creates the <code>values.yaml</code> file from <code>sub-chart/values-template.yaml</code> + data.</p>

<p><strong>TLDR:</strong> Not possible as of now, although there were several attempts to add such functionality that failed all of the committers to the project were unwilling to go through the additional bureaucracy required by the Helm project members.</p>
<p>The <a href="https://github.com/helm/helm/pull/6876" rel="nofollow noreferrer">PR 6876</a> &quot;feat(helm): Adding values templates in order to customize values with go-template, for the chart and its dependencies&quot; could be of interest:</p>
<blockquote>
<p>There have been many requests for a way to use templates for chart values.yaml (#2492, <a href="https://github.com/helm/helm/issues/2133#issuecomment-683222039" rel="nofollow noreferrer">#2133</a>, ...).<br />
The main reason being that it's currently impossible to derive the values of the subcharts from templates.</p>
<p>However, having templates in <code>values.yaml</code> make them unparsable and create a &quot;chicken or the egg&quot; problem when rendering them.</p>
<p>This merge request creates an intuitive solution without such a problem: an optional <code>values/</code> directory which templates are rendered using <code>values.yaml</code>, and then merge them with it.<br />
Those <code>values/</code> templates are only required for specific cases, work the same way as <code>templates/</code> templates, and <code>values.yaml</code> will remain the main parsable source of value.</p>
<p>The rendering order has also been changed to allow those new values to enable or disable dependencies, and to avoid rendering values templates of disabled dependencies.</p>
<h2>New possibilities:</h2>
<p>Can now customize dependencies values, which was previously totally impossible</p>
</blockquote>
<h3>values/subchart.yaml</h3>
<pre><code>subchart:
    fullnameOverride: subchart-{{ .Relese.Name }}
    debug: {{ default &quot;false&quot; .Values.debug }}
</code></pre>
<blockquote>
<p>Can derive dependencies conditions from values</p>
</blockquote>
<h3>Chart.yaml</h3>
<pre class="lang-yaml prettyprint-override"><code>dependencies:
- name: subchart
  condition: subchart.enabled
</code></pre>
<h3>values/subchart.yaml</h3>
<pre class="lang-yaml prettyprint-override"><code>subchart:
{{- if eq .Values.environment &quot;production&quot; -}}
  enabled: true
{{- else -}}
  enabled: false
{{- end -}}
</code></pre>
<hr />
<p>Similarly, <a href="https://github.com/helm/helm/pull/8580" rel="nofollow noreferrer">PR 8580</a> &quot;Added support to pass values to sub-charts via <code>map.yaml</code>&quot; is of interest</p>
<blockquote>
<p>This PR allows developers to declare a <code>map.yaml</code> file on their chart, which can be used to map values in <code>values.yaml</code> to derived values that are used in templating, including sub-charts (see <a href="https://github.com/helm/helm/issues/8576" rel="nofollow noreferrer">#8576</a> for the long explanation).</p>
<p>This allows developers to write e.g.</p>
</blockquote>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
description: Chart with map and subcharts
name: chart-with-map
version: 0.0.1
dependencies:
  - name: backend
    version: 0.0.1
  - name: frontend
    version: 0.0.1
</code></pre>
<h3>values.yaml</h3>
<pre class="lang-yaml prettyprint-override"><code>domain: example.com
</code></pre>
<h3>map.yaml</h3>
<pre class="lang-yaml prettyprint-override"><code>backend:
  uri: {{ printf &quot;https://api.%s&quot; .Values.domain }}

frontend:
  uri: {{ printf &quot;https://app.%s&quot; .Values.domain }}

other_uri: {{ printf &quot;https://blabla.%s&quot; .Values.domain }}
</code></pre>
<blockquote>
<p>thereby not having to expose backend: uri, frontend: uri in values.yaml (for the subchart), nor ask chart users to have to pass the same value in multiple keys for consistency (or use global names that lead to naming collisions).</p>
<p>I.e. it allows subcharts to be populated with derived (or maped) values without exposing these values to values.yaml (the public interface of the chart).</p>
</blockquote>
<hr />
<p>This is being implemented/evaluated in:</p>
<ul>
<li><a href="https://github.com/helm/helm/pull/8677" rel="nofollow noreferrer">PR 8677</a>: &quot;fix: limit the usage of chartutil.Values to avoid conversion bugs&quot;</li>
<li><a href="https://github.com/helm/helm/pull/8679" rel="nofollow noreferrer">PR 8679</a>: &quot;fix: do not merge and import values from disabled dependencies&quot;</li>
<li><a href="https://github.com/helm/helm/pull/8690" rel="nofollow noreferrer">PR 8690</a>: &quot;feat: add values templates to customize values with go-template&quot;</li>
</ul>
<p>But that <a href="https://github.com/helm/helm/pull/6876#issuecomment-687233515" rel="nofollow noreferrer">will likely require</a> an <a href="https://github.com/helm/community/blob/master/hips/hip-0001.md" rel="nofollow noreferrer">HIP (Helm Improvement Proposal)</a>.</p>
<hr />
<p>Update Feb. 2021: <a href="https://github.com/helm/helm/pull/6876" rel="nofollow noreferrer">PR 6876</a> confirms in <a href="https://github.com/helm/helm/pull/6876#issuecomment-707002193" rel="nofollow noreferrer">this comment</a> a formal proposal is needed.</p>
