Argo: Template within Workflow can not directly call a WorkflowTemplate with arguments

Created on 23 Jan 2020  路  11Comments  路  Source: argoproj/argo

Checklist:

  • [x] I've included the version.
  • [ ] I've included reproduction steps.
  • [x] I've included the workflow YAML.
  • [ ] I've included the logs.

What happened:
Trying to submit a Workflow which executes a template on a WorkflowTemplate fails.

What you expected to happen:
The workflow should be submitted and run.

How to reproduce it (as minimally and precisely as possible):

# workflow_template.yaml
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: example-workflow-template
spec:
  templates:
  - name: on-workflow-template
    inputs:
      parameters:
        - name: parameter-passed-in
    container:
      image: docker/whalesay
      command: [cowsay]
      args: ["test {{inputs.parameters.parameter-passed-in}}"]
# workflow.yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: directly-call-workflow-template-
spec:
  entrypoint: entrypoint
  arguments:
    parameters:
      - name: parameter-1
        value: "default-value-from-workflow"

  templates:
    - name: entrypoint
      templateRef:
        name: example-workflow-template
        template: on-workflow-template
      arguments:
        parameters:
          - name: parameter-passed-in
            value: "{{workflow.parameters.parameter-1}}"
$ kubectl apply -f workflow_template.yaml
workflowtemplate.argoproj.io/example-workflow-template created
$ argo submit workflow.yaml
2020/01/23 13:05:02 Failed to submit workflow: templates.entrypoint.arguments must be used with template or templateRef

Anything else we need to know?:

Environment:

  • Argo version:
$ argo version
argo: v2.4.3
  BuildDate: 2019-12-06T03:36:38Z
  GitCommit: cfe5f377bc3552fba90afe6db7a76edd92c753cd
  GitTreeState: clean
  GitTag: v2.4.3
  GoVersion: go1.11.5
  Compiler: gc
  Platform: darwin/amd64
  • Kubernetes version :
$ kubectl version -o yaml
clientVersion:
  buildDate: "2019-10-15T12:12:15Z"
  compiler: gc
  gitCommit: a8b52209ee172232b6db7a6e0ce2adc77458829f
  gitTreeState: clean
  gitVersion: v1.13.12
  goVersion: go1.11.13
  major: "1"
  minor: "13"
  platform: darwin/amd64
serverVersion:
  buildDate: "2019-10-15T12:04:30Z"
  compiler: gc
  gitCommit: a8b52209ee172232b6db7a6e0ce2adc77458829f
  gitTreeState: clean
  gitVersion: v1.13.12
  goVersion: go1.11.13
  major: "1"
  minor: "13"
  platform: linux/amd64


Message from the maintainers:

If you are impacted by this bug please add a 馃憤 reaction to this issue! We often sort issues this way to know what to prioritize.

bug workaround

Most helpful comment

You can use the Step template on Exithandler that can refer the workflowtemplate.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: workflow-template-hello-world-
spec:
  entrypoint: whalesay
  onExit: exittmpl
  templates:
  - name: whalesay
    steps:
      - - name: call-whalesay-template
          templateRef:
            name: workflow-template-whalesay-template
            template: whalesay-template
          arguments:
            parameters:
            - name: message
              value: "hello world"
  - name: exittmpl
    steps:
      - - name: call-whalesay-template
          templateRef:
            name: workflow-template-whalesay-template
            template: whalesay-template
          arguments:
            parameters:
              - name: message
                value: "Exit Handler"

All 11 comments

Attempting to triage the issue. At first glance it's unclear to me what the intent is for this code in the validateTemplate function. If anyone has insights to share please do.

https://github.com/argoproj/argo/blob/b024c46c8fec8a682802c1d6667a79fede959ae4/workflow/validate/validate.go#L215-L217

I'd do some further investigation this weekend.

i think this commmit has something to do with this issue (merged into v2.4.3)

That changed the name of the field for passing args to a template from templateRef from arguments to inputs.

Actually, https://github.com/argoproj/argo/blob/v2.4.3/examples/workflow-template/hello-world.yaml#L12 uses inputs instead of arguments as in https://github.com/argoproj/argo/blob/v2.4.2/examples/workflow-template/hello-world.yaml#L12

i hope this comment would help those who struggle

I tried to use inputs instead of arguments but I got this other error...

2020/02/12 10:15:43 Failed to submit workflow: inputs.parameters.xxxxx was not supplied

I think that the problem is in the validateTemplate function as @bartlinga said. I tried to understand that part of the code but I don't know anything about Go.

@dtaniwaki FYI

@delwaterman While attempting to troubleshoot this I stumbled across a (the?) solve. The parameters in the workflow template need default values.

You'll also need to use inputs instead arguments to pass the args via the template ref. I'm using 2.5-rc10 but given when the code change happened I suspect this will work for you (thanks @mathetake).

# workflow_template.yaml
apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: example-workflow-template
spec:
  templates:
  - name: on-workflow-template
    inputs:
      parameters:
        - name: parameter-passed-in
          value: "default"          # add a value here
    container:
      image: docker/whalesay
      command: [cowsay]
      args: ["test {{inputs.parameters.parameter-passed-in}}"]
# workflow.yaml
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: directly-call-workflow-template-
spec:
  entrypoint: entrypoint
  arguments:
    parameters:
      - name: parameter-1
        value: "default-value-from-workflow"

  templates:
    - name: entrypoint
      templateRef:
        name: example-workflow-template
        template: on-workflow-template
      inputs:                       # use inputs instead of arguments
        parameters:
          - name: parameter-passed-in
            value: "{{workflow.parameters.parameter-1}}"
directly-call-workflow-template-slss5:   __________________________________ 
directly-call-workflow-template-slss5:  < test default-value-from-workflow >
directly-call-workflow-template-slss5:   ---------------------------------- 
<snip>

Bug is basically a workflow template that has "arguments", but these are never used by the code. I will delete this.

So I've been playing around with this and while this does now work, this causes a lot of confusing. For now we're sticking with the pattern of using steps to trigger a single workflow.

I'll think on this a bit, and maybe write up an enhancement proposal for possibly a better solution.

Hello everyone. Please be advised that we will be deprecating calling templates directly on a template object and will now only support calling them under template.steps or template.dag.

Please see this doc for more information: https://github.com/argoproj/argo/blob/master/docs/workflow-templates.md#referencing-other-workflowtemplates

Let me know if you have any questions.

(Also cc people who reacted but didn't comment: @ptemmer, @amartinunowhy, @sbabineau, @pez5001, @walleb, @jotsen, @Pmastern, @csielee, @mool, @wincus)

@simster7 If understand you correctly then this deprecation means that onExit handlers will not be able to use template references anymore as they always reference a template within the current workflow definition which after this change cannot reference a templateRef anymore.
Is my understanding correct and is this intended?

You can use the Step template on Exithandler that can refer the workflowtemplate.

apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
  generateName: workflow-template-hello-world-
spec:
  entrypoint: whalesay
  onExit: exittmpl
  templates:
  - name: whalesay
    steps:
      - - name: call-whalesay-template
          templateRef:
            name: workflow-template-whalesay-template
            template: whalesay-template
          arguments:
            parameters:
            - name: message
              value: "hello world"
  - name: exittmpl
    steps:
      - - name: call-whalesay-template
          templateRef:
            name: workflow-template-whalesay-template
            template: whalesay-template
          arguments:
            parameters:
              - name: message
                value: "Exit Handler"

@sarabala1979 Thank you very much. That helps a lot!

Was this page helpful?
0 / 5 - 0 ratings