diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index c02ff10c..3789e2f4 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -39,6 +39,8 @@ spec: args: - --leader-elect=false - --provider-config=/etc/kruise-game/config.toml + - --api-server-qps=5 + - --api-server-qps-burst=10 image: controller:latest name: manager env: diff --git a/main.go b/main.go index 0495414d..1355149d 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,7 @@ import ( "github.com/openkruise/kruise-game/pkg/metrics" "github.com/openkruise/kruise-game/pkg/webhook" "google.golang.org/grpc" + "k8s.io/client-go/rest" "net" "os" "time" @@ -53,6 +54,8 @@ import ( var ( scheme = runtime.NewScheme() setupLog = ctrl.Log.WithName("setup") + + apiServerSustainedQPSFlag, apiServerBurstQPSFlag int ) func init() { @@ -82,6 +85,8 @@ func main() { "Namespace if specified restricts the manager's cache to watch objects in the desired namespace. Defaults to all namespaces.") flag.StringVar(&syncPeriodStr, "sync-period", "", "Determines the minimum frequency at which watched resources are reconciled.") flag.StringVar(&scaleServerAddr, "scale-server-bind-address", ":6000", "The address the scale server endpoint binds to.") + flag.IntVar(&apiServerSustainedQPSFlag, "api-server-qps", 0, "Maximum sustained queries per second to send to the API server") + flag.IntVar(&apiServerBurstQPSFlag, "api-server-qps-burst", 0, "Maximum burst queries per second to send to the API server") // Add cloud provider flags cloudprovider.InitCloudProviderFlags() @@ -106,6 +111,7 @@ func main() { } restConfig := ctrl.GetConfigOrDie() + setRestConfig(restConfig) mgr, err := ctrl.NewManager(restConfig, ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsAddr, @@ -205,3 +211,12 @@ func main() { os.Exit(1) } } + +func setRestConfig(c *rest.Config) { + if apiServerSustainedQPSFlag > 0 { + c.QPS = float32(apiServerSustainedQPSFlag) + } + if apiServerBurstQPSFlag > 0 { + c.Burst = apiServerBurstQPSFlag + } +}