argoproj/argo-workflows · error

failed to get workflow template: %w

Error message

failed to get workflow template: %w

What it means

The Argo Server's event dispatch (WorkflowEventBinding consumer) failed to fetch the WorkflowTemplate referenced by `spec.submit.workflowTemplateRef` before submitting a workflow. It reads via ClusterWorkflowTemplates when `clusterScope: true`, otherwise namespaced WorkflowTemplates in the binding's namespace, and wraps any k8s API error. This is a user/configuration-facing failure surfaced as a Warning event `WorkflowEventBindingError` on the binding.

Source

Thrown at server/event/dispatch/operation.go:110

	matched, err := argoexpr.EvalBool(selector, o.env)
	if err != nil {
		return nil, fmt.Errorf("failed to evaluate workflow template expression: %w", err)
	}
	logger.WithFields(logging.Fields{"namespace": wfeb.Namespace, "event": wfeb.Name, "selector": selector, "matched": matched}).Debug(ctx, "Selector evaluation")
	submit := wfeb.Spec.Submit
	if matched && submit != nil {
		//nolint: contextcheck
		client := auth.GetWfClient(o.ctx)
		ref := wfeb.Spec.Submit.WorkflowTemplateRef
		var tmpl wfv1.WorkflowSpecHolder
		var err error
		if ref.ClusterScope {
			tmpl, err = client.ArgoprojV1alpha1().ClusterWorkflowTemplates().Get(ctx, ref.Name, metav1.GetOptions{})
		} else {
			tmpl, err = client.ArgoprojV1alpha1().WorkflowTemplates(wfeb.Namespace).Get(ctx, ref.Name, metav1.GetOptions{})
		}
		if err != nil {
			return nil, fmt.Errorf("failed to get workflow template: %w", err)
		}
		err = o.instanceIDService.Validate(tmpl)
		if err != nil {
			return nil, fmt.Errorf("failed to validate workflow template instanceid: %w", err)
		}
		wf := common.NewWorkflowFromWorkflowTemplate(tmpl.GetName(), ref.ClusterScope)

		// Apply workflowMetadata labels and annotations from the template
		// at creation time, matching the CronWorkflow behavior.
		// labelsFrom is left to the controller since it
		// requires parameter evaluation at runtime.
		if wmd := tmpl.GetWorkflowSpec().WorkflowMetadata; wmd != nil {
			maps.Copy(wf.Labels, wmd.Labels)
			if len(wmd.Annotations) > 0 {
				maps.Copy(wf.Annotations, wmd.Annotations)
			}
		}

View on GitHub (pinned to 35bff19146)

Solutions

  1. Check the exact referenced name: run `kubectl get workflowtemplates -n <wfeb-namespace>` (or `kubectl get clusterworkflowtemplates` if clusterScope: true) and fix any typo in spec.submit.workflowTemplateRef.name.
  2. Ensure the template is in the same namespace as the WorkflowEventBinding unless clusterScope: true; move the template or set clusterScope correctly.
  3. Verify RBAC: the server's service account (or SSO-mapped SA) needs get on workflowtemplates.argoproj.io in the target namespace/cluster; adjust RBAC roles.
  4. Inspect the wrapped k8s error in the Warning event on the WorkflowEventBinding to distinguish NotFound vs Forbidden vs transient errors.
  5. If the error was transient (API server blip), check controller/server logs; non-transient errors are recorded as `WorkflowEventBindingError` events and the dispatch fails for that binding.

Example fix

# before (binding points at missing/wrong template)
spec:
  submit:
    workflowTemplateRef:
      name: my-worfklow-template
# after
spec:
  submit:
    workflowTemplateRef:
      name: my-workflow-template
Defensive patterns

Strategy: validation

Validate before calling

# before creating/applying the WorkflowEventBinding
kubectl get workflowtemplate <ref-name> -n <binding-namespace>
# or if clusterScope: true
kubectl get clusterworkflowtemplate <ref-name>

Try / catch

// wrap event dispatch submission
_, err := op.Dispatch(ctx)
if err != nil && strings.Contains(err.Error(), "failed to get workflow template") {
    logger.Errorf(ctx, "check workflowTemplateRef name/namespace and RBAC: %v", err)
}

Prevention

When it happens

Trigger: An event (e.g. via `argo submit --from` / eventsource posting to the event API) matched the WorkflowEventBinding selector, but `WorkflowTemplates(wfeb.Namespace).Get(ctx, ref.Name)` or `ClusterWorkflowTemplates().Get(ctx, ref.Name)` returned an error: template not found (NotFound), RBAC denied (Forbidden), wrong namespace in the ref, or transient API server errors (retried only if errorsutil.IsTransientErr deems them so).

Common situations: Typo in workflowTemplateRef.name; template deleted after the binding was created; template lives in a different namespace than the WorkflowEventBinding; clusterScope=true but the template is only namespaced (or vice versa); SSO/server service account lacks argoproj.io workflowtemplates get permission in that namespace.

Related errors


AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03). Data as JSON: /api/errors/8a611e7b9f31bc8c. Report an issue: GitHub.