From 5032b43896b6eeba4dcacf48cd23039c7f0a4e29 Mon Sep 17 00:00:00 2001 From: Jerop Date: Tue, 21 Jun 2022 23:10:01 -0400 Subject: [PATCH] Check for non-nil `TaskRun` in `GetTaskRunsResults` In this change, we handle scenarios where a matrixed `PipelineTask` is successful - so `rprt` is successful but its `TaskRun` field is nil because it has `TaskRuns` instead. We need to add a check that `rprt.TaskRun` is non-nil before attempting to access its field: `rprt.TaskRun.Status.TaskRunResults`. --- .../pipelinerun/resources/pipelinerunstate.go | 5 +- .../resources/pipelinerunstate_test.go | 63 +++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go b/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go index ba8c48ceedf..d028789a26f 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunstate.go @@ -182,9 +182,10 @@ func (state PipelineRunState) GetTaskRunsResults() map[string][]v1beta1.TaskRunR if !rprt.isSuccessful() { continue } - results[rprt.PipelineTask.Name] = rprt.TaskRun.Status.TaskRunResults + if rprt.TaskRun != nil { + results[rprt.PipelineTask.Name] = rprt.TaskRun.Status.TaskRunResults + } } - return results } diff --git a/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go b/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go index 152f7b96f36..cc5f95ce6fb 100644 --- a/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go +++ b/pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go @@ -2368,6 +2368,69 @@ func TestPipelineRunState_GetResultsFuncs(t *testing.T) { PipelineTask: &v1beta1.PipelineTask{ Name: "nil-run-1", }, + }, { + TaskRunNames: []string{ + "matrixed-task-run-0", + "matrixed-task-run-1", + "matrixed-task-run-2", + "matrixed-task-run-3", + }, + PipelineTask: &v1beta1.PipelineTask{ + Name: "matrixed-task", + TaskRef: &v1beta1.TaskRef{ + Name: "task", + Kind: "Task", + APIVersion: "v1beta1", + }, + 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{{ + TypeMeta: metav1.TypeMeta{APIVersion: "tekton.dev/v1beta1"}, + ObjectMeta: metav1.ObjectMeta{Name: "matrixed-task-run-0"}, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{Conditions: []apis.Condition{{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionTrue, + Reason: v1beta1.TaskRunReasonSuccessful.String(), + }}}, + }, + }, { + TypeMeta: metav1.TypeMeta{APIVersion: "tekton.dev/v1beta1"}, + ObjectMeta: metav1.ObjectMeta{Name: "matrixed-task-run-1"}, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{Conditions: []apis.Condition{{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionTrue, + Reason: v1beta1.TaskRunReasonSuccessful.String(), + }}}, + }, + }, { + TypeMeta: metav1.TypeMeta{APIVersion: "tekton.dev/v1beta1"}, + ObjectMeta: metav1.ObjectMeta{Name: "matrixed-task-run-2"}, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{Conditions: []apis.Condition{{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionTrue, + Reason: v1beta1.TaskRunReasonSuccessful.String(), + }}}, + }, + }, { + TypeMeta: metav1.TypeMeta{APIVersion: "tekton.dev/v1beta1"}, + ObjectMeta: metav1.ObjectMeta{Name: "matrixed-task-run-3"}, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{Conditions: []apis.Condition{{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionTrue, + Reason: v1beta1.TaskRunReasonSuccessful.String(), + }}}, + }, + }}, }} expectedTaskResults := map[string][]v1beta1.TaskRunResult{