3

我有如下所述的 Argo DAG 示例。如下所示,我对每个任务的参数值进行了硬编码。每个任务使用不同的参数值。我知道 Argo 提供了一种以 JSON 或 YAML 格式提交参数文件以动态传递参数值的方法。但是,我想知道是否有一种方法可以通过参数文件为下面 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
4

1 回答 1

2

Argo Workflow 规范包括可以定义arguments许多全局参数的位置。

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

(我稍微修改了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
于 2020-10-21T21:56:43.687 回答