argoproj / argo-workflows

Workflow Engine for Kubernetes
https://argo-workflows.readthedocs.io/
Apache License 2.0
15.08k stars 3.2k forks source link

failed to resolve parameters in `withParam` expression #10462

Open Nizar-opt opened 1 year ago

Nizar-opt commented 1 year ago

Pre-requisites

What happened/what you expected to happen?

I wanted to use withParam but with a generated JSON with the help of expression & sprig functions. The below example works as expected.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: loops-
spec:
  entrypoint: loop-example
  arguments:
    parameters:
      - name: chunk
        value: 20
  templates:
  - name: loop-example
    steps:
    - - name: print-message
        template: whalesay
        arguments:
          parameters:
          - name: start
            value: "{{item.start}}"
          - name: end
            value: "{{item.end}}"
        withParam: >-
          {{=
            toJson(
              map(sprig.untilStep(0,100,20), { {start: #, end: # + 20 } })
            )
            }}

  - name: whalesay
    inputs:
      parameters:
      - name: start
      - name: end
    container:
      image: docker/whalesay:latest
      command: [cowsay]
      args: ["start: ","{{inputs.parameters.start}}", " | end: ", "{{inputs.parameters.end}}"]

But.. when I started to parametrize it by replacing sprig.untilStep(0,100,20) with sprig.untilStep(0,100,workflow.parameters.chunk), It always failed with the following error:

withParam value could not be parsed as a JSON list: {{= toJson( map(sprig.untilStep(0,100,workflow.parameters.chunk), { {start: #, end: # + 20 } }) ) }}: invalid character '{' looking for beginning of object key string

as you can see, it does not resolve the parameter workflow.parameters.chunk. I also tried inputs.parameters & steps.**.outputs.result

Here is an example that would fail.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: loops-
spec:
  entrypoint: loop-example
  arguments:
    parameters:
      - name: chunk
        value: 20
  templates:
  - name: loop-example
    steps:
    - - name: print-message
        template: whalesay
        arguments:
          parameters:
          - name: start
            value: "{{item.start}}"
          - name: end
            value: "{{item.end}}"
        withParam: >-
          {{=
            toJson(
              map(sprig.untilStep(0,100,workflow.parameters.chunk), { {start: #, end: # + 20 } })
            )
            }}

  - name: whalesay
    inputs:
      parameters:
      - name: start
      - name: end
    container:
      image: docker/whalesay:latest
      command: [cowsay]
      args: ["start: ","{{inputs.parameters.start}}", " | end: ", "{{inputs.parameters.end}}"]

Version

v3.4.4

Paste a small workflow that reproduces the issue. We must be able to run the workflow; don't enter a workflows that uses private images.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: loops-
spec:
  entrypoint: loop-example
  arguments:
    parameters:
      - name: chunk
        value: 20
  templates:
  - name: loop-example
    steps:
    - - name: print-message
        template: whalesay
        arguments:
          parameters:
          - name: start
            value: "{{item.start}}"
          - name: end
            value: "{{item.end}}"
        withParam: >-
          {{=
            toJson(
              map(sprig.untilStep(0,100,workflow.parameters.chunk), { {start: #, end: # + 20 } })
            )
            }}

  - name: whalesay
    inputs:
      parameters:
      - name: start
      - name: end
    container:
      image: docker/whalesay:latest
      command: [cowsay]
      args: ["start: ","{{inputs.parameters.start}}", " | end: ", "{{inputs.parameters.end}}"]

Logs from the workflow controller

kubectl logs -n argo deploy/workflow-controller | grep ${workflow}

Found 3 pods, using pod/workflow-controller-6c4d6fbd5f-nkqk2

> the workflow fails right away, hence no logs.

Logs from in your workflow's wait container

kubectl logs -n argo -c wait -l workflows.argoproj.io/workflow=${workflow},workflow.argoproj.io/phase!=Succeeded

No resources found in argo namespace.

> the workflow fails right away, hence no logs.
JPZ13 commented 1 year ago

@sarabala1979 - Do you know if the variable substitution in withParam shown above where it's in a sprig function is supported? If not, we can add it as an enhancement. If so, we'll keep it as a bug

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is a mentoring request, please provide an update here. Thank you for your contributions.