5

In an Argo workflow, I have a loop and I need to continue running the loop in case the output of a previous step has NOT been supplied yet. Until now, I couldn't find any way of performing this simple empty/null check. The following "when" expression:

when: "'{{steps.wait-completion.outputs.parameters.result}}' == ''"

never evaluates as expected because Argo returns the tag name as it is (without being substituted) if the value has not been supplied and then I get:

'{{steps.wait-completion.outputs.parameters.result}}' == ''' evaluated false

Is this a bug or a feature? Any ideas how I can perform such a check from the "when" expression? I also tried using the "default" tag to set a default but it seems to be ignored by the suspend step (another bug or another feature?)

I would really appreciate some ideas here. Thanks in advance!

What I tried:

when: "'{{steps.wait-completion.outputs.parameters.result}}' == ''"

What I expected:

When expression above evaluates to true if the output parameter "result" has not been supplied yet.

What I got:

'{{steps.wait-completion.outputs.parameters.result}}' == ''' evaluated false

Samir Wafa
  • 76
  • 4

1 Answers1

1

Here's a simple example to demonstrate checking for empty parameters in a when clause, and also within a ternary expression.

Obviously the "blank" value is never displayed in whalesay, because of the when clause, but I wanted to show how it can be done, since it has caused me grief in the past.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  generateName: example-
  namespace: <your_namespace>
spec:
  entrypoint: main
  serviceAccountName: <your_service_account>
  arguments:
    parameters:
      - name: name
        default: ""


  templates:
    - name: main
      inputs:
        parameters:
          - name: name
      steps:
        - - name: say
            arguments:
              parameters:
                - name: name
                  value: "{{inputs.parameters.name}}"
            template: whalesay
            when: >-
              {{= workflow.parameters.name != "" }}

    - name: whalesay
      inputs:
        parameters:
          - name: "name"
      container:
        image: docker/whalesay
        command: [cowsay]
        args:
          - >-
            {{= inputs.parameters.name == "" ? "blank" : inputs.parameters.name }}
bn0
  • 71
  • 5