From 89e80a673ec8f2f0983e1a2dc95e36d783e28a58 Mon Sep 17 00:00:00 2001 From: Garrybest Date: Tue, 3 Aug 2021 16:45:07 +0800 Subject: [PATCH] add qps and burst option Signed-off-by: Garrybest --- cmd/agent/app/agent.go | 3 ++- cmd/agent/app/options/options.go | 12 ++++++++++++ cmd/controller-manager/app/controllermanager.go | 3 ++- cmd/controller-manager/app/options/options.go | 12 ++++++++++++ cmd/scheduler/app/options/options.go | 7 +++++++ cmd/scheduler/app/scheduler.go | 1 + cmd/webhook/app/options/options.go | 6 ++++++ cmd/webhook/app/webhook.go | 2 ++ 8 files changed, 44 insertions(+), 2 deletions(-) diff --git a/cmd/agent/app/agent.go b/cmd/agent/app/agent.go index 78b08d733..c5ced600b 100644 --- a/cmd/agent/app/agent.go +++ b/cmd/agent/app/agent.go @@ -54,6 +54,7 @@ func run(ctx context.Context, karmadaConfig karmadactl.KarmadaConfig, opts *opti if err != nil { return fmt.Errorf("error building kubeconfig of karmada control plane: %s", err.Error()) } + controlPlaneRestConfig.QPS, controlPlaneRestConfig.Burst = opts.KubeAPIQPS, opts.KubeAPIBurst err = registerWithControlPlaneAPIServer(controlPlaneRestConfig, opts.ClusterName) if err != nil { @@ -100,7 +101,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop StopChan: stopChan, ClusterClientSetFunc: util.NewClusterClientSetForAgent, ClusterDynamicClientSetFunc: util.NewClusterDynamicClientSetForAgent, - ClusterClientOption: &util.ClientOption{QPS: 40, Burst: 60}, + ClusterClientOption: &util.ClientOption{QPS: opts.ClusterAPIQPS, Burst: opts.ClusterAPIBurst}, ClusterStatusUpdateFrequency: opts.ClusterStatusUpdateFrequency, ClusterLeaseDuration: opts.ClusterLeaseDuration, ClusterLeaseRenewIntervalFraction: opts.ClusterLeaseRenewIntervalFraction, diff --git a/cmd/agent/app/options/options.go b/cmd/agent/app/options/options.go index 270ab045c..aec98ef2c 100644 --- a/cmd/agent/app/options/options.go +++ b/cmd/agent/app/options/options.go @@ -29,6 +29,14 @@ type Options struct { // ClusterLeaseRenewIntervalFraction is a fraction coordinated with ClusterLeaseDuration that // how long the current holder of a lease has last updated the lease. ClusterLeaseRenewIntervalFraction float64 + // ClusterAPIQPS is the QPS to use while talking with cluster kube-apiserver. + ClusterAPIQPS float32 + // ClusterAPIBurst is the burst to allow while talking with cluster kube-apiserver. + ClusterAPIBurst int + // KubeAPIQPS is the QPS to use while talking with karmada-apiserver. + KubeAPIQPS float32 + // KubeAPIBurst is the burst to allow while talking with karmada-apiserver. + KubeAPIBurst int } // NewOptions builds an default scheduler options. @@ -57,4 +65,8 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { "Specifies the expiration period of a cluster lease.") fs.Float64Var(&o.ClusterLeaseRenewIntervalFraction, "cluster-lease-renew-interval-fraction", 0.25, "Specifies the cluster lease renew interval fraction.") + fs.Float32Var(&o.ClusterAPIQPS, "cluster-api-qps", 40.0, "QPS to use while talking with cluster kube-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") + fs.IntVar(&o.ClusterAPIBurst, "cluster-api-burst", 60, "Burst to use while talking with cluster kube-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") + fs.Float32Var(&o.KubeAPIQPS, "kube-api-qps", 40.0, "QPS to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") + fs.IntVar(&o.KubeAPIBurst, "kube-api-burst", 60, "Burst to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") } diff --git a/cmd/controller-manager/app/controllermanager.go b/cmd/controller-manager/app/controllermanager.go index a42ee6229..b792127ec 100644 --- a/cmd/controller-manager/app/controllermanager.go +++ b/cmd/controller-manager/app/controllermanager.go @@ -64,6 +64,7 @@ func Run(ctx context.Context, opts *options.Options) error { if err != nil { panic(err) } + config.QPS, config.Burst = opts.KubeAPIQPS, opts.KubeAPIBurst controllerManager, err := controllerruntime.NewManager(config, controllerruntime.Options{ Scheme: gclient.NewSchema(), LeaderElection: opts.LeaderElection.LeaderElect, @@ -168,7 +169,7 @@ func setupControllers(mgr controllerruntime.Manager, opts *options.Options, stop StopChan: stopChan, ClusterClientSetFunc: util.NewClusterClientSet, ClusterDynamicClientSetFunc: util.NewClusterDynamicClientSet, - ClusterClientOption: &util.ClientOption{QPS: 40, Burst: 60}, + ClusterClientOption: &util.ClientOption{QPS: opts.ClusterAPIQPS, Burst: opts.ClusterAPIBurst}, ClusterStatusUpdateFrequency: opts.ClusterStatusUpdateFrequency, ClusterLeaseDuration: opts.ClusterLeaseDuration, ClusterLeaseRenewIntervalFraction: opts.ClusterLeaseRenewIntervalFraction, diff --git a/cmd/controller-manager/app/options/options.go b/cmd/controller-manager/app/options/options.go index a9120329a..ecf0a3119 100644 --- a/cmd/controller-manager/app/options/options.go +++ b/cmd/controller-manager/app/options/options.go @@ -52,6 +52,14 @@ type Options struct { ClusterAPIContext string // ClusterAPIKubeconfig holds the cluster-api management cluster KUBECONFIG file path. ClusterAPIKubeconfig string + // ClusterAPIQPS is the QPS to use while talking with cluster kube-apiserver. + ClusterAPIQPS float32 + // ClusterAPIBurst is the burst to allow while talking with cluster kube-apiserver. + ClusterAPIBurst int + // KubeAPIQPS is the QPS to use while talking with karmada-apiserver. + KubeAPIQPS float32 + // KubeAPIBurst is the burst to allow while talking with karmada-apiserver. + KubeAPIBurst int } // NewOptions builds an empty options. @@ -93,4 +101,8 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) { "Comma-separated namespaces that should be skipped from propagating in addition to the default skipped namespaces(namespaces prefixed by kube- and karmada-).") flags.StringVar(&o.ClusterAPIContext, "cluster-api-context", "", "Name of the cluster context in cluster-api management cluster kubeconfig file.") flags.StringVar(&o.ClusterAPIKubeconfig, "cluster-api-kubeconfig", "", "Path to the cluster-api management cluster kubeconfig file.") + flags.Float32Var(&o.ClusterAPIQPS, "cluster-api-qps", 40.0, "QPS to use while talking with cluster kube-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") + flags.IntVar(&o.ClusterAPIBurst, "cluster-api-burst", 60, "Burst to use while talking with cluster kube-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") + flags.Float32Var(&o.KubeAPIQPS, "kube-api-qps", 40.0, "QPS to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") + flags.IntVar(&o.KubeAPIBurst, "kube-api-burst", 60, "Burst to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") } diff --git a/cmd/scheduler/app/options/options.go b/cmd/scheduler/app/options/options.go index f108ee303..58bc38e83 100644 --- a/cmd/scheduler/app/options/options.go +++ b/cmd/scheduler/app/options/options.go @@ -34,6 +34,11 @@ type Options struct { // Failover indicates if scheduler should reschedule on cluster failure. Failover bool + + // KubeAPIQPS is the QPS to use while talking with karmada-apiserver. + KubeAPIQPS float32 + // KubeAPIBurst is the burst to allow while talking with karmada-apiserver. + KubeAPIBurst int } // NewOptions builds an default scheduler options. @@ -63,4 +68,6 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) { fs.StringVar(&o.BindAddress, "bind-address", defaultBindAddress, "The IP address on which to listen for the --secure-port port.") fs.IntVar(&o.SecurePort, "secure-port", defaultPort, "The secure port on which to serve HTTPS.") fs.BoolVar(&o.Failover, "failover", false, "Reschedule on cluster failure.") + fs.Float32Var(&o.KubeAPIQPS, "kube-api-qps", 40.0, "QPS to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") + fs.IntVar(&o.KubeAPIBurst, "kube-api-burst", 60, "Burst to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") } diff --git a/cmd/scheduler/app/scheduler.go b/cmd/scheduler/app/scheduler.go index a12c627b3..e8431b28f 100644 --- a/cmd/scheduler/app/scheduler.go +++ b/cmd/scheduler/app/scheduler.go @@ -49,6 +49,7 @@ func run(opts *options.Options, stopChan <-chan struct{}) error { if err != nil { return fmt.Errorf("error building kubeconfig: %s", err.Error()) } + restConfig.QPS, restConfig.Burst = opts.KubeAPIQPS, opts.KubeAPIBurst dynamicClientSet := dynamic.NewForConfigOrDie(restConfig) karmadaClient := karmadaclientset.NewForConfigOrDie(restConfig) diff --git a/cmd/webhook/app/options/options.go b/cmd/webhook/app/options/options.go index e66b78c52..db4993f9a 100644 --- a/cmd/webhook/app/options/options.go +++ b/cmd/webhook/app/options/options.go @@ -22,6 +22,10 @@ type Options struct { // if not set, webhook server would look up the server key and certificate in {TempDir}/k8s-webhook-server/serving-certs. // The server key and certificate must be named `tls.key` and `tls.crt`, respectively. CertDir string + // KubeAPIQPS is the QPS to use while talking with karmada-apiserver. + KubeAPIQPS float32 + // KubeAPIBurst is the burst to allow while talking with karmada-apiserver. + KubeAPIBurst int } // NewOptions builds an empty options. @@ -37,4 +41,6 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) { "The secure port on which to serve HTTPS.") flags.StringVar(&o.CertDir, "cert-dir", defaultCertDir, "The directory that contains the server key(named tls.key) and certificate(named tls.crt).") + flags.Float32Var(&o.KubeAPIQPS, "kube-api-qps", 40.0, "QPS to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") + flags.IntVar(&o.KubeAPIBurst, "kube-api-burst", 60, "Burst to use while talking with karmada-apiserver. Doesn't cover events and node heartbeat apis which rate limiting is controlled by a different set of flags.") } diff --git a/cmd/webhook/app/webhook.go b/cmd/webhook/app/webhook.go index 3e4664be5..41206d26b 100644 --- a/cmd/webhook/app/webhook.go +++ b/cmd/webhook/app/webhook.go @@ -49,6 +49,8 @@ func Run(ctx context.Context, opts *options.Options) error { if err != nil { panic(err) } + config.QPS, config.Burst = opts.KubeAPIQPS, opts.KubeAPIBurst + hookManager, err := controllerruntime.NewManager(config, controllerruntime.Options{ Scheme: gclient.NewSchema(), Host: opts.BindAddress,