<p>There's a <a href="https://stackoverflow.com/questions/66143201/reuse-uuid-in-helm-charts">similar</a> question that alludes to the possibility of auto-generating a uuid in helm charts when used as a secret or configmap. I'm trying precisely to do that, but I'm getting a new uuid each time.</p>
<p>My test case:</p>
<pre><code>---
{{- $config := (lookup &quot;v1&quot; &quot;ConfigMap&quot; .Release.Namespace &quot;{{ .Release.Name }}-testcase&quot;) -}}
apiVersion: v1
kind: ConfigMap
metadata:
  name: &quot;{{ .Release.Name }}-testcase&quot;
  namespace: &quot;{{ .Release.Namespace }}&quot;
  labels:
    app.kubernetes.io/managed-by: &quot;{{ .Release.Service }}&quot;
    app.kubernetes.io/instance: &quot;{{ .Release.Name }}&quot;
    app.kubernetes.io/version: &quot;{{ .Chart.AppVersion }}&quot;
    helm.sh/chart: &quot;{{ .Chart.Name }}-{{ .Chart.Version }}&quot;
data:
{{- if $config }}
  TEST_VALUE: {{ $config.data.TEST_VALUE | quote }}
{{- else }}
  TEST_VALUE: {{ uuidv4 | quote }}
{{ end }}
</code></pre>
<p>I initially deploy this with:</p>
<pre><code>helm upgrade --install --namespace test mytest .
</code></pre>
<p>If I run it again, or run with <code>helm diff upgrade --namespace test mytest .</code> I get a new value for <code>TEST_VALUE</code>. When I dump the contents of <code>$config</code> it's an empty map <code>{}</code>.</p>
<p>I'm using Helm v3.9.0, kubectl 1.24, and kube server is 1.22.</p>
<p>NOTE: I couldn't ask in a comment thread on the other post because I don't have enough reputation.</p>

dcode
<p>Refering to my issue where you enclosed your stack overflow post : <a href="https://github.com/helm/helm/issues/11187" rel="nofollow noreferrer">https://github.com/helm/helm/issues/11187</a></p>
<p>A way to make your configmap work is to save as a variable before conditionnaly set your value. This means every time you upgrade, you'll generate a UUID which will normally will not be used, but this is not dramatic.
When assigning an existing value, := should become =.
Also don't forget to b64enc your value in your manifest</p>
<pre><code>{{- $config := uuidv4 | b64enc | quote -}}
{{- $config_lookup := (lookup &quot;v1&quot; &quot;ConfigMap&quot; .Release.Namespace &quot;{{ .Release.Name }}-testcase&quot;) -}}
{{- if $config_lookup -}}
{{- $config = $config_lookup.data.TEST_VALUE -}}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: &quot;{{ .Release.Name }}-testcase&quot;
  namespace: &quot;{{ .Release.Namespace }}&quot;
  labels:
    app.kubernetes.io/managed-by: &quot;{{ .Release.Service }}&quot;
    app.kubernetes.io/instance: &quot;{{ .Release.Name }}&quot;
    app.kubernetes.io/version: &quot;{{ .Chart.AppVersion }}&quot;
    helm.sh/chart: &quot;{{ .Chart.Name }}-{{ .Chart.Version }}&quot;
data:
  TEST_VALUE: {{ $config | quote }}
</code></pre>
