Skip to content

Commit 84893a8

Browse files
committed
karmada-search: wire cluster-api-qps and cluster-api-burst
Signed-off-by: manmathbh <manmathcode@gmail.com> search: rename clientOption to clusterClientOption Signed-off-by: manmathbh <manmathcode@gmail.com> search: format controller for gci lint Signed-off-by: manmathbh <manmathcode@gmail.com>
1 parent 3424bc7 commit 84893a8

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

cmd/karmada-search/app/karmada-search.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import (
5454
"github.com/karmada-io/karmada/pkg/sharedcli"
5555
"github.com/karmada-io/karmada/pkg/sharedcli/klogflag"
5656
"github.com/karmada-io/karmada/pkg/sharedcli/profileflag"
57+
"github.com/karmada-io/karmada/pkg/util"
5758
"github.com/karmada-io/karmada/pkg/util/lifted"
5859
"github.com/karmada-io/karmada/pkg/util/names"
5960
"github.com/karmada-io/karmada/pkg/version"
@@ -211,10 +212,12 @@ func config(o *options.Options, outOfTreeRegistryOptions ...Option) (*search.Con
211212

212213
karmadaClient := karmadaclientset.NewForConfigOrDie(serverConfig.ClientConfig)
213214
factory := informerfactory.NewSharedInformerFactory(karmadaClient, 0)
215+
rateLimiterGetter := util.GetClusterRateLimiterGetter().SetDefaultLimits(o.ClusterAPIQPS, o.ClusterAPIBurst)
216+
clusterClientOption := &util.ClientOption{RateLimiterGetter: rateLimiterGetter.GetRateLimiter}
214217

215218
var ctl *search.Controller
216219
if !o.DisableSearch {
217-
ctl, err = search.NewController(serverConfig.ClientConfig, factory, restMapper)
220+
ctl, err = search.NewController(serverConfig.ClientConfig, factory, restMapper, clusterClientOption)
218221
if err != nil {
219222
return nil, err
220223
}

cmd/karmada-search/app/options/options.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ type Options struct {
4747
KubeAPIQPS float32
4848
// KubeAPIBurst is the burst to allow while talking with karmada-search.
4949
KubeAPIBurst int
50+
// ClusterAPIQPS is the QPS to use while talking with cluster kube-apiserver.
51+
ClusterAPIQPS float32
52+
// ClusterAPIBurst is the burst to allow while talking with cluster kube-apiserver.
53+
ClusterAPIBurst int
5054

5155
ProfileOpts profileflag.Options
5256

@@ -86,6 +90,8 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
8690

8791
flags.Float32Var(&o.KubeAPIQPS, "kube-api-qps", 40.0, "QPS to use while talking with karmada-apiserver.")
8892
flags.IntVar(&o.KubeAPIBurst, "kube-api-burst", 60, "Burst to use while talking with karmada-apiserver.")
93+
flags.Float32Var(&o.ClusterAPIQPS, "cluster-api-qps", 40.0, "QPS to use while talking with cluster kube-apiserver.")
94+
flags.IntVar(&o.ClusterAPIBurst, "cluster-api-burst", 60, "Burst to use while talking with cluster kube-apiserver.")
8995
flags.BoolVar(&o.DisableSearch, "disable-search", false, "Disable search feature that would save memory usage significantly.")
9096
flags.BoolVar(&o.DisableProxy, "disable-proxy", false, "Disable proxy feature that would save memory usage significantly.")
9197

pkg/search/controller.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,30 @@ func (c *clusterRegistry) unregistry() bool {
6464

6565
// Controller ResourceRegistry controller
6666
type Controller struct {
67-
restConfig *rest.Config
68-
restMapper meta.RESTMapper
69-
informerFactory informerfactory.SharedInformerFactory
70-
clusterLister clusterlister.ClusterLister
71-
queue workqueue.TypedRateLimitingInterface[any]
67+
restConfig *rest.Config
68+
restMapper meta.RESTMapper
69+
informerFactory informerfactory.SharedInformerFactory
70+
clusterLister clusterlister.ClusterLister
71+
queue workqueue.TypedRateLimitingInterface[any]
72+
clusterClientOption *util.ClientOption
7273

7374
clusterRegistry sync.Map
7475

7576
InformerManager genericmanager.MultiClusterInformerManager
7677
}
7778

7879
// NewController returns a new ResourceRegistry controller
79-
func NewController(restConfig *rest.Config, factory informerfactory.SharedInformerFactory, restMapper meta.RESTMapper) (*Controller, error) {
80+
func NewController(restConfig *rest.Config, factory informerfactory.SharedInformerFactory, restMapper meta.RESTMapper, clusterClientOption *util.ClientOption) (*Controller, error) {
8081
clusterLister := factory.Cluster().V1alpha1().Clusters().Lister()
8182
queue := workqueue.NewTypedRateLimitingQueue[any](workqueue.DefaultTypedControllerRateLimiter[any]())
8283

8384
c := &Controller{
84-
restConfig: restConfig,
85-
informerFactory: factory,
86-
clusterLister: clusterLister,
87-
queue: queue,
88-
restMapper: restMapper,
85+
restConfig: restConfig,
86+
informerFactory: factory,
87+
clusterLister: clusterLister,
88+
queue: queue,
89+
clusterClientOption: clusterClientOption,
90+
restMapper: restMapper,
8991

9092
InformerManager: genericmanager.GetInstance(),
9193
}
@@ -348,9 +350,8 @@ func (c *Controller) getRegistryBackendHandler(cluster string, matchedRegistries
348350
return handler, nil
349351
}
350352

351-
var clusterDynamicClientBuilder = func(cluster string, controlPlaneClient client.Client) (*util.DynamicClusterClient, error) {
352-
// TODO: Add "--cluster-api-qps" and "--cluster-api-burst" flags to karmada-search and pass them via clientOption, instead of passing a "nil" here
353-
return util.NewClusterDynamicClientSet(cluster, controlPlaneClient, nil)
353+
var clusterDynamicClientBuilder = func(cluster string, controlPlaneClient client.Client, clusterClientOption *util.ClientOption) (*util.DynamicClusterClient, error) {
354+
return util.NewClusterDynamicClientSet(cluster, controlPlaneClient, clusterClientOption)
354355
}
355356

356357
// doCacheCluster processes the resourceRegistry object
@@ -392,7 +393,7 @@ func (c *Controller) doCacheCluster(cluster string) error {
392393
klog.Info("Try to build informer manager for cluster ", cluster)
393394
controlPlaneClient := gclient.NewForConfigOrDie(c.restConfig)
394395

395-
clusterDynamicClient, err := clusterDynamicClientBuilder(cluster, controlPlaneClient)
396+
clusterDynamicClient, err := clusterDynamicClientBuilder(cluster, controlPlaneClient, c.clusterClientOption)
396397
if err != nil {
397398
return err
398399
}

pkg/search/controllers_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestNewKarmadaSearchController(t *testing.T) {
105105
if err := test.prep(&test.factory, test.client); err != nil {
106106
t.Fatalf("failed to prep test environment before creating new controller, got: %v", err)
107107
}
108-
_, err := NewController(test.restConfig, test.factory, test.restMapper)
108+
_, err := NewController(test.restConfig, test.factory, test.restMapper, nil)
109109
if err == nil && test.wantErr {
110110
t.Fatal("expected an error, but got none")
111111
}
@@ -270,7 +270,7 @@ func TestDeleteClusterEventHandler(t *testing.T) {
270270
}
271271
)
272272

273-
clusterDynamicClientBuilder = func(string, client.Client) (*util.DynamicClusterClient, error) {
273+
clusterDynamicClientBuilder = func(string, client.Client, *util.ClientOption) (*util.DynamicClusterClient, error) {
274274
return &util.DynamicClusterClient{
275275
DynamicClientSet: fakedynamic.NewSimpleDynamicClient(scheme.Scheme),
276276
ClusterName: clusterName,
@@ -359,7 +359,7 @@ func TestAddResourceRegistryEventHandler(t *testing.T) {
359359
}
360360
)
361361

362-
clusterDynamicClientBuilder = func(string, client.Client) (*util.DynamicClusterClient, error) {
362+
clusterDynamicClientBuilder = func(string, client.Client, *util.ClientOption) (*util.DynamicClusterClient, error) {
363363
return &util.DynamicClusterClient{
364364
DynamicClientSet: fakedynamic.NewSimpleDynamicClient(scheme.Scheme),
365365
ClusterName: clusterName,
@@ -445,7 +445,7 @@ func TestUpdateResourceRegistryEventHandler(t *testing.T) {
445445
}
446446
)
447447

448-
clusterDynamicClientBuilder = func(string, client.Client) (*util.DynamicClusterClient, error) {
448+
clusterDynamicClientBuilder = func(string, client.Client, *util.ClientOption) (*util.DynamicClusterClient, error) {
449449
return &util.DynamicClusterClient{
450450
DynamicClientSet: fakedynamic.NewSimpleDynamicClient(scheme.Scheme),
451451
ClusterName: clusterName,
@@ -529,7 +529,7 @@ func TestDeleteResourceRegistryEventHandler(t *testing.T) {
529529
}
530530
)
531531

532-
clusterDynamicClientBuilder = func(string, client.Client) (*util.DynamicClusterClient, error) {
532+
clusterDynamicClientBuilder = func(string, client.Client, *util.ClientOption) (*util.DynamicClusterClient, error) {
533533
return &util.DynamicClusterClient{
534534
DynamicClientSet: fakedynamic.NewSimpleDynamicClient(scheme.Scheme),
535535
ClusterName: clusterName,
@@ -585,7 +585,7 @@ func TestDeleteResourceRegistryEventHandler(t *testing.T) {
585585
// Kubernetes REST configuration, shared informer factory, and REST mapper.
586586
// It returns the created Controller or an error if initialization fails.
587587
func createController(ctx context.Context, restConfig *rest.Config, factory informerfactory.SharedInformerFactory, restMapper meta.RESTMapper) (*Controller, error) {
588-
newController, err := NewController(restConfig, factory, restMapper)
588+
newController, err := NewController(restConfig, factory, restMapper, nil)
589589
if err != nil {
590590
return nil, fmt.Errorf("failed to create new controller, got: %v", err)
591591
}

0 commit comments

Comments
 (0)