kubernetesargo-workflows

Conditional Argo Workflow Execution


i have a simple workflow with dag, it runs the first job and depending on the output of that job, it will run either one or both of the following jobs named optional-job-one or optional-job-two. here is the part of my yaml file that does this:

workflowSpec:
  serviceAccountName: "{{ .Values.serviceAccountName }}"
  entrypoint: mother
  templates:
    - name: mother
      dag:
        tasks:
          - name: main-job
            template: main-job-step

          - name: optional-job-one
            dependencies: [main-job]
            when: "{{`{{tasks.main-job.outputs.parameters.command}} == OPTION1 || {{tasks.main-job.outputs.parameters.command}} == BothOptions`}}"
            templateRef:
              name: master-templater
              template: option-one-template
            arguments:
              parameters:
                - name: argument-one
                  value: "{{`{{tasks.main-job.outputs.parameters.argument-one}}`}}"
                - name: argument-two
                  value: "{{`{{tasks.main-job.outputs.parameters.argument-two}}`}}"

          - name: optional-job-two
            dependencies: [main-job]
            when: "{{`{{tasks.main-job.outputs.parameters.command}} == OPTION2 || {{tasks.main-job.outputs.parameters.command}} == BothOptions`}}"
            templateRef:
              name: master-templater
              template: option-two-template
            arguments:
              parameters:
                - name: argument-one
                  value: "{{`{{tasks.main-job.outputs.parameters.argument-one}}`}}"
                - name: argument-two
                  value: "{{`{{tasks.main-job.outputs.parameters.argument-two}}`}}"

Now, i want to add a new step. This new step will run if either one or both of the optional-job-one or optional-job-two have ran and finished successfully. how do i do it? i asked the AI chatbots for help and i got this but it doesnt work and im lost (im super new to k8 and argo)!

- name: optional-job-three
  when: "{{tasks.optional-job-one.status}} == Succeeded || {{tasks.optional-job-two.status}} == Succeeded"
  continueOn:
    failed: false
    error: false
  templateRef:
    name: master-templater
    template: option-three-template
  arguments:
    parameters:
      - name: argument-one
        value: "{{`{{tasks.scraper.outputs.parameters.argument-one}}`}}"

Thank you in advance for your help!


Solution

  • Thanks to the previous response i came across this solution that works perfectly, its a bit ugly but it does the job:

    - name: optional-job-three
      depends: "(optional-job-one.Succeeded && optional-job-two.Skipped) || (optional-job-one.Skipped && optional-job-two.Succeeded) || (optional-job-one.Succeeded && optional-job-two.Succeeded)"
      templateRef:
        name: master-templater
        template: option-three-template
      arguments:
        parameters:
          - name: argument-one
            value: "{{`{{tasks.scraper.outputs.parameters.argument-one}}`}}"