From d949ba6806a477c4034e0ce6160da4660f0c021b Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Mon, 23 Sep 2024 15:57:20 -0700 Subject: [PATCH] Add ability to configure QPS and Burst for go-client Signed-off-by: James Sturtevant --- admission-webhook/main.go | 38 +++++++++++++++++++-------- charts/gmsa/templates/deployment.yaml | 4 +++ charts/gmsa/values.yaml | 2 ++ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/admission-webhook/main.go b/admission-webhook/main.go index c04a4dd0..fb6a99ab 100644 --- a/admission-webhook/main.go +++ b/admission-webhook/main.go @@ -29,10 +29,7 @@ func main() { keyPath: env("TLS_KEY"), } - port, err := port("HTTPS_PORT") - if err != nil { - panic(err) - } + port := env_int("HTTPS_PORT", 443) if err = webhook.start(port, tlsConfig, nil); err != nil { panic(err) @@ -83,19 +80,38 @@ func createKubeClient() (*kubeClient, error) { return nil, err } + config.QPS = env_float("QPS", rest.DefaultQPS) + config.Burst = env_int("BURST", rest.DefaultBurst) + logrus.Infof("QPS: %f, Burst: %d", config.QPS, config.Burst) + return newKubeClient(config) } +func env_float(key string, defaultFloat float32) float32 { + if v, found := os.LookupEnv(key); found { + if i, err := strconv.ParseFloat(v, 32); err != nil { + return float32(i) + } + logrus.Warningf("unable to parse environment variable %s; using default value %f", key, defaultFloat) + } + + return defaultFloat +} + +func env_int(key string, defaultInt int) int { + if v, found := os.LookupEnv(key); found { + if i, err := strconv.Atoi(v); err != nil { + return i + } + logrus.Warningf("unable to parse environment variable %s; using default value %d", key, defaultInt) + } + + return defaultInt +} + func env(key string) string { if value, found := os.LookupEnv(key); found { return value } panic(fmt.Errorf("%s env var not found", key)) } - -func port(key string) (int, error) { - if port, found := os.LookupEnv(key); found { - return strconv.Atoi(port) - } - return 443, nil -} diff --git a/charts/gmsa/templates/deployment.yaml b/charts/gmsa/templates/deployment.yaml index f171181c..3eebd509 100644 --- a/charts/gmsa/templates/deployment.yaml +++ b/charts/gmsa/templates/deployment.yaml @@ -53,6 +53,10 @@ spec: value: /tls/crt - name: HTTPS_PORT value: "{{ .Values.containerPort }}" + - name: BURST + value: "{{ .Values.burst }}" + - name: QPS + value: "{{ .Values.qps }}" {{- if .Values.securityContext }} securityContext: {{ toYaml .Values.securityContext | nindent 12 }} {{- end }} diff --git a/charts/gmsa/values.yaml b/charts/gmsa/values.yaml index 55c381ae..0aa4fe0d 100644 --- a/charts/gmsa/values.yaml +++ b/charts/gmsa/values.yaml @@ -49,3 +49,5 @@ podSecurityContext: {} replicaCount: 2 securityContext: {} tolerations: [] +qps: 30 +burst: 50