kubernetes-helmargo-workflowsargoproj

How to control Argo(helm) flow with Script output


I have a script defined in Argo WorkflowTemplate as follows. This may either print status:true or status:false (I have simplified this)

- name:util-script
    script:
      image: python3
      command: ["python3"]
      script |
         print(status:true)

Is there a way to control dag flow based on the above script output? I know helm provides flow control like Helm Doc - Flow control

Following is what I tried so far, but this always jumps to else condition. anything Im doing wrong? Appreciate any input on this

{{- if contains "status:true" `tasks.util-script.outputs.result` }}
  # even result is `status:true`, does not reach here
{{ else }}
  # always reach here
{{ end }}

I have verified tasks.util-script.outputs.result indeed returns the expected result.


Solution

  • Helm executes before the workflow runs. That's why you'd end up in the else block.

    1. Your task is not evaluated
    2. When template is rendered,
      `tasks.util-script.outputs.result`
      creates a literal string, which doesn't contain status text

    You need to use a when conditional, as shown in the documentation - https://argo-workflows.readthedocs.io/en/stable/walk-through/conditionals/

    - name: next
      template: next
      when: {{`{{tasks.util-script.outputs.result}}`}} == "status:true"