2

我正在使用 Argo 工作流程。

在 my 中有一个 DAG 步骤,entrypoint它遵循几个正常的步骤。这些步骤之一执行sys.stdout. 一旦进入 DAG 步骤,我希望某些任务能够引用sys.stdout.

我知道如果我们想参考sys.stdout当工作流从一个步骤进入下一步(没有 DAG)时,我们可以做{{steps.step-name.outputs.result}}. 但是,这在 DAG 任务中不起作用。

如何在 DAG 任务中引用 sys.stdout 以便我可以使用它withParam

编辑:

工作流程如下所示:

  templates:
  - name: the-entrypoint
    steps:
    - - name: step01
        template: first-step
    - - name: step02
        template: second-step
    - - name: step03
        template: third-step
    - - name: step04-the-dag-step
        template: fourth-step

一般来说,如果third-step有 a ,我们可以通过insys.stdout来引用它。但是,在这种情况下是 DAG,如果其中一个 DAG 任务想要使用 ,则在 DAG 任务中作为参数/参数调用会引发错误。{{steps.step03.outputs.result}}fourth-stepfourth-stepsys.stdout{{steps.step03.outputs.result}}

那么问题是如何正确引用内部DAG 任务sys.stdout生成的?third-stepfourth-step

4

1 回答 1

2

关于模板输出的一些背景知识

Argo Workflows 支持多种不同类型的模板

每种类型的模板都支持模板不同类型的引用。

steps模板中,您可以使用steps.step-name.outputs.parameters.param-name(对于命名参数)或steps.step-name.outputs.result(对于 ascriptcontainer模板的标准输出)访问其他步骤的输出参数。

示例(请参阅完整的工作流程):

  - name: output-parameter
    steps:
    - - name: generate-parameter
        template: whalesay
    - - name: consume-parameter
        template: print-message
        arguments:
          parameters:
          - name: message
            value: "{{steps.generate-parameter.outputs.parameters.hello-param}}"

dag模板中,您可以使用类似的语法访问各种任务的输出,只需使用tasks.代替steps..

示例(请参阅完整的工作流程):

    - name: main
      dag:
        tasks:
          - name: flip-coin
            template: flip-coin
          - name: heads
            depends: flip-coin
            template: heads
            when: "{{tasks.flip-coin.outputs.result}} == heads"
          - name: tails
            depends: flip-coin
            template: tails
            when: "{{tasks.flip-coin.outputs.result}} == tails"

在 acontainerscript模板中,您只能访问该模板的输入*。您不能直接从容器或脚本模板的步骤或任务模板访问步骤或任务的输出。

引用 DAG 的步骤输出

如上所述,DAG 模板不能直接引用steps模板的步骤输出。但是steps模板中的步骤可以将步骤输出传递给 DAG 模板

在您的示例中,它看起来像这样:

  templates:
  - name: the-entrypoint
    steps:
    - - name: step01
        template: first-step
    - - name: step02
        template: second-step
    - - name: step03
        template: third-step
    - - name: step04-the-dag-step
        template: fourth-step
        arguments:
          parameters:
          - name: some-param
            value: "{{steps.step03.outputs.result}}"
  - name: fourth-step
    inputs:
      parameters:
      - name: some-param
    dag:
      tasks:
        # use the input parameter in the fourth-step template with "{{inputs.parameters.some-param}}"

tl;博士

steps.tasks.变量旨在在单个步骤或任务模板中引用,但它们可以在模板之间显式传递。如果您需要在 DAG 中使用步骤的输出,请直接将该输出作为调用 DAG 的参数传递。

在您的情况下,DAG 模板作为四个步骤中的最后一个被调用,因此您将在其中传递参数。

* 好的,您还可以从一个或模板中访问各种其他变量,但您无法访问在另一个模板中作为内部变量作用域的变量。scriptcontainer

于 2021-03-06T21:22:50.180 回答