Early evaluate sprig functions and set the result as an input parameter
Summary
Hi, our teams encounter the same issue with #9166. When we pass a parameters with sprig function such as name-{{=sprig.randAlphaNum(5)}} to a step base template which execute two parallel templates, the sprig-function will be re-evaluated during the two templates run time and the result SOMETIMES are inconsistent.
I'd like to know if it's possible to have a feature switch, e.g. an environment variable 'SPRIG_EARLY_EVALUATE', when we set it true, then the sprig function can be evaluated only once when passing it to the root level template.
Use Cases
We have a template to prepare DB schema with inputed schema name which is randomly created. The name will be used by several leaf steps to prepare schema, and do some processing. For examples:
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: prepare-db-schema-
spec:
entrypoint: prepare-db-schema
templates:
- name: prepare-db-schema
inputs:
parameters:
- name: schema
outputs:
parameters:
- name: schema
valueFrom:
parameter: steps.print-schema.outputs.result
steps:
- - name: execute-sql
arguments:
arguments:
parameters:
- name: script
value: 'echo "prepare schema : {{inputs.parameters.schema}}"'
template: execute-script
- name: print-schema
arguments:
parameters:
- name: script
value: 'echo "{{inputs.parameters.schema}}"'
template: execute-script
- name: execute-script
inputs:
parameters:
- name: script
script:
image: 'debian:9.4'
command: [ 'bash' ]
source: '{{inputs.parameters.script}}'
arguments:
parameters:
- name: schema
value: "myschema_{{=sprig.lower(sprig.randAlphaNum(6))}}"
To make sure the consistency of the schema name, I'll turn the flag on in our system.
Message from the maintainers:
Love this enhancement proposal? Give it a 👍. We prioritise the proposals with the most 👍.
Hi @sarabala1979, I've read your comment in @9166, would you please help to take a look on this issue? Thank you.