Skip to content

Commit

Permalink
add qps and burst set, edit go version
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuanyiyi committed Oct 14, 2023
1 parent ddcfeb7 commit e3e3764
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand All @@ -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() {
Expand All @@ -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,
Expand All @@ -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()

Expand All @@ -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,
Expand Down Expand Up @@ -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
}
}

0 comments on commit e3e3764

Please sign in to comment.