diff --git a/controllers/drupalsite_controller.go b/controllers/drupalsite_controller.go index 60916e60ce96a6974e4965695fb7abc7d9f6f475..6bbf2b3ec5fe89a1bc7bda0bb74112d86a81685d 100644 --- a/controllers/drupalsite_controller.go +++ b/controllers/drupalsite_controller.go @@ -34,6 +34,7 @@ import ( appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" + "k8s.io/client-go/util/workqueue" k8sapierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -41,6 +42,7 @@ import ( "k8s.io/apimachinery/pkg/types" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/reconcile" @@ -72,8 +74,10 @@ var ( // DrupalSiteReconciler reconciles a DrupalSite object type DrupalSiteReconciler struct { client.Client - Log logr.Logger - Scheme *runtime.Scheme + Log logr.Logger + Scheme *runtime.Scheme + StartRateLimiterMillis int + MaxRateLimiterSeconds int } // +kubebuilder:rbac:groups=drupal.webservices.cern.ch,resources=drupalsites,verbs=get;list;watch;create;update;patch;delete @@ -100,6 +104,10 @@ type DrupalSiteReconciler struct { // SetupWithManager adds a manager which watches the resources func (r *DrupalSiteReconciler) SetupWithManager(mgr ctrl.Manager) error { + exponentialFailure := workqueue.NewItemExponentialFailureRateLimiter( + time.Millisecond*time.Duration(r.StartRateLimiterMillis), + time.Second*time.Duration(r.MaxRateLimiterSeconds), + ) return ctrl.NewControllerManagedBy(mgr). For(&webservicesv1a1.DrupalSite{}). Owns(&appsv1.Deployment{}). @@ -134,6 +142,9 @@ func (r *DrupalSiteReconciler) SetupWithManager(mgr ctrl.Manager) error { return []reconcile.Request{} }), ). + WithOptions(controller.Options{ + RateLimiter: exponentialFailure, + }). Complete(r) } diff --git a/main.go b/main.go index 0a0c37db8796014396b62857b1fcc808654ccae2..7b8731124aa4627e4a7836faebb3fae231830a83 100644 --- a/main.go +++ b/main.go @@ -105,9 +105,11 @@ func main() { } if err = (&controllers.DrupalSiteReconciler{ - Client: mgr.GetClient(), - Log: ctrl.Log.WithName("controllers").WithName("DrupalSite"), - Scheme: mgr.GetScheme(), + Client: mgr.GetClient(), + Log: ctrl.Log.WithName("controllers").WithName("DrupalSite"), + Scheme: mgr.GetScheme(), + StartRateLimiterMillis: 500, + MaxRateLimiterSeconds: 300, // 5 Minutes }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "DrupalSite") os.Exit(1)