user18354658
user18354658

Reputation: 75

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
.

My question is how to use every element of this list {{input.parameters.?}} ? Help me with some reference. Thank you

Upvotes: 5

Views: 7254

Answers (1)

Tom Slabbaert
Tom Slabbaert

Reputation: 22316

You didn't really specify what exactly you want to do with these values so i'll explain both ways to use this input.

  1. The more common usage with arrays is to iterate over them using "withParam", With this syntax a new task (pod) will be created for each of the items.
  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}}")

Argo with param

The other option is just to pass the entire array as a variable to the pod, and use custom logic based on needs:

  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

Upvotes: 3

Related Questions