From e3e376495cbd3893b75b96d4fe87fde97a50a960 Mon Sep 17 00:00:00 2001 From: yuanyi <344476153@qq.com> Date: Sun, 8 Oct 2023 09:10:15 +0800 Subject: [PATCH] add qps and burst set, edit go version --- config/manager/manager.yaml | 4 ++++ go.mod | 2 +- main.go | 38 +++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index c02ff10c..5f00d4c4 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -46,6 +46,10 @@ spec: value: "60" - name: "NETWORK_PROBE_INTERVAL_TIME" value: "5" + - name: "API_SERVER_QPS" + value: "10" + - name: "API_SERVER_QPS_BURST" + value: "20" ports: - name: https containerPort: 8080 diff --git a/go.mod b/go.mod index 10a3e4bb..96cc9b1a 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.18.1 github.com/openkruise/kruise-api v1.3.0 + github.com/prometheus/client_golang v1.12.1 google.golang.org/grpc v1.40.0 google.golang.org/protobuf v1.27.1 k8s.io/api v0.24.0 @@ -57,7 +58,6 @@ require ( github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/nxadm/tail v1.4.8 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/prometheus/client_golang v1.12.1 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect github.com/prometheus/procfs v0.7.3 // indirect diff --git a/main.go b/main.go index 0495414d..ce45ad7d 100644 --- a/main.go +++ b/main.go @@ -29,8 +29,10 @@ 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" + "strconv" "time" // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) @@ -50,9 +52,17 @@ import ( //+kubebuilder:scaffold:imports ) +const ( + apiServerQps = "API_SERVER_QPS" + apiServerBurst = "API_SERVER_QPS_BURST" +) + var ( scheme = runtime.NewScheme() setupLog = ctrl.Log.WithName("setup") + + apiServerSustainedQPSFlag = flag.Int(apiServerQps, 0, "Maximum sustained queries per second to send to the API server") + apiServerBurstQPSFlag = flag.Int(apiServerBurst, 0, "Maximum burst queries per second to send to the API server") ) func init() { @@ -73,6 +83,7 @@ func main() { var namespace string var syncPeriodStr string var scaleServerAddr string + flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.") flag.StringVar(&probeAddr, "health-probe-bind-address", ":8082", "The address the probe endpoint binds to.") flag.BoolVar(&enableLeaderElection, "leader-elect", false, @@ -83,6 +94,7 @@ func main() { 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.") + getEnvConfig() // Add cloud provider flags cloudprovider.InitCloudProviderFlags() @@ -106,6 +118,8 @@ func main() { } restConfig := ctrl.GetConfigOrDie() + // set qps and burst + setRestConfig(restConfig) mgr, err := ctrl.NewManager(restConfig, ctrl.Options{ Scheme: scheme, MetricsBindAddress: metricsAddr, @@ -205,3 +219,27 @@ func main() { os.Exit(1) } } + +func getEnvConfig() { + if qpsStr := os.Getenv(apiServerQps); qpsStr != "" { + num, err := strconv.Atoi(qpsStr) + if err == nil { + *apiServerSustainedQPSFlag = num + } + } + if burstStr := os.Getenv(apiServerBurst); burstStr != "" { + num, err := strconv.Atoi(burstStr) + if err == nil { + *apiServerBurstQPSFlag = num + } + } +} + +func setRestConfig(c *rest.Config) { + if *apiServerSustainedQPSFlag > 0 { + c.QPS = float32(*apiServerSustainedQPSFlag) + } + if *apiServerBurstQPSFlag > 0 { + c.Burst = *apiServerBurstQPSFlag + } +}