core: log panics in controller reconcile functions
add RecoverAndLogException() helper to log panics with stack trace.
added defer call in all rook controller Reconcile() methods for
better error visibility in operator logs
Signed-off-by: Oded Viner <oviner@redhat.com>
(cherry picked from commit cf13deee6f)
This commit is contained in:
1 parent
af05d4b16f
commit
ee0bae1a6c
24 files changed
+33
No files matched your search
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime/debug"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -281,3 +282,11 @@ var ClusterResource = k8sutil.CustomResource{
|
||||
Kind: reflect.TypeOf(cephv1.CephCluster{}).Name(),
|
||||
APIVersion: fmt.Sprintf("%s/%s", cephv1.CustomResourceGroup, cephv1.Version),
|
||||
}
|
||||
|
||||
// RecoverAndLogException handles and logs panics from a controller Reconcile loop.
|
||||
func RecoverAndLogException() {
|
||||
if r := recover(); r != nil {
|
||||
logger.Errorf("Panic: %v", r)
|
||||
logger.Errorf("Stack trace:\n%s", string(debug.Stack()))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user