MCPcopy
hub / github.com/argoproj/argo-workflows / executeTemplate

Method executeTemplate

workflow/controller/operator.go:2091–2529  ·  view source on GitHub ↗

executeTemplate executes the template with the given arguments and returns the created NodeStatus for the created node (if created). Nodes may not be created if parallelism or deadline exceeded. nodeName is the name to be used as the name of the node, and boundaryID indicates which template boundary

(ctx context.Context, nodeName string, orgTmpl wfv1.TemplateReferenceHolder, tmplCtx *templateresolution.TemplateContext, args wfv1.Arguments, opts *executeTemplateOpts)

Source from the content-addressed store, hash-verified

2089// nodeName is the name to be used as the name of the node, and boundaryID indicates which template
2090// boundary this node belongs to.
2091func (woc *wfOperationCtx) executeTemplate(ctx context.Context, nodeName string, orgTmpl wfv1.TemplateReferenceHolder, tmplCtx *templateresolution.TemplateContext, args wfv1.Arguments, opts *executeTemplateOpts) (node *wfv1.NodeStatus, err error) {
2092 // if this function returns an error, a pod is never created
2093 // we should never expect task results to sync
2094 defer func() {
2095 if err != nil && node != nil && node.TaskResultSynced != nil {
2096 tmp := true
2097 node.TaskResultSynced = &tmp
2098 }
2099 }()
2100
2101 woc.log.WithFields(logging.Fields{"nodeName": nodeName, "template": common.GetTemplateHolderString(orgTmpl), "boundaryID": opts.boundaryID}).Debug(ctx, "Evaluating node")
2102
2103 // Set templateScope from which the template resolution starts.
2104 templateScope := tmplCtx.GetTemplateScope()
2105
2106 node, err = woc.wf.GetNodeByName(nodeName)
2107 if err != nil {
2108 // Will be initialized via woc.initializeNodeOrMarkError
2109 woc.log.Info(ctx, "Node was nil, will be initialized as type Skipped")
2110 }
2111
2112 if node != nil {
2113 if node.DisplayName == "dependencyTesting" {
2114 woc.log.WithField("nodeName", nodeName).Debug(ctx, "Node already exists, will be updated")
2115 }
2116 }
2117
2118 woc.currentStackDepth++
2119 defer func() { woc.currentStackDepth-- }()
2120
2121 if woc.currentStackDepth >= woc.controller.maxStackDepth && os.Getenv("DISABLE_MAX_RECURSION") != "true" {
2122 return woc.initializeNodeOrMarkError(ctx, node, nodeName, templateScope, orgTmpl, opts.boundaryID, opts.nodeFlag, ErrMaxDepthExceeded), ErrMaxDepthExceeded
2123 }
2124
2125 newTmplCtx, resolvedTmpl, templateStored, err := tmplCtx.ResolveTemplate(ctx, orgTmpl)
2126 if err != nil {
2127 return woc.initializeNodeOrMarkError(ctx, node, nodeName, templateScope, orgTmpl, opts.boundaryID, opts.nodeFlag, err), err
2128 }
2129 // A new template was stored during resolution, persist it
2130 if templateStored {
2131 woc.updated = true
2132 }
2133
2134 // Merge Template defaults to template
2135 err = woc.mergedTemplateDefaultsInto(resolvedTmpl)
2136 if err != nil {
2137 return woc.initializeNodeOrMarkError(ctx, node, nodeName, templateScope, orgTmpl, opts.boundaryID, opts.nodeFlag, err), err
2138 }
2139
2140 localParams := make(map[string]string)
2141 // Inject the pod name. If the pod has a retry strategy, the pod name will be changed and will be injected when it
2142 // is determined
2143 if resolvedTmpl.IsPodType() && woc.retryStrategy(resolvedTmpl) == nil {
2144 localParams[common.LocalVarPodName] = woc.getPodName(nodeName, resolvedTmpl.Name)
2145 }
2146 if orgTmpl.IsDAGTask() {
2147 localParams["tasks.name"] = orgTmpl.GetName()
2148 }

Callers 6

executeDAGTaskMethod · 0.95
operateMethod · 0.95
runOnExitNodeMethod · 0.95
executeStepGroupMethod · 0.95

Calls 15

retryStrategyMethod · 0.95
getPodNameMethod · 0.95
setNodeDisplayNameMethod · 0.95
handleNodeFulfilledMethod · 0.95
requeueMethod · 0.95
checkTemplateTimeoutMethod · 0.95
markNodePhaseMethod · 0.95
checkParallelismMethod · 0.95

Tested by

no test coverage detected