Closed agrawroh closed 2 years ago
Jsonnet is a pure language. We cannot add impure functions that break referential transparency. I found related discussions in https://github.com/google/jsonnet/issues/225 and https://github.com/google/jsonnet/issues/478. The second one mentions k8s descriptors, this may be close to your use case. I think the approach from the first ticket should work for us as well: Compute a hash of the content (or maybe a list index when iterating over a list of elements) based on a seed that is passed in as an extVar. We already have hashing functions in the standard library. You could use this to construct a deterministic UUID from a hash (plus an external seed).
Such a deterministic UUID function could be implemented in Scala but it's probably not worth the effort. If we still want to do it, it should go into a separate namespace, maybe stdext
instead of std
to make clear that it's not part of the official standard library, together with a flag that allows our Sjsonnet-specific extensions to be disabled.
What changes are proposed in this PR?
In this PR we are adding a new standard function to return a random UUID string. This could be used to tag the different k8s resources if they are all being deployed as a list (kind: List). Kubernetes creates a separate UUID for each individual resource even if they are all getting deployed together and we have a use-case where we want to identify everything getting deployed as part of the same list.