如何使用 withParam 引用在 DAG 外部创建的 sys.stdout 以在 DAG 内部使用?

TCR*_*TCR 2 kubernetes argoproj argo-workflows

我正在使用 Argo 工作流程。

我的中有一个 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
Run Code Online (Sandbox Code Playgroud)

一般来说,如果third-stepa 存在,我们可以通过insys.stdout引用它。但是,在本例中是一个 DAG,如果其中一个 DAG 任务想要使用,则在 DAG 任务内部作为自变量/参数进行调用会引发错误。{{steps.step03.outputs.result}}fourth-stepfourth-stepsys.stdout{{steps.step03.outputs.result}}

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

Mic*_*haw 5

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

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

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

stepstemplate中,您可以使用steps.step-name.outputs.parameters.param-name(对于命名参数) 或(对于 a或templatesteps.step-name.outputs.result的 stdout ) 访问其他步骤的输出参数。scriptcontainer

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

  - 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}}"
Run Code Online (Sandbox Code Playgroud)

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"
Run Code Online (Sandbox Code Playgroud)

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

引用 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}}"
Run Code Online (Sandbox Code Playgroud)

太长了;博士

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

在您的例子中,DAG 模板是作为四个步骤中的最后一个步骤调用的,因此您将在此处传递参数。

* 好吧,您还可以访问或模板中的各种其他变量,但您无权访问另一个模板中范围为内部变量的变量。scriptcontainer