Skip to content

Commit ce8bdd3

Browse files
authored
Merge pull request #1810 from sbueringer/pr-log-panic
🌱 log panic in reconcile even if panic should not be recovered
2 parents f62a0f5 + f99e395 commit ce8bdd3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pkg/internal/controller/controller.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,21 @@ type watchDescription struct {
9999

100100
// Reconcile implements reconcile.Reconciler.
101101
func (c *Controller) Reconcile(ctx context.Context, req reconcile.Request) (_ reconcile.Result, err error) {
102-
if c.RecoverPanic {
103-
defer func() {
104-
if r := recover(); r != nil {
102+
log := c.Log.WithValues("name", req.Name, "namespace", req.Namespace)
103+
defer func() {
104+
if r := recover(); r != nil {
105+
if c.RecoverPanic {
105106
for _, fn := range utilruntime.PanicHandlers {
106107
fn(r)
107108
}
108109
err = fmt.Errorf("panic: %v [recovered]", r)
110+
return
109111
}
110-
}()
111-
}
112-
log := c.Log.WithValues("name", req.Name, "namespace", req.Namespace)
112+
113+
log.Info(fmt.Sprintf("Observed a panic in reconciler: %v", r))
114+
panic(r)
115+
}
116+
}()
113117
ctx = logf.IntoContext(ctx, log)
114118
return c.Do.Reconcile(ctx, req)
115119
}

0 commit comments

Comments
 (0)