1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-17 15:58:41 +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 c4ebbe629f
commit 75feceeb86

View File

@@ -2,7 +2,10 @@ package client
import (
"fmt"
"log"
"net/http"
"os"
"strconv"
"time"
"github.com/rancher/apiserver/pkg/types"
@@ -42,8 +45,7 @@ func (a *addQuery) RoundTrip(req *http.Request) (*http.Response, error) {
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
@@ -192,3 +194,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
}
}
}