Skip to content

Commit

Permalink
Merge pull request #1810 from sbueringer/pr-log-panic
Browse files Browse the repository at this point in the history
馃尡 log panic in reconcile even if panic should not be recovered
  • Loading branch information
k8s-ci-robot committed Feb 22, 2022
2 parents f62a0f5 + f99e395 commit ce8bdd3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,21 @@ type watchDescription struct {

// Reconcile implements reconcile.Reconciler.
func (c *Controller) Reconcile(ctx context.Context, req reconcile.Request) (_ reconcile.Result, err error) {
if c.RecoverPanic {
defer func() {
if r := recover(); r != nil {
log := c.Log.WithValues("name", req.Name, "namespace", req.Namespace)
defer func() {
if r := recover(); r != nil {
if c.RecoverPanic {
for _, fn := range utilruntime.PanicHandlers {
fn(r)
}
err = fmt.Errorf("panic: %v [recovered]", r)
return
}
}()
}
log := c.Log.WithValues("name", req.Name, "namespace", req.Namespace)

log.Info(fmt.Sprintf("Observed a panic in reconciler: %v", r))
panic(r)
}
}()
ctx = logf.IntoContext(ctx, log)
return c.Do.Reconcile(ctx, req)
}
Expand Down

0 comments on commit ce8bdd3

Please sign in to comment.