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

2024-06-19

我正在使用 Argo 工作流程。

我的中有一个 DAG 步骤entrypoint这遵循几个正常步骤。其中一个步骤执行sys.stdout。进入 DAG 步骤后,我希望某些任务引用 DAG 步骤的结果sys.stdout.

我知道我们是否想参考sys.stdout当工作流程从一个步骤转到下一步时(没有 DAG),我们可以这样做{{steps.step-name.outputs.result}}。不过,这在 DAG 任务内部不起作用。

如何在 DAG 任务中引用 sys.stdout 以便将其与withParam?

Edit:

工作流程如下所示:

  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 does a sys.stdout,我们可以通过以下方式引用它{{steps.step03.outputs.result}} in fourth-step。然而,在这种情况下fourth-step是一个 DAG,如果 DAG 任务之一想要使用sys.stdout, 呼叫{{steps.step03.outputs.result}}作为 DAG 任务内部的参数/参数会引发错误。

那么问题是如何正确引用sys.stdout产生于third-step inside fourth-stepDAG 任务?


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

Argo Workflows 支持多种不同的模板类型 https://github.com/argoproj/argo-workflows/blob/master/docs/workflow-concepts.md#template-types.

每种类型的模板支持不同类型的引用在模板内.

在一个steps模板,您可以使用以下命令访问其他步骤的输出参数steps.step-name.outputs.parameters.param-name(对于命名参数)或steps.step-name.outputs.result(对于 a 的标准输出script or container模板)。

例子 (查看完整的工作流程 https://github.com/argoproj/argo-workflows/blob/master/examples/output-parameter.yaml):

  - 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..

例子 (查看完整的工作流程 https://github.com/argoproj/argo-workflows/blob/master/examples/dag-conditional-parameters.yaml):

    - 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"

在一个container or script模板,您可以访问仅该模板的输入*。您不能直接从容器或脚本模板访问步骤或任务模板的步骤或任务的输出。

引用 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;dr

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

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

* Okay, you also have access to various other variables https://github.com/argoproj/argo-workflows/blob/master/docs/variables.md from within a script or container template, but you don't have access to variables that are scoped as internal variables within another template.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

随机推荐