Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store locally referenced templates properly #1670

Merged
merged 1 commit into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1315,8 +1315,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