Argo workflows expression tester
Argo has a complex expression language to modify parameters in its workflows
It is difficult for a go novices to figure out how these work and what functions can be used.
This CLI provides a way to test the expressions before submitting the workflow to argo, it dumps failure information
Installation
go install github.com/blacha/argo-expr@latest
Usage
Add 1 to a number
$ argo-expr "{{=asInt(inputs.parameters.name) + 1}}" --value inputs.parameters.name="1"
2
Create a sha256sum
$ argo-expr '{{=sprig.sha256sum("hello world")}}'
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
$ argo-expr '{{=sprig.sha256sum(inputs.parameters.value)}}' --value inputs.parameters.value="hello world"
b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
load from file
Read a JSON input file and compute the output
{
"template": "hello world 1+1:{{= 1+1 }} i:{{= inputs.parameters.number }}",
"values": {
"inputs.parameters.number": "4"
}
}
$ argo-expr --from-file ./input.json
hello world 1+1:2 i:4
Both values and the expression from the file can be overridden with --value
or expression.
$ argo-expr --from-file ./input.json --value inputs.parameters.number=1
hello world 1+1:2 i:2
Override input expression
$ argo-expr --from-file ./input.json "i:{{=asInt(inputs.parameters.number)+3}}"
i:7
Error logs
When a template fails to run a somewhat helpful error message is displayed
$ argo-expr "{{=asInt('hello')}}"
failed to evaluate expression: strconv.ParseInt: parsing "hello": invalid syntax (1:1)
| asInt('hello')
| ^