argoproj / argoproj/argo-workflows
Combining recursive parameters and expr-lang logic sometimes doesn't work
- 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 issue exists when I tested with `:latest`
- [X] I have searched existing issues and could not find a match for this bug
- [ ] I'd like to contribute the fix myself (see [contributing guide](https://github.com/argoproj/argo-workflows/blob/main/docs/CONTRIBUTING.md))
### What happened/what did you expect to happen?
Trying to use [expressions](https://argo-workflows.readthedocs.io/en/latest/variables/#expression) for comparing numbers from input parameters, this logic seems to work for expressions like `==` but not for `>` for example; this throws:
```
error: cannot finish template replacement because the result was invalid JSON
```
Also, replacing the parameter with a static number shows that the larger than logic works fine as long as we don't use an input parameter.
### Version
Tried on v3.4.8 and v3.5.4
### 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:
name: testwf
spec:
entrypoint: calculate-memory-limit
arguments:
parameters:
- name: number_of_transactions
value: 50000
templates:
- name: calculate-memory-limit
inputs:
parameters:
- name: number_of_transactions
- name: doesntwork
value: "{{= asInt(inputs.parameters.number_of_transactions) > 40000 ? '2222Mi' : '2233Mi' }}"
- name: works1
value: "{{= asInt(inputs.parameters.number_of_transactions) == 40000 ? '2222Mi' : '2233Mi' }}"
- name: works2
value: "{{= 50000 > 40000 ? '2222Mi' : '2233Mi' }}"
script:
image: python:alpine3.6
command: [python]
source: |
print('doesntwork: {{inputs.parameters.doesntwork}}')
print('works1: {{inputs.parameters.works1}}')
print('works2: {{inputs.parameters.works2}}')
```
### Logs from the workflow controller
```text
❯ kubectl logs -n argo-workflows deploy/argo-workflows-workflow-controller | grep testwf
time="2024-02-28T16:31:03.120Z" level=info msg="Processing workflow" Phase= ResourceVersion=53738 namespace=local workflow=testwf
time="2024-02-28T16:31:03.123Z" level=info msg="Task-result reconciliation" namespace=local numObjs=0 workflow=testwf
time="2024-02-28T16:31:03.123Z" level=info msg="Updated phase -> Running" namespace=local workflow=testwf
time="2024-02-28T16:31:03.123Z" level=warning msg="Node was nil, will be initialized as type Skipped" namespace=local workflow=testwf
time="2024-02-28T16:31:03.123Z" level=info msg="was unable to obtain node for , letting display name to be nodeName" namespace=local workflow=testwf
time="2024-02-28T16:31:03.123Z" level=info msg="Pod node testwf initialized Pending" namespace=local workflow=testwf
time="2024-02-28T16:31:03.125Z" level=error msg="Mark error node" error="cannot finish template replacement because the result was invalid JSON" namespace=local nodeName=testwf workflow=testwf
time="2024-02-28T16:31:03.125Z" level=info msg="node testwf phase Pending -> Error" namespace=local workflow=testwf
time="2024-02-28T16:31:03.125Z" level=info msg="node testwf message: cannot finish template replacement because the result was invalid JSON" namespace=local workflow=testwf
time="2024-02-28T16:31:03.125Z" level=info msg="node testwf finished: 2024-02-28 16:31:03.125939505 +0000 UTC" namespace=local workflow=testwf
time="2024-02-28T16:31:03.125Z" level=error msg="error in entry template execution" error="cannot finish template replacement because the result was invalid JSON" namespace=local workflow=testwf
time="2024-02-28T16:31:03.126Z" level=info msg="Updated phase Running -> Error" namespace=local workflow=testwf
time="2024-02-28T16:31:03.126Z" level=info msg="Updated message -> error in entry template execution: cannot finish template replacement because the result was invalid JSON" namespace=local workflow=testwf
time="2024-02-28T16:31:03.126Z" level=info msg="Marking workflow completed" namespace=local workflow=testwf
time="2024-02-28T16:31:03.130Z" level=info msg="Workflow update successful" namespace=local phase=Error resourceVersion=53741 workflow=testwf
time="2024-02-28T16:31:03.131Z" level=info msg="cleaning up pod" action=deletePod key=local/testwf-1340600742-agent/deletePod
```
### Logs from in your workflow's wait container
```text
N/A
```
Contributor guide
Research direction
Start with the supplied workflow reproduction and the workflow controller error, then trace the template replacement and expr-lang evaluation path involved in recursive input parameters. The issue is done when the parameterized greater-than expression produces valid workflow JSON and the reproduction completes without the reported replacement error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, kubernetes
- Domain
- backend, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100