<p>I am beginner in helm chart templating and I'm looking for best practise.
I would like to create a helm chart template enough generics to use same chart for all team project (backend, front-end,..)
On order to make it generics I can let developer to specify list of many cases in values.yml (volumes for deployment, network policy ingress egress etc...).
And i could keep the kubernetes template deployment, service etc.. Enough generics to never mention any specific keys.
So the developer could only modify values yml for add values for their application behavior.</p>
<p>The disadvantage is that the kubernetes generics template will not contain any logic about the application , and the generic template will be hard to maintain (because it will handle every possible case).
The advantage is that the developer doesn't need to understand helm because they will not modify the kubernetes template.</p>
<p>So you have any experience about that?</p>

julus
<p>You can use _*.tpl files to define generic templates, They are located in ./templates/_*.tpl (. being the directory with global Chart.yaml and values.yaml).
Also by defaul in helm global values override local values. Solution to this can be found here - <a href="https://github.com/helm/helm/issues/5676" rel="nofollow noreferrer">https://github.com/helm/helm/issues/5676</a></p>
<p>By using these 2 techniques in conjunction you can make generic templates and only use values.yaml to render what you want to render.</p>
<p>For example:</p>
<p>values.yaml:</p>
<pre><code>global:
  defaults:
    switches:
      volumesEnabled: false
      ingressEnabled: false
    ingress:
      host: &quot;generic-host.com&quot;
    volumes:
      volumeName: &quot;generic-volume-name&quot;

subchart1:
  defaultOverrides:
    switches:
      volumesEnabled: true
  volumes:
    volumeName: &quot;not-so-generic-name&quot;

subchart2:
  defaultOverrides:
    switches:
      volumesEnabled: true
      ingressEnabled: true
</code></pre>
<p>Then templates (java is just for grouping templates in one category, you can try to guess in which language my backend microservices are written :) )</p>
<p>./templates/java/_deployment.tpl:</p>
<pre><code>{{- define &quot;templates.java.deployment&quot; }}
{{- $properties := merge .Values.defaultOverrides $.Values.global.defaults -}}
{{*/ generic deployment structure */}}
{{- if $properties.switches.volumesEnabled -}}
volume: {{ $properties.volumes.volumeName }}
{{- end }}
{{*/ generic deployment structure */}}
{{- end }}
</code></pre>
<p>./templates/java/_ingress.tpl:</p>
<pre><code>{{- define &quot;templates.java.ingress&quot; }}
{{- $properties := merge .Values.defaultOverrides $.Values.global.defaults -}}
{{- if $properties.switches.ingressEnabled -}}
host: {{ $properties.ingress.host }}
{{*/ generic ingress structure */}}
{{- end }}
{{- end }}
</code></pre>
<p>And then subchart templates
./charts/subchart1/templates/deployment.yaml:</p>
<pre><code>{{ include &quot;templates.java.deployment&quot; . }}
</code></pre>
<p>./charts/subchart1/templates/ingress.yaml:</p>
<pre><code>{{ include &quot;templates.java.ingress&quot; . }}
</code></pre>
<p>subchart2 has exactly the same includes.</p>
<p>In the end we will have:</p>
<p>subchart1:</p>
<ul>
<li>has deployment</li>
<li>volumeName is overriden from local values with &quot;not-so-generic-name&quot;</li>
<li>ingress is not rendered at all</li>
</ul>
<p>subchart2:</p>
<ul>
<li>has deployment</li>
<li>volumeName is default from global values</li>
<li>ingress host is default from global values</li>
</ul>
<p>But I would say that it's a bad practice to generlize to much, because it will make your templates overly complex. In my case I found 2 distinct groups which have nearly identical manifests within them (basically frontend and backend) and made a set of _*.tpl files for each of them and settings default values for each group respectivelly in global values.yaml.</p>
