Skip to content

Commit 117fb0d

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 117fb0d

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

pkg/apis/pipeline/v1beta1/pipeline_types.go

+35-7
Original file line numberDiff line numberDiff line change
@@ -170,23 +170,31 @@ func (pt PipelineTask) HashKey() string {
170170

171171
func (pt PipelineTask) Deps() []string {
172172
deps := []string{}
173-
deps = append(deps, pt.RunAfter...)
173+
174+
deps = append(deps, pt.ResourceDeps()...)
175+
deps = append(deps, pt.OrderingDeps()...)
176+
177+
return deps
178+
}
179+
180+
func (pt PipelineTask) ResourceDeps() []string {
181+
resourceDeps := []string{}
174182
if pt.Resources != nil {
175183
for _, rd := range pt.Resources.Inputs {
176-
deps = append(deps, rd.From...)
184+
resourceDeps = append(resourceDeps, rd.From...)
177185
}
178186
}
179187
// Add any dependents from conditional resources.
180188
for _, cond := range pt.Conditions {
181189
for _, rd := range cond.Resources {
182-
deps = append(deps, rd.From...)
190+
resourceDeps = append(resourceDeps, rd.From...)
183191
}
184192
for _, param := range cond.Params {
185193
expressions, ok := GetVarSubstitutionExpressionsForParam(param)
186194
if ok {
187195
resultRefs := NewResultRefs(expressions)
188196
for _, resultRef := range resultRefs {
189-
deps = append(deps, resultRef.PipelineTask)
197+
resourceDeps = append(resourceDeps, resultRef.PipelineTask)
190198
}
191199
}
192200
}
@@ -197,7 +205,7 @@ func (pt PipelineTask) Deps() []string {
197205
if ok {
198206
resultRefs := NewResultRefs(expressions)
199207
for _, resultRef := range resultRefs {
200-
deps = append(deps, resultRef.PipelineTask)
208+
resourceDeps = append(resourceDeps, resultRef.PipelineTask)
201209
}
202210
}
203211
}
@@ -207,11 +215,31 @@ func (pt PipelineTask) Deps() []string {
207215
if ok {
208216
resultRefs := NewResultRefs(expressions)
209217
for _, resultRef := range resultRefs {
210-
deps = append(deps, resultRef.PipelineTask)
218+
resourceDeps = append(resourceDeps, resultRef.PipelineTask)
211219
}
212220
}
213221
}
214-
return deps
222+
return resourceDeps
223+
}
224+
225+
func (pt PipelineTask) OrderingDeps() []string {
226+
orderingDeps := []string{}
227+
resourceDeps := pt.ResourceDeps()
228+
for _, runAfter := range pt.RunAfter {
229+
if !contains(runAfter, resourceDeps) {
230+
orderingDeps = append(orderingDeps, runAfter)
231+
}
232+
}
233+
return orderingDeps
234+
}
235+
236+
func contains(s string, arr []string) bool {
237+
for _, elem := range arr {
238+
if elem == s {
239+
return true
240+
}
241+
}
242+
return false
215243
}
216244

217245
type PipelineTaskList []PipelineTask

0 commit comments

Comments
 (0)