From 0fdcf7fe6d75b893b7fedf754eecede0b6c0eeeb Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Wed, 10 Aug 2022 09:59:19 +0100 Subject: [PATCH] Enable RecoverPanic The controller-runtime provides the ability to recover from panics that have arisen from a reconciliation. This change enables this functionality by default. Signed-off-by: Paulo Gomes --- controllers/imageupdateautomation_controller.go | 2 ++ main.go | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/controllers/imageupdateautomation_controller.go b/controllers/imageupdateautomation_controller.go index 497da1c3..a9177abd 100644 --- a/controllers/imageupdateautomation_controller.go +++ b/controllers/imageupdateautomation_controller.go @@ -96,6 +96,7 @@ type ImageUpdateAutomationReconciler struct { type ImageUpdateAutomationReconcilerOptions struct { MaxConcurrentReconciles int RateLimiter ratelimiter.RateLimiter + RecoverPanic bool } // +kubebuilder:rbac:groups=image.toolkit.fluxcd.io,resources=imageupdateautomations,verbs=get;list;watch;create;update;patch;delete @@ -443,6 +444,7 @@ func (r *ImageUpdateAutomationReconciler) SetupWithManager(mgr ctrl.Manager, opt WithOptions(controller.Options{ MaxConcurrentReconciles: opts.MaxConcurrentReconciles, RateLimiter: opts.RateLimiter, + RecoverPanic: opts.RecoverPanic, }). Complete(r) } diff --git a/main.go b/main.go index 886482b1..3860aa64 100644 --- a/main.go +++ b/main.go @@ -50,7 +50,12 @@ import ( "github.com/fluxcd/image-automation-controller/controllers" ) -const controllerName = "image-automation-controller" +const ( + controllerName = "image-automation-controller" + + // recoverPanic indicates whether panic caused by reconciles should be recovered. + recoverPanic = true +) var ( scheme = runtime.NewScheme() @@ -155,6 +160,7 @@ func main() { }).SetupWithManager(mgr, controllers.ImageUpdateAutomationReconcilerOptions{ MaxConcurrentReconciles: concurrent, RateLimiter: helper.GetRateLimiter(rateLimiterOptions), + RecoverPanic: recoverPanic, }); err != nil { setupLog.Error(err, "unable to create controller", "controller", "ImageUpdateAutomation") os.Exit(1)