如何为 Argo Workflow DAG 中的每个步骤传递不同的参数值

How to pass different value of parameters for each Step in Argo Workflow DAG

我有下面提到的示例 Argo DAG。如下所示,我已经对每个任务的参数值进行了硬编码。每个任务使用不同的参数值。我知道 Argo 提供了一种以 JSON 或 YAML 格式提交参数文件以动态传递参数值的方法。但是,我想知道是否有办法通过 parameter file.

为下面的 DAG 中的每个任务传递不同的值
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: dag-diamond-custom-
spec:
  entrypoint: diamond
  templates:
  - name: echo
    retryStrategy:
      limit: 3
    inputs:
      parameters:
      - name: message
      - name: task
    container:
      image: index_ruby:latest
      imagePullPolicy: Never
      command: [ruby, "index.rb", "-s" , "{{inputs.parameters.task}}" , "-r", "{{inputs.parameters.message}}"]
  - name: diamond
    dag:
      tasks:
      - name: A
        template: echo
        arguments:
          parameters: 
            - name: message
              value: |
                {"key": "valueA"}
            - name: task
              value: A
      - name: B
        dependencies: [A]
        template: echo
        arguments:
          parameters: 
            - name: message
              value: |
                {"key": "valueB"}
            - name: task
              value: B
      - name: C
        dependencies: [A]
        template: echo
        arguments:
          parameters: 
            - name: message
              value: |
                {"key": "valueC"}
            - name: task
              value: C
      - name: D
        dependencies: [B, C]
        template: echo
        arguments:
          parameters: 
            - name: message
              value: |
                {"key": "valueD"}
            - name: task
              value: D

Argo Workflow 规范包括 arguments,其中可以定义多个 global parameters

您可以为每个任务定义一个参数,然后通过模板访问它。

(我稍微修改了 echo 容器,因为我在使用 Ruby 图像时遇到了问题。)

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: dag-diamond-custom-
spec:
  entrypoint: diamond
  arguments:
    parameters:
    - name: valueA
    - name: valueB
    - name: valueC
    - name: valueD
  templates:
  - name: echo
    retryStrategy:
      limit: 3
    inputs:
      parameters:
      - name: message
      - name: task
    container:
      image: docker/whalesay:latest
      command: [echo]
      args: ["{{inputs.parameters.task}}", "{{inputs.parameters.message}}"]
  - name: diamond
    dag:
      tasks:
      - name: A
        template: echo
        arguments:
          parameters: 
            - name: message
              value: |
                {"key": "{{workflow.parameters.valueA}}"}
            - name: task
              value: A
      - name: B
        dependencies: [A]
        template: echo
        arguments:
          parameters: 
            - name: message
              value: |
                {"key": "{{workflow.parameters.valueB}}"}
            - name: task
              value: B
      - name: C
        dependencies: [A]
        template: echo
        arguments:
          parameters: 
            - name: message
              value: |
                {"key": "{{workflow.parameters.valueC}}"}
            - name: task
              value: C
      - name: D
        dependencies: [B, C]
        template: echo
        arguments:
          parameters: 
            - name: message
              value: |
                {"key": "{{workflow.parameters.valueD}}"}
            - name: task
              value: D

如您所述,您可以创建一个 JSON 参数文件...

{
  "valueA": 1,
  "valueB": 2,
  "valueC": 3,
  "valueD": 4
}

...然后通过argo submit.

从文件传递参数
argo submit workflow.yaml -f params.json --watch