0

I have a template which I'm generating a name using uuidv4 built-in function:

apiVersion: k6.io/v1alpha1
kind: pod
metadata:
  name: test-{{ uuidv4 }}
  namespace: {{ .Release.Namespace }}

Then, I want to use the same name uuidv4 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?

Note: The manifests are located in different files, but in the same /templates folder.

user16217248
  • 3,119
  • 19
  • 19
  • 37
Ido Segal
  • 430
  • 2
  • 7
  • 20

1 Answers1

1

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.

David Maze
  • 130,717
  • 29
  • 175
  • 215