mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #26756 from hongchaodeng/cli
Automatic merge from submit-queue Change client default value of qps and burst to constant
This commit is contained in:
commit
d8d5ab29a5
@ -244,12 +244,6 @@ func setConfigDefaults(config *$.Config|raw$) error {
|
|||||||
|
|
||||||
config.NegotiatedSerializer = $.directCodecFactory|raw${CodecFactory: $.codecs|raw$}
|
config.NegotiatedSerializer = $.directCodecFactory|raw${CodecFactory: $.codecs|raw$}
|
||||||
|
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
@ -83,12 +83,6 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
||||||
|
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,12 +83,6 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
||||||
|
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,12 +83,6 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
||||||
|
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,12 +83,6 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
||||||
|
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,12 +153,6 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
||||||
|
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,12 +123,6 @@ func setConfigDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
|
||||||
|
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +37,11 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/version"
|
"k8s.io/kubernetes/pkg/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultQPS float32 = 5.0
|
||||||
|
DefaultBurst int = 10
|
||||||
|
)
|
||||||
|
|
||||||
// Config holds the common attributes that can be passed to a Kubernetes client on
|
// Config holds the common attributes that can be passed to a Kubernetes client on
|
||||||
// initialization.
|
// initialization.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@ -93,10 +98,12 @@ type Config struct {
|
|||||||
// on top of the returned RoundTripper.
|
// on top of the returned RoundTripper.
|
||||||
WrapTransport func(rt http.RoundTripper) http.RoundTripper
|
WrapTransport func(rt http.RoundTripper) http.RoundTripper
|
||||||
|
|
||||||
// QPS indicates the maximum QPS to the master from this client. If zero, QPS is unlimited.
|
// QPS indicates the maximum QPS to the master from this client.
|
||||||
|
// If it's zero, the created RESTClient will use DefaultQPS: 5
|
||||||
QPS float32
|
QPS float32
|
||||||
|
|
||||||
// Maximum burst for throttle
|
// Maximum burst for throttle.
|
||||||
|
// If it's zero, the created RESTClient will use DefaultBurst: 10.
|
||||||
Burst int
|
Burst int
|
||||||
|
|
||||||
// Rate limiter for limiting connections to the master from this client. If present overwrites QPS/Burst
|
// Rate limiter for limiting connections to the master from this client. If present overwrites QPS/Burst
|
||||||
@ -158,6 +165,14 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
|
|||||||
if config.NegotiatedSerializer == nil {
|
if config.NegotiatedSerializer == nil {
|
||||||
return nil, fmt.Errorf("NegotiatedSerializer is required when initializing a RESTClient")
|
return nil, fmt.Errorf("NegotiatedSerializer is required when initializing a RESTClient")
|
||||||
}
|
}
|
||||||
|
qps := config.QPS
|
||||||
|
if config.QPS == 0.0 {
|
||||||
|
qps = DefaultQPS
|
||||||
|
}
|
||||||
|
burst := config.Burst
|
||||||
|
if config.Burst == 0 {
|
||||||
|
burst = DefaultBurst
|
||||||
|
}
|
||||||
|
|
||||||
baseURL, versionedAPIPath, err := defaultServerUrlFor(config)
|
baseURL, versionedAPIPath, err := defaultServerUrlFor(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -174,7 +189,7 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
|
|||||||
httpClient = &http.Client{Transport: transport}
|
httpClient = &http.Client{Transport: transport}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewRESTClient(baseURL, versionedAPIPath, config.ContentConfig, config.QPS, config.Burst, config.RateLimiter, httpClient)
|
return NewRESTClient(baseURL, versionedAPIPath, config.ContentConfig, qps, burst, config.RateLimiter, httpClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnversionedRESTClientFor is the same as RESTClientFor, except that it allows
|
// UnversionedRESTClientFor is the same as RESTClientFor, except that it allows
|
||||||
@ -214,12 +229,6 @@ func SetKubernetesDefaults(config *Config) error {
|
|||||||
if len(config.UserAgent) == 0 {
|
if len(config.UserAgent) == 0 {
|
||||||
config.UserAgent = DefaultKubernetesUserAgent()
|
config.UserAgent = DefaultKubernetesUserAgent()
|
||||||
}
|
}
|
||||||
if config.QPS == 0.0 {
|
|
||||||
config.QPS = 5.0
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,13 +69,6 @@ func NewClient(conf *restclient.Config) (*Client, error) {
|
|||||||
conf.UserAgent = restclient.DefaultKubernetesUserAgent()
|
conf.UserAgent = restclient.DefaultKubernetesUserAgent()
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.QPS == 0.0 {
|
|
||||||
conf.QPS = 5.0
|
|
||||||
}
|
|
||||||
if conf.Burst == 0 {
|
|
||||||
conf.Burst = 10
|
|
||||||
}
|
|
||||||
|
|
||||||
cl, err := restclient.RESTClientFor(conf)
|
cl, err := restclient.RESTClientFor(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -73,11 +73,5 @@ func setAppsDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||||
config.NegotiatedSerializer = api.Codecs
|
config.NegotiatedSerializer = api.Codecs
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -74,11 +74,5 @@ func setAutoscalingDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||||
config.NegotiatedSerializer = api.Codecs
|
config.NegotiatedSerializer = api.Codecs
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -104,11 +104,5 @@ func setBatchDefaults(config *restclient.Config, gv *unversioned.GroupVersion) e
|
|||||||
|
|
||||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||||
config.NegotiatedSerializer = api.Codecs
|
config.NegotiatedSerializer = api.Codecs
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -128,11 +128,5 @@ func setExtensionsDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||||
config.NegotiatedSerializer = api.Codecs
|
config.NegotiatedSerializer = api.Codecs
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,6 @@ func TestSetKubernetesDefaults(t *testing.T) {
|
|||||||
Codec: testapi.Default.Codec(),
|
Codec: testapi.Default.Codec(),
|
||||||
NegotiatedSerializer: testapi.Default.NegotiatedSerializer(),
|
NegotiatedSerializer: testapi.Default.NegotiatedSerializer(),
|
||||||
},
|
},
|
||||||
QPS: 5,
|
|
||||||
Burst: 10,
|
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
@ -73,11 +73,5 @@ func setPolicyDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||||
config.NegotiatedSerializer = api.Codecs
|
config.NegotiatedSerializer = api.Codecs
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -93,11 +93,5 @@ func setRbacDefaults(config *restclient.Config) error {
|
|||||||
|
|
||||||
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
|
||||||
config.NegotiatedSerializer = api.Codecs
|
config.NegotiatedSerializer = api.Codecs
|
||||||
if config.QPS == 0 {
|
|
||||||
config.QPS = 5
|
|
||||||
}
|
|
||||||
if config.Burst == 0 {
|
|
||||||
config.Burst = 10
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user