<p>I've created a helm chart which contains some resources, which are reused in several other Helm charts:</p>
<pre><code>base/templates/base.yaml

apiVersion: secrets-store.csi.x-k8s.io/v1alpha1
kind: SecretProviderClass
metadata:
  name: {{ .Chart.Name }}
</code></pre>
<p>Then I've created a helm chart which inherits the base chart and contains some special resources:</p>
<pre><code>sub1/templates/sub1.yaml

...
name: {{ .Chart.Name }}
</code></pre>
<h2>Actual Output</h2>
<p>In the actual output the resources of the base chart use always the chart name of the base chart.</p>
<pre><code>---
# Source: sub1/templates/sub1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sub1
---
# Source: sub1/charts/base/templates/base.yaml
apiVersion: secrets-store.csi.x-k8s.io/v1alpha1
kind: SecretProviderClass
metadata:
  name: base
</code></pre>
<h2>Wanted output</h2>
<p>But I want the chart name of the sub chart to be used in the base chart resources.</p>
<pre><code># Source: sub1/charts/base/templates/base.yaml
...
kind: SecretProviderClass
metadata:
  name: sub1
</code></pre>
<p>How can I achieve this?</p>

Matthias M
<p>A solution is to reuse the resources via <a href="https://helm.sh/docs/chart_template_guide/named_templates/" rel="nofollow noreferrer">named templates</a>:</p>
<pre><code>base/templates/base.yaml

{{- define &quot;base-lib.secret-provider-class&quot; -}}
apiVersion: secrets-store.csi.x-k8s.io/v1alpha1
kind: SecretProviderClass
metadata:
  name: {{ .Chart.Name }}
{{- end -}}


sub1/templates/sub1.yaml

{{ include &quot;base-lib.secret-provider-class&quot; . }}
---
...
</code></pre>
