<p>At the moment I have the following secret set up:</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: my-repository-key
type: kubernetes.io/dockerconfigjson
data:
  .dockerconfigjson: {{ template &quot;imagePullSecret&quot; . }}
</code></pre>
<p>Unfortunately, I have 2 subcharts using the same secret, which cause an issue when I try to install them using helm.</p>
<p>Per the <a href="https://stackoverflow.com/questions/57909821/how-to-tell-helm-to-not-create-change-resource-if-it-already-exists">stackoverflow answer</a>, I've tried using the following line to prevent the re-creation of the secret:</p>
<pre><code>{{- if not (lookup &quot;v1&quot; &quot;Secret&quot; &quot;&quot; &quot;my-repository-key&quot;) }}
</code></pre>
<p>Unfortunately It did not work, and I'm unable to debug the lookup as it's <a href="https://github.com/helm/helm/issues/8137" rel="nofollow noreferrer">impossible</a> for the time being.</p>
<p>How do I prevent the creation with a lookup? Is there a better way?</p>

Bharel
<p>In Helm charts, Kubernetes objects are often named with a prefix that's the name of the current release plus the name of the current chart.  That will make the name unique, even if there are related subcharts that declare similar secrets.  (A secret is pretty small and duplicating it between two subcharts shouldn't be an operational problem.)</p>
<pre class="lang-yaml prettyprint-override"><code>metadata:
  name: &quot;{{ .Release.Name }}-{{ .Chart.Name }}-key&quot;
</code></pre>
<p>If you created the chart with <code>helm create</code>, this pattern is common enough that the new-chart template <a href="https://github.com/helm/helm/blob/f228a7c36c2b1c33f43a6660e01038cd8e010996/pkg/chartutil/create.go#L415" rel="nofollow noreferrer">includes</a> a helper template that generates this.  If the chart only has a single secret, you can use the default name:</p>
<pre class="lang-yaml prettyprint-override"><code>metadata:
  name: &quot;{{ include &quot;chartname.fullname&quot; . }}&quot;
</code></pre>
<p>Or, up to some corner cases around naming, you can add a suffix to it</p>
<pre class="lang-yaml prettyprint-override"><code>metadata:
  name: &quot;{{ include &quot;chartname.fullname&quot; . }}-key&quot;
</code></pre>
