Skip to content

Commit

Permalink
chore: Add Rate limiter for Hash and Status Controller (#6043)
Browse files Browse the repository at this point in the history
  • Loading branch information
engedaam authored Apr 16, 2024
1 parent 723bbdc commit b64305c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion pkg/controllers/nodeclass/hash/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion pkg/controllers/nodeclass/status/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
}))
}

0 comments on commit b64305c

Please sign in to comment.