Skip to content

Commit 881510f

Browse files
jeroptekton-robot
authored andcommitted
GetChildReferences checks for non-nil TaskRuns
In #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: #5008
1 parent 1d3d9ad commit 881510f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pkg/reconciler/pipelinerun/resources/pipelinerunstate.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,9 @@ func (state PipelineRunState) GetChildReferences() []v1beta1.ChildStatusReferenc
250250
childRefs = append(childRefs, rprt.getChildRefForTaskRun(rprt.TaskRun))
251251
case len(rprt.TaskRuns) != 0:
252252
for _, taskRun := range rprt.TaskRuns {
253-
childRefs = append(childRefs, rprt.getChildRefForTaskRun(taskRun))
253+
if taskRun != nil {
254+
childRefs = append(childRefs, rprt.getChildRefForTaskRun(taskRun))
255+
}
254256
}
255257
}
256258
}

pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,6 +2628,34 @@ func TestPipelineRunState_GetChildReferences(t *testing.T) {
26282628
PipelineTaskName: "single-custom-task-1",
26292629
}},
26302630
},
2631+
{
2632+
name: "unresolved-matrixed-task",
2633+
state: PipelineRunState{{
2634+
TaskRunNames: []string{"task-run-0", "task-run-1", "task-run-2", "task-run-3"},
2635+
PipelineTask: &v1beta1.PipelineTask{
2636+
Name: "matrixed-task",
2637+
TaskRef: &v1beta1.TaskRef{
2638+
Name: "task",
2639+
Kind: "Task",
2640+
APIVersion: "v1beta1",
2641+
},
2642+
WhenExpressions: []v1beta1.WhenExpression{{
2643+
Input: "foo",
2644+
Operator: selection.In,
2645+
Values: []string{"foo", "bar"},
2646+
}},
2647+
Matrix: []v1beta1.Param{{
2648+
Name: "foobar",
2649+
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"foo", "bar"}},
2650+
}, {
2651+
Name: "quxbaz",
2652+
Value: v1beta1.ArrayOrString{Type: v1beta1.ParamTypeArray, ArrayVal: []string{"qux", "baz"}},
2653+
}},
2654+
},
2655+
TaskRuns: []*v1beta1.TaskRun{nil, nil, nil, nil},
2656+
}},
2657+
childRefs: nil,
2658+
},
26312659
{
26322660
name: "matrixed-task",
26332661
state: PipelineRunState{{

0 commit comments

Comments
 (0)