diff --git a/pkg/controllers/nodeclass/hash/controller.go b/pkg/controllers/nodeclass/hash/controller.go index 8cc70c28c7bb..2242aca5db23 100644 --- a/pkg/controllers/nodeclass/hash/controller.go +++ b/pkg/controllers/nodeclass/hash/controller.go @@ -16,10 +16,13 @@ package hash import ( "context" + "time" "github.com/samber/lo" "go.uber.org/multierr" + "golang.org/x/time/rate" "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/client-go/util/workqueue" controllerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -74,7 +77,14 @@ func (c *Controller) Builder(_ context.Context, m manager.Manager) corecontrolle return corecontroller.Adapt(controllerruntime. NewControllerManagedBy(m). For(&v1beta1.EC2NodeClass{}). - WithOptions(controller.Options{MaxConcurrentReconciles: 10})) + WithOptions(controller.Options{ + RateLimiter: workqueue.NewMaxOfRateLimiter( + workqueue.NewItemExponentialFailureRateLimiter(100*time.Millisecond, 1*time.Minute), + // 10 qps, 100 bucket size + &workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)}, + ), + MaxConcurrentReconciles: 10, + })) } // Updating `ec2nodeclass-hash-version` annotation inside the karpenter controller means a breaking change has been made to the hash calculation. diff --git a/pkg/controllers/nodeclass/status/controller.go b/pkg/controllers/nodeclass/status/controller.go index e39981d9f510..da4aeca04dc0 100644 --- a/pkg/controllers/nodeclass/status/controller.go +++ b/pkg/controllers/nodeclass/status/controller.go @@ -16,9 +16,12 @@ package status import ( "context" + "time" "go.uber.org/multierr" + "golang.org/x/time/rate" "k8s.io/apimachinery/pkg/api/equality" + "k8s.io/client-go/util/workqueue" controllerruntime "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -109,5 +112,12 @@ func (c *Controller) Builder(_ context.Context, m manager.Manager) corecontrolle return corecontroller.Adapt(controllerruntime. NewControllerManagedBy(m). For(&v1beta1.EC2NodeClass{}). - WithOptions(controller.Options{MaxConcurrentReconciles: 10})) + WithOptions(controller.Options{ + RateLimiter: workqueue.NewMaxOfRateLimiter( + workqueue.NewItemExponentialFailureRateLimiter(100*time.Millisecond, 1*time.Minute), + // 10 qps, 100 bucket size + &workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)}, + ), + MaxConcurrentReconciles: 10, + })) }