Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to configure QPS and Burst for go-client #149

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading