1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-19 01:45:13 +00:00

Add support for QPS and Burst from the environment.

This adds support for optionally configuring the created client's QPS
and Burst values from environment variables.

RANCHER_CLIENT_QPS and RANCHER_CLIENT_BURST are treated as int and float
values respectively see https://pkg.go.dev/k8s.io/client-go/rest#Config
for details.
This commit is contained in:
Kevin McDermott
2025-04-07 12:04:31 +01:00
parent 83cf2ac76f
commit 825f722bdc

View File

@@ -2,7 +2,10 @@ package client
import (
"fmt"
"log"
"net/http"
"os"
"strconv"
"time"
"github.com/rancher/apiserver/pkg/types"
@@ -49,8 +52,7 @@ func (a *addQuery) WrappedRoundTripper() http.RoundTripper {
func NewFactory(cfg *rest.Config, impersonate bool) (*Factory, error) {
clientCfg := rest.CopyConfig(cfg)
clientCfg.QPS = 10000
clientCfg.Burst = 100
updateConfigFromEnvironment(clientCfg)
watchClientCfg := rest.CopyConfig(clientCfg)
watchClientCfg.Timeout = 30 * time.Minute
@@ -199,3 +201,27 @@ func newClient(ctx *types.APIRequest, cfg *rest.Config, s *types.APISchema, name
gvr := attributes.GVR(s)
return client.Resource(gvr).Namespace(namespace), nil
}
func updateConfigFromEnvironment(cfg *rest.Config) {
cfg.QPS = 10000
if v := os.Getenv("RANCHER_CLIENT_QPS"); v != "" {
qps, err := strconv.ParseFloat(v, 32)
if err != nil {
log.Printf("steve: configuring client failed to parse RANCHER_CLIENT_QPS: %s", err)
} else {
log.Printf("steve: configuring client.QPS = %v", qps)
cfg.QPS = float32(qps)
}
}
cfg.Burst = 100
if v := os.Getenv("RANCHER_CLIENT_BURST"); v != "" {
burst, err := strconv.Atoi(v)
if err != nil {
log.Printf("steve: configuring client failed to parse RANCHER_CLIENT_BURST: %s", err)
} else {
log.Printf("steve: configuring client.Burst = %v", burst)
cfg.Burst = burst
}
}
}