From c25d4ea107bc40f75f801fe20cdcb9ca33ee68c0 Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Tue, 6 Oct 2020 09:33:16 +0200 Subject: [PATCH] Allow override QPS and Burst via flag. Add `--kube-api-qps` and `--kube-api-burst` command-line flags to control client QPS and Burst respectively. The default value is set to 0 to keep backward compatibility. Signed-off-by: Pierangelo Di Pilato --- injection/sharedmain/main.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/injection/sharedmain/main.go b/injection/sharedmain/main.go index 33d45391e2..dcd8dc33b3 100644 --- a/injection/sharedmain/main.go +++ b/injection/sharedmain/main.go @@ -21,6 +21,7 @@ import ( "errors" "flag" "log" + "math" "net/http" "os" "os/user" @@ -323,6 +324,9 @@ func ParseAndGetConfigOrDie() *rest.Config { "The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.") kubeconfig = flag.String("kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.") + + burst = flag.Int("kube-api-burst", 0, "Maximum burst for throttle.") + qps = flag.Float64("kube-api-qps", 0, "Maximum QPS to the server from the client.") ) klog.InitFlags(flag.CommandLine) flag.Parse() @@ -332,9 +336,27 @@ func ParseAndGetConfigOrDie() *rest.Config { log.Fatal("Error building kubeconfig: ", err) } + validBurstOrDie(*burst) + validQPSOrDie(*qps) + + cfg.Burst = *burst + cfg.QPS = float32(*qps) + return cfg } +func validBurstOrDie(burst int) { + if burst < 0 { + log.Fatal("Invalid burst value", burst) + } +} + +func validQPSOrDie(qps float64) { + if qps < 0 || qps > math.MaxFloat32 { + log.Fatal("Invalid QPS value", qps) + } +} + // MemStatsOrDie sets up reporting on Go memory usage every 30 seconds or dies // by calling log.Fatalf. func MemStatsOrDie(ctx context.Context) {