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 .Values
and per-template parameters and return values. Every time you call uuidv4
it will generate a new random UUID.
The more common case of this is trying to generate a random password for a database. How not to overwrite randomly generated secrets in Helm templates could be interesting reading, but note how the answers quickly dive into using lookup
to only maybe generate a credential, and then adding more workarounds when that doesn't work well either.
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 "unique enough" Deployment names for example. Potentially you could use that here
metadata:
name: {{ include "mychart.fullname" . }}-test
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.
metadata:
name: test{{ with .Values.testUuid }}-{{ . }}{{ end }}
helm install --set-string testUuid=$(uuidgen) ...
Then within a chart invocation, the .Values.testUuid
will be the same value everywhere. If you upgrade the chart, you can helm upgrade --reuse-values
to keep the previous random value.