Skip to content

Commit

Permalink
GetChildReferences checks for non-nil TaskRuns
Browse files Browse the repository at this point in the history
In tektoncd#5006, we refactored
`GetChildReferences` such that it checks that `TaskRun` is non-nil
before calling the helper function `getChildRefForTaskRun` that
expects a non-nil `TaskRun`.

In this change, we add a check that each `TaskRun` from matrixed
`PipelineTask` is non-nil before calling `getChildRefForTaskRun`.

Related PR: tektoncd#5008
  • Loading branch information
jerop committed Jun 22, 2022
1 parent 1bd3dfb commit 492928e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/reconciler/pipelinerun/resources/pipelinerunstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@ func (state PipelineRunState) GetChildReferences() []v1beta1.ChildStatusReferenc
childRefs = append(childRefs, rprt.getChildRefForTaskRun(rprt.TaskRun))
case len(rprt.TaskRuns) != 0:
for _, taskRun := range rprt.TaskRuns {
childRefs = append(childRefs, rprt.getChildRefForTaskRun(taskRun))
if taskRun != nil {
childRefs = append(childRefs, rprt.getChildRefForTaskRun(taskRun))
}
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2565,6 +2565,34 @@ func TestPipelineRunState_GetChildReferences(t *testing.T) {
PipelineTaskName: "single-custom-task-1",
}},
},
{
name: "unresolved-matrixed-task",
state: PipelineRunState{{
TaskRunNames: []string{"task-run-0", "task-run-1", "task-run-2", "task-run-3"},
PipelineTask: &v1beta1.PipelineTask{
Name: "matrixed-task",
TaskRef: &v1beta1.TaskRef{
Name: "task",
Kind: "Task",
APIVersion: "v1beta1",
},
WhenExpressions: []v1beta1.WhenExpression{{
Input: "foo",
Operator: selection.In,
Values: []string{"foo", "bar"},
}},
Matrix: []v1beta1.Param{{
Name: "foobar",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"foo", "bar"}},
}, {
Name: "quxbaz",
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"qux", "baz"}},
}},
},
TaskRuns: []*v1beta1.TaskRun{nil, nil, nil, nil},
}},
childRefs: nil,
},
{
name: "matrixed-task",
state: PipelineRunState{{
Expand Down

0 comments on commit 492928e

Please sign in to comment.