Skip to content

Commit

Permalink
Check for non-nil TaskRun in GetTaskRunsResults
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
jerop authored and tekton-robot committed Jun 22, 2022
1 parent 1bd3dfb commit 5032b43
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
63 changes: 63 additions & 0 deletions pkg/reconciler/pipelinerun/resources/pipelinerunstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 5032b43

Please sign in to comment.