From 47787133ea8a547763d70d4d4b7159295dff5bb4 Mon Sep 17 00:00:00 2001 From: Mangirdas Judeikis Date: Fri, 8 Sep 2023 14:07:58 +0300 Subject: [PATCH] Split clients for rate limit (#83) * split clients for rate limit --------- Co-authored-by: Mangirdas --- main.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index c31e0246..c49fb83a 100644 --- a/main.go +++ b/main.go @@ -109,7 +109,12 @@ func run( if err != nil { return err } + restConfigLeader := rest.CopyConfig(restconfig) + restConfigDynamic := rest.CopyConfig(restconfig) + restconfig.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(float32(cfg.KubeClient.QPS), cfg.KubeClient.Burst) + restConfigLeader.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(float32(cfg.KubeClient.QPS), cfg.KubeClient.Burst) + restConfigDynamic.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(float32(cfg.KubeClient.QPS), cfg.KubeClient.Burst) helmClient := helm.NewClient(logger, helm.NewChartLoader(), restconfig) @@ -117,8 +122,12 @@ func run( if err != nil { return err } + clientSetLeader, err := kubernetes.NewForConfig(restConfigLeader) + if err != nil { + return err + } - dynamicClient, err := dynamic.NewForConfig(restconfig) + dynamicClient, err := dynamic.NewForConfig(restConfigDynamic) if err != nil { return err } @@ -190,7 +199,7 @@ func run( if cfg.LeaderElection.Enabled { // Run actions service with leader election. Blocks. - return runWithLeaderElection(ctx, log, clientset, leaderHealthCheck, cfg.LeaderElection, svc.Run) + return runWithLeaderElection(ctx, log, clientSetLeader, leaderHealthCheck, cfg.LeaderElection, svc.Run) } // Run action service. Blocks.