argo中循环任务的输出是什么?

jos*_*ose 7 kubernetes argoproj argo-workflows

根据Argo DAG 模板文档

\n
\n

tasks.<TASKNAME>.outputs.parameters: 当上一个任务使用\n\'withItems\' 或 \'withParams\' 时,这包含每个调用的输出\n参数映射的 JSON 数组

\n
\n

当尝试使用以下简单的工作流程时:

\n
apiVersion: argoproj.io/v1alpha1\nkind: Workflow\nmetadata:\n  generateName: test-workflow-\nspec:\n  entrypoint: start\n  templates:\n  - name: start\n    dag:\n      tasks:\n        - name: with-items\n          template: hello-letter\n          arguments:\n            parameters:\n            - name: input-letter\n              value: "{{item}}"\n          withItems:\n          - A\n          - B\n          - C\n        - name: show-result\n          dependencies:\n          - with-items\n          template: echo-result\n          arguments:\n            parameters:\n            - name: input\n              value: "{{tasks.with-items.outputs.parameters}}"\n\n  - name: hello-letter\n    inputs:\n      parameters:\n      - name: input-letter\n    outputs:\n      parameters:\n      - name: output-letter\n        value: "{{inputs.parameters.input-letter}}"\n    script:\n      image: alpine\n      command: ["sh"]\n      source: |\n        echo "{{inputs.parameters.input-letter}}"\n\n  - name: echo-result\n    inputs:\n      parameters:\n      - name: input\n    outputs:\n      parameters:\n      - name: output\n        value: "{{inputs.parameters.input}}"\n    script:\n      image: alpine\n      command: ["sh"]\n      source: |\n        echo {{inputs.parameters.input}}\n
Run Code Online (Sandbox Code Playgroud)\n

我收到以下错误:\nFailed to submit workflow: templates.start.tasks.show-result failed to resolve {{tasks.with-items.outputs.parameters}}

\n

Argo 版本(在 minikube 集群中运行)

\n
argo: v2.10.0+195c6d8.dirty\n  BuildDate: 2020-08-18T23:06:32Z\n  GitCommit: 195c6d8310a70b07043b9df5c988d5a62dafe00d\n  GitTreeState: dirty\n  GitTag: v2.10.0\n  GoVersion: go1.13.4\n  Compiler: gc\n  Platform: darwin/amd64\n
Run Code Online (Sandbox Code Playgroud)\n

在 Argo 2.8.1 中出现同样的错误,尽管在显示结果任务中使用.result而不是工作正常(结果是),但在 2.10 中不再工作.parameters[A,B,C]

\n
        - name: show-result\n          dependencies:\n          - with-items\n          template: echo-result\n          arguments:\n            parameters:\n            - name: input\n              value: "{{tasks.with-items.outputs.result}}"\n
Run Code Online (Sandbox Code Playgroud)\n

结果:

\n
STEP                                TEMPLATE      PODNAME                                     DURATION  MESSAGE\n \xe2\x9a\xa0 test-workflow-parallelism-xngg4  start                                                                                                                     \n \xe2\x94\x9c-\xe2\x9c\x94 with-items(0:A)                hello-letter  test-workflow-parallelism-xngg4-3307649634  6s                                                              \n \xe2\x94\x9c-\xe2\x9c\x94 with-items(1:B)                hello-letter  test-workflow-parallelism-xngg4-768315880   7s                                                              \n \xe2\x94\x9c-\xe2\x9c\x94 with-items(2:C)                hello-letter  test-workflow-parallelism-xngg4-2631126026  9s                                                              \n \xe2\x94\x94-\xe2\x9a\xa0 show-result                    echo-result                                                         invalid character \'A\' looking for beginning of value\n
Run Code Online (Sandbox Code Playgroud)\n

我还尝试将显示结果任务更改为:

\n
        - name: show-result\n          dependencies:\n          - with-items\n          template: echo-result\n          arguments:\n            parameters:\n            - name: input\n              value: "{{tasks.with-items.outputs.parameters.output-letter}}"\n
Run Code Online (Sandbox Code Playgroud)\n

执行没有错误:

\n
STEP                                TEMPLATE      PODNAME                                     DURATION  MESSAGE\n \xe2\x9c\x94 test-workflow-parallelism-qvp72  start                                                                 \n \xe2\x94\x9c-\xe2\x9c\x94 with-items(0:A)                hello-letter  test-workflow-parallelism-qvp72-4221274474  8s          \n \xe2\x94\x9c-\xe2\x9c\x94 with-items(1:B)                hello-letter  test-workflow-parallelism-qvp72-112866000   9s          \n \xe2\x94\x9c-\xe2\x9c\x94 with-items(2:C)                hello-letter  test-workflow-parallelism-qvp72-1975676146  6s          \n \xe2\x94\x94-\xe2\x9c\x94 show-result                    echo-result   test-workflow-parallelism-qvp72-3460867848  3s \n
Run Code Online (Sandbox Code Playgroud)\n

但参数不被值替换:

\n
argo logs test-workflow-parallelism-qvp72\ntest-workflow-parallelism-qvp72-1975676146: 2020-08-25T14:52:50.622496755Z C\ntest-workflow-parallelism-qvp72-4221274474: 2020-08-25T14:52:52.228602517Z A\ntest-workflow-parallelism-qvp72-112866000: 2020-08-25T14:52:53.664320195Z B\ntest-workflow-parallelism-qvp72-3460867848: 2020-08-25T14:52:59.628892135Z {{tasks.with-items.outputs.parameters.output-letter}}\n
Run Code Online (Sandbox Code Playgroud)\n

我不明白循环的输出会是什么!我错过了什么?有没有办法找出发生了什么?

\n

Tom*_*ert 0

这是我遇到过的一个相当常见的问题,到目前为止,我还没有在任何错误报告或功能文档中遇到过这个问题,因此尚未确定这是一个功能还是错误。然而 argo 显然无法执行“map-reduce”流程 OOB。

我发现的唯一“真正”的解决方法是附加一个工件,将任务with-items输出写入其中,并将其传递到下一步,您将通过读取来自的值在代码/脚本中自行“减少”人工制品。

- - 编辑 - - -

正如另一个答案所提到的,这确实是最新版本已解决的错误parameters,这解决了您提到的选项的用法,但outputs.result在错误修复后仍然会导致错误。