argoproj / argoproj/argo-workflows

expression `{{= workflow?.outputs?.parameters?.my_param ?? 'na' }}` always return `na`

Open
#11,549 10 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area/templating P2 solution/workaround
Dominant language
Go
Stars
17k
Forks
3.7k
Avg merge
1d 20h
Merged PRs (30d)
138

Description

### Pre-requisites

- [X] I have double-checked my configuration
- [X] I can confirm the issues exists when I tested with `:latest`
- [ ] I'd like to contribute the fix myself (see [contributing guide](https://github.com/argoproj/argo-workflows/blob/master/docs/CONTRIBUTING.md))

### What happened/what you expected to happen?

Running workflow with global output parameter, that is used in metrics label value with expression containing "??" always evaluates as if the parameter value is `nil`. The reason for using the condition is to support step failing, when the outputs are not generated and in that case I want to fallback to `"na"`.

Running the workflow below, after completed, the value of `.spec.metrics` is

```json
{
"prometheus": [
{
"name": "test_metric",
"labels": [
{
"key": "param",
"value": "na"
}
],
"help": "Test metric",
"counter": {
"value": "1"
}
}
]
}
```

Expected value is:
```json
{
"prometheus": [
{
"name": "test_metric",
"labels": [
{
"key": "param",
"value": "hello world"
}
],
"help": "Test metric",
"counter": {
"value": "1"
}
}
]
}
```

To check, the value of `.status.outputs` is correct as expected:

```json
{
"parameters": [
{
"name": "my_global_param",
"value": "hello world"
}
]
}
```

When setting the expression to `"{{= workflow?.outputs?.parameters?.my_global_param }}"` (i.e. removing the safe conditional), the evaluated value in the metric label is correct.

### Version

v3.4.9

### Paste a small workflow that reproduces the issue. We must be able to run the workflow; don't enter a workflows that uses private images.

```YAML
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: global-outputs-
spec:
entrypoint: generate-globals
serviceAccountName: argo

templates:
- name: generate-globals
steps:
- - name: generate
template: global-output
- name: global-output
container:
image: alpine:3.7
command: [sh, -c]
args: ["sleep 1; echo -n hello world > /tmp/hello_world.txt"]
outputs:
parameters:
- name: hello-param
valueFrom:
path: /tmp/hello_world.txt
globalName: my_global_param

metrics:
prometheus:
- name: test_metric
help: Test metric
counter:
value: "1"
labels:
- key: param
value: "{{= workflow?.outputs?.parameters?.my_global_param ?? 'na' }}"
```

### Logs from the workflow controller

```text
time="2023-08-09T12:00:14.976Z" level=info msg="Processing workflow" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:14.984Z" level=info msg="Updated phase -> Running" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:14.987Z" level=info msg="Steps node global-outputs-llzsn initialized Running" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:14.987Z" level=info msg="StepGroup node global-outputs-llzsn-482890107 initialized Running" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:14.993Z" level=info msg="Pod node global-outputs-llzsn-2540520120 initialized Pending" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:15.025Z" level=info msg="Created pod: global-outputs-llzsn[0].generate (global-outputs-llzsn-global-output-2540520120)" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:15.026Z" level=info msg="Workflow step group node global-outputs-llzsn-482890107 not yet completed" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:15.026Z" level=info msg="TaskSet Reconciliation" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:15.026Z" level=info msg=reconcileAgentPod namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:15.042Z" level=info msg="Workflow update successful" namespace=argo phase=Running resourceVersion=1328 workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.030Z" level=info msg="Processing workflow" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.031Z" level=info msg="Task-result reconciliation" namespace=argo numObjs=0 workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.035Z" level=warning msg="workflow uses legacy/insecure pod patch, see https://argoproj.github.io/argo-workflows/workflow-rbac/" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.037Z" level=info msg="node changed" namespace=argo new.message= new.phase=Succeeded new.progress=0/1 nodeID=global-outputs-llzsn-2540520120 old.message= old.phase=Pending old.progress=0/1 workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.037Z" level=info msg="setting workflow.outputs.parameters.my_global_param: 'hello world'" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.039Z" level=info msg="Step group node global-outputs-llzsn-482890107 successful" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="node global-outputs-llzsn-482890107 phase Running -> Succeeded" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="node global-outputs-llzsn-482890107 finished: 2023-08-09 12:00:25.040122772 +0000 UTC" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="Outbound nodes of global-outputs-llzsn-2540520120 is [global-outputs-llzsn-2540520120]" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="Outbound nodes of global-outputs-llzsn is [global-outputs-llzsn-2540520120]" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="node global-outputs-llzsn phase Running -> Succeeded" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="node global-outputs-llzsn finished: 2023-08-09 12:00:25.040335284 +0000 UTC" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="Checking daemoned children of global-outputs-llzsn" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="TaskSet Reconciliation" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg=reconcileAgentPod namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="Updated phase Running -> Succeeded" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="Marking workflow completed" namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.040Z" level=info msg="Checking daemoned children of " namespace=argo workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.046Z" level=info msg="cleaning up pod" action=deletePod key=argo/global-outputs-llzsn-1340600742-agent/deletePod
time="2023-08-09T12:00:25.056Z" level=info msg="Workflow update successful" namespace=argo phase=Succeeded resourceVersion=1366 workflow=global-outputs-llzsn
time="2023-08-09T12:00:25.068Z" level=info msg="cleaning up pod" action=labelPodCompleted key=argo/global-outputs-llzsn-global-output-2540520120/labelPodCompleted
```

### Logs from in your workflow's wait container

```text
time="2023-08-09T12:00:20.879Z" level=info msg="No Script output reference in workflow. Capturing script output ignored"
time="2023-08-09T12:00:20.879Z" level=info msg="Saving output parameters"
time="2023-08-09T12:00:20.879Z" level=info msg="Saving path output parameter: hello-param"
time="2023-08-09T12:00:20.879Z" level=info msg="Copying /tmp/hello_world.txt from base image layer"
time="2023-08-09T12:00:20.879Z" level=info msg="Successfully saved output parameter: hello-param"
time="2023-08-09T12:00:20.879Z" level=info msg="No output artifacts"
time="2023-08-09T12:00:20.898Z" level=warning msg="failed to patch task set, falling back to legacy/insecure pod patch, see https://argoproj.github.io/argo-workflows/workflow-rbac/" error="workflowtaskresults.argoproj.io is forbidden: User \"system:serviceaccount:argo:argo\" cannot create resource \"workflowtaskresults\" in API group \"argoproj.io\" in the namespace \"argo\""
time="2023-08-09T12:00:20.919Z" level=info msg="Alloc=8343 TotalAlloc=16613 Sys=28797 NumGC=5 Goroutines=8"
time="2023-08-09T12:00:20.919Z" level=info msg="Deadline monitor stopped"
time="2023-08-09T12:00:20.919Z" level=info msg="stopping progress monitor (context done)" error="context canceled"
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided workflow on v3.4.9 and tracing expression evaluation for the metrics label using workflow.outputs.parameters. Compare the `??` expression with the expression without the fallback; done means the label resolves to `hello world` when the global output exists and still falls back to `na` when it does not.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.