简体   繁体   中英

Argo workflow template execution failing when I use when condition with withParam loop along with the artifact input

I've the following workflow template which has when condition when: "'{{item}}' =~ '^tests/'" , artifacts input as file path in AWS S3 bucket and withParam loop.

Here is my workflow template

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: process-wft
spec:
  entrypoint: main
  templates:
    - name: main
      inputs:
        parameters:
          - name: dir-process
            default: true
          - name: dir


        artifacts:
          - name: Code

      dag:
        tasks:
          - name: process-wft-tests
            when: "'{{item}}' =~ '^tests/'"
            templateRef:
              name: tf-wf-rn
              template: main
            arguments:
              parameters:
                - name: dir-process
                  value: "{{inputs.parameters.dir-process}}"
              artifacts:
                - name: Code
                  from: "{{inputs.artifacts.Code}}"
            withParam: "{{inputs.parameters.dir}}"

here is my input artifact Code extracted result which is being passed from my workflow

inputs:
  artifacts:
  - archive:
      tar:
        compressionLevel: 9
    archiveLogs: true
    globalName: GitSource
    name: Code
    path: /mnt/out/code
    s3:
      key: process-kfxqf/process-kfxqf-1938174407/GitSource.tgz

It is giving the below Error when I run my workflow

message: failed to resolve {{inputs.artifacts.Code}}

What's the mistake am doing here? if it doesn't work what's the alternate way to get this worked?

Note: I tried workflow execution by removing when condition, it is working fine. It is giving issue only when I add when condition.

This is a bug .

It seems that when the condition evaluates to false , some code skips populating the artifact (makes sense, save some time), but some other code doesn't respect the when condition and still expects the artifact to be populated.

Potential workarounds:

  1. Move the conditional logic into the container.

    1. remove the when condition
    2. pass the dir parameter to the main template in your tf-wf-rn WorkflowTemplate
    3. change the main template to run the regex against the dir parameter - if it doesn't match, just exit 0

    This could make the workflow much slower, because you'll have to spin up a pod for each iteration of the loop to determine if there's actually any work to be done.

  2. If you can calculate all the information about the artifact, pass that information as parameters to the main template in your tf-wf-rn WorkflowTemplate. Then actually load the artifact in that non-conditioned, non-looped template. (Basically hopscotch over the problematic code.)

  3. Try an older version.

    If you find a working older version, please 1) comment on the bug report and 2) make sure the older version doesn't have any relevant security vulnerabilities before running it on a production system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM