argoproj / argoproj/argo-workflows

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

Open
#9,239 1 comment 12 reactions 0 assignees View on GitHub
area/templating
Dominant language
Go
Stars
17k
Forks
3.7k
Avg merge
1d 15h
Merged PRs (30d)
138

Description

# 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:

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

Contributor guide

Open the contributing guide

Research direction

The issue describes workflow-level parameters, a root template, parallel step templates, and Sprig expressions, but names no source files, tests, or entry points. Start by tracing where root-level and step-level parameters are evaluated, then define how an SPRIG_EARLY_EVALUATE switch should preserve one value across child templates. Done means the example workflow produces one consistent schema name when the switch is enabled, with coverage for both enabled and default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
devops
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.