<p>I have a template which I'm generating a name using <code>uuidv4</code> built-in function:</p>
<pre><code>apiVersion: k6.io/v1alpha1
kind: pod
metadata:
  name: test-{{ uuidv4 }}
  namespace: {{ .Release.Namespace }}
</code></pre>
<p>Then, I want to use the same name <code>uuidv4</code> on another template.
When I'm just using the built-in function in another template, it's generating a new Id but I want the id which is already generated in the pod. How am I doing it?</p>
<p><strong>Note:</strong> The manifests are located in different files, but in the same <code>/templates</code> folder.</p>

Ido Segal
<p>You can't use random values in Helm this way.  Helm doesn't have any kind of global storage, only the end-user configuration in <code>.Values</code> and per-template parameters and return values.  Every time you call <code>uuidv4</code> it will generate a new random UUID.</p>
<p>The more common case of this is trying to generate a random password for a database.  <a href="https://stackoverflow.com/questions/56170052/how-not-to-overwrite-randomly-generated-secrets-in-helm-templates">How not to overwrite randomly generated secrets in Helm templates</a> could be interesting reading, but note how the answers quickly dive into using <code>lookup</code> to only maybe generate a credential, and then adding more workarounds when that doesn't work well either.</p>
<p>The default Helm chart scaffolding comes with helpers to produce names.  It generally assumes that the combination of Helm chart and release names is unique within its namespace, which lets you create &quot;unique enough&quot; Deployment names for example.  Potentially you could use that here</p>
<pre class="lang-yaml prettyprint-override"><code>metadata:
  name: {{ include &quot;mychart.fullname&quot; . }}-test
</code></pre>
<p>If the name really does need to be random, then possibly the best approach is to generate a random value outside of Helm and pass it as a value.</p>
<pre class="lang-yaml prettyprint-override"><code>metadata:
  name: test{{ with .Values.testUuid }}-{{ . }}{{ end }}
</code></pre>
<pre class="lang-bash prettyprint-override"><code>helm install --set-string testUuid=$(uuidgen) ...
</code></pre>
<p>Then within a chart invocation, the <code>.Values.testUuid</code> will be the same value everywhere.  If you upgrade the chart, you can <code>helm upgrade --reuse-values</code> to keep the previous random value.</p>
