Skip to content

Commit

Permalink
Metrics: Nil Derefence when TR/PR not found
Browse files Browse the repository at this point in the history
We derefence a nil pointer when TR/PR is not found or
somehow taskrun or pipelinerun pointer is nil.
  • Loading branch information
khrm committed Aug 29, 2022
1 parent 31644db commit a5f9958
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/reconciler/pipelinerun/pipelinerun.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ func (c *Reconciler) durationAndCountMetrics(ctx context.Context, pr *v1beta1.Pi
if err != nil && !kerrors.IsNotFound(err) {
logger.Errorf("Error getting PipelineRun %s when updating metrics: %w", pr.Name, err)
return
} else if kerrors.IsNotFound(err) {
} else if kerrors.IsNotFound(err) || newPr == nil {
logger.Debugf("Pipelinerun %s not found when updating metrics: %w", pr.Name, err)
return
}

before := newPr.Status.GetCondition(apis.ConditionSucceeded)
Expand Down
3 changes: 2 additions & 1 deletion pkg/reconciler/taskrun/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ func (c *Reconciler) durationAndCountMetrics(ctx context.Context, tr *v1beta1.Ta
if err != nil && !k8serrors.IsNotFound(err) {
logger.Errorf("Error getting TaskRun %s when updating metrics: %w", tr.Name, err)
return
} else if k8serrors.IsNotFound(err) {
} else if k8serrors.IsNotFound(err) || newTr == nil {
logger.Debugf("TaskRun %s not found when updating metrics: %w", tr.Name, err)
return
}

before := newTr.Status.GetCondition(apis.ConditionSucceeded)
Expand Down

0 comments on commit a5f9958

Please sign in to comment.