Skip to content

Commit

Permalink
Fix some assignment to nil map issues
Browse files Browse the repository at this point in the history
updatePipelineRunStatusFromTaskRuns causes panic if the taskruns
map in the pipeline run status is nil.
Add a unit test that reproduces the issue and fix it.

Fixes: #3000
  • Loading branch information
afrittoli authored and tekton-robot committed Jul 24, 2020
1 parent a42de87 commit 7aef61d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,8 @@ func updatePipelineRunStatusFromTaskRuns(logger *zap.SugaredLogger, prName strin
for taskRunName, pipelineRunTaskRunStatus := range prStatus.TaskRuns {
taskRunByPipelineTask[pipelineRunTaskRunStatus.PipelineTaskName] = taskRunName
}
} else {
prStatus.TaskRuns = make(map[string]*v1beta1.PipelineRunTaskRunStatus)
}
// Loop over all the TaskRuns associated to Tasks
for _, taskrun := range trs {
Expand Down
33 changes: 33 additions & 0 deletions pkg/reconciler/pipelinerun/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3161,6 +3161,13 @@ func TestUpdatePipelineRunStatusFromTaskRuns(t *testing.T) {
},
}

prStatusWithEmptyTaskRuns := v1beta1.PipelineRunStatus{
Status: prRunningStatus,
PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
TaskRuns: nil,
},
}

prStatusWithOrphans := v1beta1.PipelineRunStatus{
Status: duckv1beta1.Status{
Conditions: []apis.Condition{
Expand Down Expand Up @@ -3204,6 +3211,18 @@ func TestUpdatePipelineRunStatusFromTaskRuns(t *testing.T) {
},
}

prStatusRecoveredSimple := v1beta1.PipelineRunStatus{
Status: prRunningStatus,
PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{
TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{
"pr-task-1-xxyyy": {
PipelineTaskName: "task-1",
Status: &v1beta1.TaskRunStatus{},
},
},
},
}

allTaskRuns := []*v1beta1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -3269,6 +3288,20 @@ func TestUpdatePipelineRunStatusFromTaskRuns(t *testing.T) {
prStatus: prStatusWithCondition,
trs: nil,
expectedPrStatus: prStatusWithCondition,
}, {
prName: "status-nil-taskruns",
prStatus: prStatusWithEmptyTaskRuns,
trs: []*v1beta1.TaskRun{
{
ObjectMeta: metav1.ObjectMeta{
Name: "pr-task-1-xxyyy",
Labels: map[string]string{
pipeline.GroupName + pipeline.PipelineTaskLabelKey: "task-1",
},
},
},
},
expectedPrStatus: prStatusRecoveredSimple,
}, {
prName: "status-missing-taskruns",
prStatus: prStatusWithCondition,
Expand Down

0 comments on commit 7aef61d

Please sign in to comment.