Search code examples
jsonloopsargo-workflowsmultilinestring

how to pass a multi line json string in map in argo workflows


I am working on creating a argo workflow with a loop withParam for map variable. In this map I want to use multi line json string. Is there any way to use it?

Here is the way am using policy as multi line string but it is not working

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: loops-param-arg-
spec:
  entrypoint: loop-param-arg-example
  arguments:
    parameters:
    - name: os-list
      value: |
        [
          { "image": "debian", "tag": "9.1", "policy": "{
              "Version": "2012-10-17",
              "Statement": [
                  {
                      "Sid": "BucketAdmin",
                      "Effect": "Allow",
                      "Principal": "*",
                      "Action": "s3:*",
                      "Resource": "*"
                  }
              ]
          }" },
          { "image": "ubuntu", "tag": "17.10", "policy":  "{
              "Version": "2012-10-17",
              "Statement": [
                  {
                      "Sid": "BucketAdmin",
                      "Effect": "Allow",
                      "Principal": "*",
                      "Action": "s3:*",
                      "Resource": "*"
                  }
              ]
          }"}
        ]
  templates:
  - name: loop-param-arg-example
    inputs:
      parameters:
      - name: os-list
    steps:
    - - name: test-linux
        template: cat-os-release
        arguments:
          parameters:
          - name: image
            value: "{{item.image}}"
          - name: tag
            value: "{{item.tag}}"
        withParam: "{{inputs.parameters.os-list}}"

  - name: cat-os-release
    inputs:
      parameters:
      - name: image
      - name: tag
    container:
      image: "{{inputs.parameters.image}}:{{inputs.parameters.tag}} and policy is {{inputs.parameters.policy}}"
      command: [cat]
      args: [/etc/os-release]

Is there any way in argo workflows to achieve this? if not, what's the alternate way to do this?


Solution

  • The solutions provided by Michael works and also the below solution works for you with some readability of the policy

    kind: Workflow
    metadata:
      generateName: loops-param-arg-
    spec:
      entrypoint: loop-param-arg-example
      arguments:
        parameters:
        - name: os-list
          value: |
            [
              { "image": "debian", "tag": "9.1", "policy": {
                                                              "Version": "2012-10-17",
                                                              "Statement": [
                                                                  {
                                                                      "Sid": "BucketAdmin",
                                                                      "Effect": "Allow",
                                                                      "Principal": "*",
                                                                      "Action": "s3:*",
                                                                      "Resource": "*"
                                                                  }
                                                              ]
                                                          } },
              { "image": "ubuntu", "tag": "17.10", "policy":  {
                                                                "Version": "2012-10-17",
                                                                "Statement": [
                                                                    {
                                                                        "Sid": "BucketAdmin",
                                                                        "Effect": "Allow",
                                                                        "Principal": "*",
                                                                        "Action": "s3:*",
                                                                        "Resource": "*"
                                                                    }
                                                                ]
                                                            }
              }
            ]
      templates:
      - name: loop-param-arg-example
        inputs:
          parameters:
          - name: os-list
        steps:
        - - name: test-linux
            template: cat-os-release
            arguments:
              parameters:
              - name: image
                value: "{{item.image}}"
              - name: tag
                value: "{{item.tag}}"
            withParam: "{{inputs.parameters.os-list}}"
    
      - name: cat-os-release
        inputs:
          parameters:
          - name: image
          - name: tag
        container:
          image: "{{inputs.parameters.image}}:{{inputs.parameters.tag}} and policy is {{inputs.parameters.policy}}"
          command: [cat]
          args: [/etc/os-release]