Skip to content

Commit

Permalink
Store locally referenced template properly (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtaniwaki authored and sarabala1979 committed Oct 17, 2019
1 parent 30a91ef commit 095d67f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
23 changes: 13 additions & 10 deletions pkg/apis/workflow/v1alpha1/workflow_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type TemplateGetter interface {
type TemplateHolder interface {
GetTemplateName() string
GetTemplateRef() *TemplateRef
IsResolvable() bool
}

// Workflow is the definition of a workflow resource
Expand Down Expand Up @@ -367,6 +368,10 @@ func (tmpl *Template) GetTemplateRef() *TemplateRef {
return tmpl.TemplateRef
}

func (tmpl *Template) IsResolvable() bool {
return tmpl.Template != "" || tmpl.TemplateRef != nil
}

// GetBaseTemplate returns a base template content.
func (tmpl *Template) GetBaseTemplate() *Template {
baseTemplate := tmpl.DeepCopy()
Expand Down Expand Up @@ -567,6 +572,10 @@ func (step *WorkflowStep) GetTemplateRef() *TemplateRef {
return step.TemplateRef
}

func (step *WorkflowStep) IsResolvable() bool {
return true
}

// Item expands a single workflow step into multiple parallel steps
// The value of Item can be a map, string, bool, or number
type Item struct {
Expand Down Expand Up @@ -773,16 +782,6 @@ type NodeStatus struct {
OutboundNodes []string `json:"outboundNodes,omitempty"`
}

var _ TemplateHolder = &NodeStatus{}

func (n *NodeStatus) GetTemplateName() string {
return n.TemplateName
}

func (n *NodeStatus) GetTemplateRef() *TemplateRef {
return n.TemplateRef
}

func (n NodeStatus) String() string {
return fmt.Sprintf("%s (%s)", n.Name, n.ID)
}
Expand Down Expand Up @@ -1158,6 +1157,10 @@ func (t *DAGTask) GetTemplateRef() *TemplateRef {
return t.TemplateRef
}

func (t *DAGTask) IsResolvable() bool {
return true
}

// SuspendTemplate is a template subtype to suspend a workflow at a predetermined point in time
type SuspendTemplate struct {
}
Expand Down
10 changes: 8 additions & 2 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1322,8 +1322,14 @@ func (woc *wfOperationCtx) initializeExecutableNode(nodeName string, nodeType wf
// Store the template for the later use.
if node.TemplateRef != nil {
node.StoredTemplateID = fmt.Sprintf("%s/%s", node.TemplateRef.Name, node.TemplateRef.Template)
} else if node.WorkflowTemplateName != "" {
node.StoredTemplateID = fmt.Sprintf("%s/%s", node.WorkflowTemplateName, node.TemplateName)
} else if node.TemplateName != "" {
if node.WorkflowTemplateName != "" {
// Locally resolvable in workflow template level.
node.StoredTemplateID = fmt.Sprintf("%s/%s", node.WorkflowTemplateName, node.TemplateName)
} else if orgTmpl.IsResolvable() {
// Locally resolvable in workflow level.
node.StoredTemplateID = fmt.Sprintf("/%s", node.TemplateName)
}
}
if node.StoredTemplateID != "" {
baseTemplate := executeTmpl.GetBaseTemplate()
Expand Down

0 comments on commit 095d67f

Please sign in to comment.