Skip to content

Commit

Permalink
distinguish task dependencies: ordering vs resource
Browse files Browse the repository at this point in the history
there are two types of dependencies between tasks:
- _resource-dependency_: based on resources needed from parent task,
which includes results, workspaces and resources
- _ordering-dependency_: based on runAfter which provides sequencing of
tasks when there may not be resource dependencies

however, it is currently difficult to distinguish between the two

this PR provides a way to know the dependency type and will be useful
for future work such as allowing execution of ordering-dependent tasks
when continueAfterSkip is set to true
  • Loading branch information
jerop committed Oct 22, 2020
1 parent e98baae commit 4a0fe52
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions pkg/apis/pipeline/v1beta1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,31 @@ func (pt PipelineTask) HashKey() string {

func (pt PipelineTask) Deps() []string {
deps := []string{}
deps = append(deps, pt.RunAfter...)

deps = append(deps, pt.resourceDeps()...)
deps = append(deps, pt.orderingDeps()...)

return deps
}

func (pt PipelineTask) resourceDeps() []string {
resourceDeps := []string{}
if pt.Resources != nil {
for _, rd := range pt.Resources.Inputs {
deps = append(deps, rd.From...)
resourceDeps = append(resourceDeps, rd.From...)
}
}
// Add any dependents from conditional resources.
for _, cond := range pt.Conditions {
for _, rd := range cond.Resources {
deps = append(deps, rd.From...)
resourceDeps = append(resourceDeps, rd.From...)
}
for _, param := range cond.Params {
expressions, ok := GetVarSubstitutionExpressionsForParam(param)
if ok {
resultRefs := NewResultRefs(expressions)
for _, resultRef := range resultRefs {
deps = append(deps, resultRef.PipelineTask)
resourceDeps = append(resourceDeps, resultRef.PipelineTask)
}
}
}
Expand All @@ -197,7 +205,7 @@ func (pt PipelineTask) Deps() []string {
if ok {
resultRefs := NewResultRefs(expressions)
for _, resultRef := range resultRefs {
deps = append(deps, resultRef.PipelineTask)
resourceDeps = append(resourceDeps, resultRef.PipelineTask)
}
}
}
Expand All @@ -207,11 +215,31 @@ func (pt PipelineTask) Deps() []string {
if ok {
resultRefs := NewResultRefs(expressions)
for _, resultRef := range resultRefs {
deps = append(deps, resultRef.PipelineTask)
resourceDeps = append(resourceDeps, resultRef.PipelineTask)
}
}
}
return deps
return resourceDeps
}

func (pt PipelineTask) orderingDeps() []string {
orderingDeps := []string{}
resourceDeps := pt.resourceDeps()
for _, runAfter := range pt.RunAfter {
if !contains(runAfter, resourceDeps) {
orderingDeps = append(orderingDeps, runAfter)
}
}
return orderingDeps
}

func contains(s string, arr []string) bool {
for _, elem := range arr {
if elem == s {
return true
}
}
return false
}

type PipelineTaskList []PipelineTask
Expand Down

0 comments on commit 4a0fe52

Please sign in to comment.