forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: aggregate JSON output parameters correctly
Fixes argoproj#13510 `outputs.result` of a `withItems`/`withParams` will be conditionally `json.Unmarshal`ed. Other output parameters are always json.Unmarshalled, which leads to inconsitency and a complete inability to pass JSON out of withItems outputs straight back in as `withItems` Conditionally unmarshal the outputs.params * avoiding it if the parameter isn't enclosed in `{` or `[`, primarily to avoid bare numbers as they're valid JSON but need quoting here * falling back to old behaviour if this fails Additional e2e test tests the example case. Signed-off-by: Alan Clucas <alan@clucas.org>
- Loading branch information
Showing
3 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Workflow | ||
metadata: | ||
generateName: double-fan-out-using-param- | ||
spec: | ||
entrypoint: main-dag | ||
templates: | ||
- inputs: | ||
parameters: | ||
- name: param1 | ||
name: operation | ||
outputs: | ||
parameters: | ||
- name: output1 | ||
valueFrom: | ||
path: /tmp/fan_out.json | ||
script: | ||
command: | ||
- python3 | ||
image: python:3.11 | ||
source: |- | ||
import os | ||
import sys | ||
sys.path.append(os.getcwd()) | ||
import json | ||
try: param1 = json.loads(r'''{{inputs.parameters.param1}}''') | ||
except: param1 = r'''{{inputs.parameters.param1}}''' | ||
with open('/tmp/fan_out.json', 'w') as f: | ||
json.dump(param1, f) | ||
print(json.dumps(param1)) | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: param1 | ||
value: '{{item}}' | ||
name: task3 | ||
template: operation | ||
withParam: '{{inputs.parameters.param1}}' | ||
inputs: | ||
parameters: | ||
- name: param1 | ||
name: secondary-dag | ||
- dag: | ||
tasks: | ||
- arguments: | ||
parameters: | ||
- name: param1 | ||
value: '[[{"key1": "value1"}, {"key2": "value2"}, {"key3": "value3"}], [{"key4": "value4"}, {"key5": "value5"}]]' | ||
name: task1 | ||
template: operation | ||
- arguments: | ||
parameters: | ||
- name: param1 | ||
value: '{{item}}' | ||
depends: task1 | ||
name: task2 | ||
template: operation | ||
withParam: '{{tasks.task1.outputs.parameters.output1}}' | ||
- arguments: | ||
parameters: | ||
- name: param1 | ||
value: '{{item}}' | ||
depends: task2 | ||
name: task3-dag | ||
template: secondary-dag | ||
withParam: '{{tasks.task2.outputs.parameters.output1}}' | ||
name: main-dag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters