Skip to content

Commit 7216c7f

Browse files
committed
distinguish task dependencies: ordering vs resource
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
1 parent e98baae commit 7216c7f

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

pkg/apis/pipeline/v1alpha1/pipeline_types.go

+34-6
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,31 @@ func (pt PipelineTask) HashKey() string {
156156

157157
func (pt PipelineTask) Deps() []string {
158158
deps := []string{}
159-
deps = append(deps, pt.RunAfter...)
159+
160+
deps = append(deps, pt.ResourceDeps()...)
161+
deps = append(deps, pt.OrderingDeps()...)
162+
163+
return deps
164+
}
165+
166+
func (pt PipelineTask) ResourceDeps() []string {
167+
resourceDeps := []string{}
160168
if pt.Resources != nil {
161169
for _, rd := range pt.Resources.Inputs {
162-
deps = append(deps, rd.From...)
170+
resourceDeps = append(resourceDeps, rd.From...)
163171
}
164172
}
165173
// Add any dependents from conditional resources.
166174
for _, cond := range pt.Conditions {
167175
for _, rd := range cond.Resources {
168-
deps = append(deps, rd.From...)
176+
resourceDeps = append(resourceDeps, rd.From...)
169177
}
170178
for _, param := range cond.Params {
171179
expressions, ok := v1beta1.GetVarSubstitutionExpressionsForParam(param)
172180
if ok {
173181
resultRefs := v1beta1.NewResultRefs(expressions)
174182
for _, resultRef := range resultRefs {
175-
deps = append(deps, resultRef.PipelineTask)
183+
resourceDeps = append(resourceDeps, resultRef.PipelineTask)
176184
}
177185
}
178186
}
@@ -183,12 +191,32 @@ func (pt PipelineTask) Deps() []string {
183191
if ok {
184192
resultRefs := v1beta1.NewResultRefs(expressions)
185193
for _, resultRef := range resultRefs {
186-
deps = append(deps, resultRef.PipelineTask)
194+
resourceDeps = append(resourceDeps, resultRef.PipelineTask)
187195
}
188196
}
189197
}
190198

191-
return deps
199+
return resourceDeps
200+
}
201+
202+
func (pt PipelineTask) OrderingDeps() []string {
203+
orderingDeps := []string{}
204+
resourceDeps := pt.ResourceDeps()
205+
for _, runAfter := range pt.RunAfter {
206+
if !contains(runAfter, resourceDeps) {
207+
orderingDeps = append(orderingDeps, runAfter)
208+
}
209+
}
210+
return orderingDeps
211+
}
212+
213+
func contains(s string, arr []string) bool {
214+
for _, elem := range arr {
215+
if elem == s {
216+
return true
217+
}
218+
}
219+
return false
192220
}
193221

194222
type PipelineTaskList []PipelineTask

0 commit comments

Comments
 (0)