如何从 argo 工作流传递参数列表并在 argo 工作流模板中使用它

How to pass list of arguments from argo workflow and use it in argo workflowtemplate

apiVersion: argoproj.io/v1alpha1
kind: Workflow
.
.
  - name: mytemplate
    steps:
    - - name: mytask
        templateRef:
          name: ABCDworkflowtemplate
          template: taskA
        arguments:
          parameters:
            - name: mylist
              value: [10,"some",false]  
....................
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: ABCDworkflowtemplate
 
spec:
  templates:
    - name: taskA
      inputs:
        parameters:
          - name: mylist
.

我的问题是如何使用此列表的每个元素 {{input.parameters.?}}?帮我参考一下。谢谢

您并没有具体说明您想对这些值做什么,所以我将解释使用此输入的两种方式。

  1. 数组更常见的用法是使用“withParam”对其进行迭代,使用此语法将为每个项目创建一个新任务 (pod)。
  templates:
    - name: taskA
      inputs:
        parameters:
          - name: mylist
      steps:
        - - name: doSomeWithItem
            template: doSomeWithItem
            arguments:
              parameters:
                - name: item
                  value: "{{item}}"
            withParam: "{{inputs.parameters.mylist}}"

    - name: doSomeWithItem
      inputs:
        parameters:
          - name: item
      container:
        image: python:alpine3.6
        command: [ python ]
        source: |
          print("{{inputs.parameters.item}}")

另一种选择是将整个数组作为变量传递给 pod,并根据需要使用自定义逻辑:

  templates:
    - name: taskA
      inputs:
        parameters:
          - name: mylist
      steps:
        - - name: doSomethingWithList
            template: doSomethingWithList
            arguments:
              parameters:
                - name: list
                  value: "{{inputs.parameters.mylist}}"

    - name: doSomethingWithList
      inputs:
        parameters:
          - name: list
      container:
        image: python:alpine3.6
        command: [ python ]
        source: |
          if (list[2] == 'some'):
            // do somehting
          else if (list[0] == 10]:
            // do something