1
0
mirror of https://github.com/rancher/steve.git synced 2025-04-27 11:00:48 +00:00

Add support for configuring the QPS and Burst from the environment.

This commit is contained in:
Kevin McDermott 2025-04-07 12:04:31 +01:00
parent 6de55df701
commit 148a22d3eb

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_QPS: %s", err)
} else {
log.Printf("steve: configuring client.Burst = %v", burst)
cfg.Burst = burst
}
}
}