Skip to content

Commit

Permalink
Fix the panic when there is no error in a reconciler (#132)
Browse files Browse the repository at this point in the history
Made the false assumption that the length of the slice of errors
would be at least one. This caused a panic when no errors occurred.
So, remove the slice, and just save off the first error.

Signed-off-by: Brad P. Crochet <brad@redhat.com>
  • Loading branch information
bcrochet authored Apr 29, 2022
1 parent 61505f9 commit 09f8997
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions controllers/operatorpipeline_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,20 @@ func (r *OperatorPipelineReconciler) Reconcile(ctx context.Context, req ctrl.Req
}

requeueResult := false
errResult := make([]error, 0, len(resourceReconcilers))
var errResult error = nil
pipeline := currentPipeline.DeepCopy()
for _, r := range resourceReconcilers {
requeue, err := r.Reconcile(ctx, pipeline)
if err != nil {
if err != nil && errResult == nil {
// Only capture the first error
log.Error(err, "requeuing with error")
requeueResult = true
errResult = append(errResult, err)
continue
errResult = err
}
requeueResult = requeueResult || requeue
}

// Just return the first error reported. It's the most likely issue that needs to be solved.
return ctrl.Result{Requeue: requeueResult}, errResult[0]
return ctrl.Result{Requeue: requeueResult}, errResult
}

// SetupWithManager sets up the controller with the Manager.
Expand Down

0 comments on commit 09f8997

Please sign in to comment.