Skip to content

Commit

Permalink
Use the same Deps logic in v1alpha1 and v1beta1
Browse files Browse the repository at this point in the history
Sometimes the PipelineTask that Deps is being executed on is actually
v1beta1 instead of v1alpha1 and the old Deps function, which doesn't
account for Results, is being called.

This PR duplicates the logics so the Deps function is the same.
After #2410 we'll be able to assume we're always using the v1beta1 types
and will not need the logic in both places and can avoid bugs like this.

It also duplicates the DAG test logic which is the closest thing Deps()
currently has to a set of unit tests.

Part of #2463

(cherry picked from commit 893dde2)
  • Loading branch information
bobcatfish committed Apr 23, 2020
1 parent 8960a6f commit 1bc5c50
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
21 changes: 21 additions & 0 deletions pkg/apis/pipeline/v1beta1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,27 @@ func (pt PipelineTask) Deps() []string {
for _, rd := range cond.Resources {
deps = append(deps, rd.From...)
}
for _, param := range cond.Params {
expressions, ok := GetVarSubstitutionExpressionsForParam(param)
if ok {
if resultRefs, err := NewResultRefs(expressions); err == nil {
for _, resultRef := range resultRefs {
deps = append(deps, resultRef.PipelineTask)
}
}
}
}
}
// Add any dependents from task results
for _, param := range pt.Params {
expressions, ok := GetVarSubstitutionExpressionsForParam(param)
if ok {
if resultRefs, err := NewResultRefs(expressions); err == nil {
for _, resultRef := range resultRefs {
deps = append(deps, resultRef.PipelineTask)
}
}
}
}
return deps
}
Expand Down
11 changes: 9 additions & 2 deletions pkg/reconciler/pipeline/dag/dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ func testGraph(t *testing.T) *dag.Graph {
}, {
Name: "b",
}, {
Name: "w",
RunAfter: []string{"b", "y"},
Name: "w",
Params: []v1alpha1.Param{{
Name: "foo",
Value: v1alpha1.ArrayOrString{
Type: v1alpha1.ParamTypeString,
StringVal: "$(tasks.y.results.bar)",
},
}},
RunAfter: []string{"b"},
}, {
Name: "x",
RunAfter: []string{"a"},
Expand Down

0 comments on commit 1bc5c50

Please sign in to comment.