Skip to content

Commit

Permalink
Merge pull request #149 from jsturtevant/qps-burst
Browse files Browse the repository at this point in the history
Add ability to configure QPS and Burst for go-client
  • Loading branch information
k8s-ci-robot committed Sep 25, 2024
2 parents 795e1c7 + d949ba6 commit 2173faf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
38 changes: 27 additions & 11 deletions admission-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions charts/gmsa/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions charts/gmsa/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ podSecurityContext: {}
replicaCount: 2
securityContext: {}
tolerations: []
qps: 30
burst: 50

0 comments on commit 2173faf

Please sign in to comment.