From 492928e7efa80dc06a61ce666e4b8c34404a51ac Mon Sep 17 00:00:00 2001 From: Jerop Date: Tue, 21 Jun 2022 22:53:11 -0400 Subject: [PATCH] `GetChildReferences` checks for non-nil `TaskRuns` In https://github.com/tektoncd/pipeline/pull/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: https://github.com/tektoncd/pipeline/pull/5008 --- .../pipelinerun/resources/pipelinerunstate.go | 4 ++- .../resources/pipelinerunstate_test.go | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go b/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go index ba8c48ceedf..90c2cb7a62a 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go @@ -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)) + } } } } diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go index 152f7b96f36..75edcf7adad 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go @@ -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{{