argo-workflows icon indicating copy to clipboard operation
argo-workflows copied to clipboard

Early evaluate sprig functions and set the result as an input parameter

Open carolkao opened this issue 3 years ago • 1 comments

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 👍.

carolkao avatar Jul 27 '22 09:07 carolkao

Hi @sarabala1979, I've read your comment in @9166, would you please help to take a look on this issue? Thank you.

carolkao avatar Aug 04 '22 01:08 carolkao