Skip to content

Commit

Permalink
feat(controller): add recovery (#249)
Browse files Browse the repository at this point in the history
add recovery

Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
yaroslavborbat authored Aug 1, 2024
1 parent 61e4ab8 commit 4d6bff1
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -71,7 +72,7 @@ func NewController(
internal.NewAttacheeHandler(mgr.GetClient()),
)

cviController, err := controller.New(ControllerName, mgr, controller.Options{Reconciler: reconciler})
cviController, err := controller.New(ControllerName, mgr, controller.Options{Reconciler: reconciler, RecoverPanic: ptr.To(true)})
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -82,7 +83,7 @@ func NewController(
internal.NewStatsHandler(stat, importer, uploader),
)

vdController, err := controller.New(ControllerName, mgr, controller.Options{Reconciler: reconciler})
vdController, err := controller.New(ControllerName, mgr, controller.Options{Reconciler: reconciler, RecoverPanic: ptr.To(true)})
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -70,7 +71,7 @@ func NewController(
internal.NewAttacheeHandler(mgr.GetClient()),
)

viController, err := controller.New(ControllerName, mgr, controller.Options{Reconciler: reconciler})
viController, err := controller.New(ControllerName, mgr, controller.Options{Reconciler: reconciler, RecoverPanic: ptr.To(true)})
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"log/slog"

"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -65,7 +66,7 @@ func NewController(
}
r := NewReconciler(client, logger, handlers...)

c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r})
c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r, RecoverPanic: ptr.To(true)})
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"log/slog"

"github.com/go-logr/logr"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -54,7 +55,7 @@ func NewController(
internal.NewDeletionHandler(),
)

vmbdaController, err := controller.New(ControllerName, mgr, controller.Options{Reconciler: reconciler})
vmbdaController, err := controller.New(ControllerName, mgr, controller.Options{Reconciler: reconciler, RecoverPanic: ptr.To(true)})
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"log/slog"

"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"

Expand Down Expand Up @@ -49,7 +50,7 @@ func NewController(
}
r := NewReconciler(client, logger, handlers...)

c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r})
c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r, RecoverPanic: ptr.To(true)})
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"

"github.com/go-logr/logr"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -55,7 +56,7 @@ func NewController(
return nil, err
}

c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r})
c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r, RecoverPanic: ptr.To(true)})
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/go-logr/logr"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -54,7 +55,7 @@ func NewController(

r := NewReconciler(mgr.GetClient(), log, handlers...)

c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r})
c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r, RecoverPanic: ptr.To(true)})
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/go-logr/logr"
"k8s.io/client-go/util/workqueue"
"k8s.io/utils/ptr"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand Down Expand Up @@ -53,8 +54,9 @@ func NewController(
})

c, err := controller.New(controllerName, mgr, controller.Options{
Reconciler: reconcilerCore,
RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(time.Second, 32*time.Second),
Reconciler: reconcilerCore,
RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(time.Second, 32*time.Second),
RecoverPanic: ptr.To(true),
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 4d6bff1

Please sign in to comment.