Skip to content

Commit 2c33641

Browse files
authored
sharder: improve retry behavior with custom rate limiter (#636)
1 parent b51168f commit 2c33641

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

pkg/controller/sharder/add.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@ limitations under the License.
1717
package sharder
1818

1919
import (
20+
"time"
21+
2022
coordinationv1 "k8s.io/api/coordination/v1"
23+
"k8s.io/client-go/util/workqueue"
2124
"k8s.io/utils/clock"
2225
"sigs.k8s.io/controller-runtime/pkg/builder"
2326
"sigs.k8s.io/controller-runtime/pkg/controller"
2427
"sigs.k8s.io/controller-runtime/pkg/handler"
2528
"sigs.k8s.io/controller-runtime/pkg/manager"
2629
"sigs.k8s.io/controller-runtime/pkg/predicate"
30+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
2731

2832
shardingv1alpha1 "github.com/timebertt/kubernetes-controller-sharding/pkg/apis/sharding/v1alpha1"
2933
shardinghandler "github.com/timebertt/kubernetes-controller-sharding/pkg/sharding/handler"
@@ -55,6 +59,11 @@ func (r *Reconciler) AddToManager(mgr manager.Manager) error {
5559
).
5660
WithOptions(controller.Options{
5761
MaxConcurrentReconciles: 5,
62+
// This custom rate limiter differs from the default in these aspects:
63+
// - no overall rate limiting, only per-item rate limiting
64+
// - start at 5s base delay, faster retries are probably wasted load on the API server
65+
// - cap delay at the configured sync period
66+
RateLimiter: workqueue.NewTypedItemExponentialFailureRateLimiter[reconcile.Request](5*time.Second, r.Config.Controller.Sharder.SyncPeriod.Duration),
5867
}).
5968
Complete(r)
6069
}

0 commit comments

Comments
 (0)