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:
k8s-merge-robot 2016-06-29 18:11:18 -07:00 committed by GitHub
commit d8d5ab29a5
16 changed files with 18 additions and 96 deletions

View File

@ -244,12 +244,6 @@ func setConfigDefaults(config *$.Config|raw$) error {
config.NegotiatedSerializer = $.directCodecFactory|raw${CodecFactory: $.codecs|raw$}
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}
`

View File

@ -83,12 +83,6 @@ func setConfigDefaults(config *restclient.Config) error {
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -83,12 +83,6 @@ func setConfigDefaults(config *restclient.Config) error {
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -83,12 +83,6 @@ func setConfigDefaults(config *restclient.Config) error {
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -83,12 +83,6 @@ func setConfigDefaults(config *restclient.Config) error {
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -153,12 +153,6 @@ func setConfigDefaults(config *restclient.Config) error {
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -123,12 +123,6 @@ func setConfigDefaults(config *restclient.Config) error {
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -37,6 +37,11 @@ import (
"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
// initialization.
type Config struct {
@ -93,10 +98,12 @@ type Config struct {
// on top of the returned 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
// Maximum burst for throttle
// Maximum burst for throttle.
// If it's zero, the created RESTClient will use DefaultBurst: 10.
Burst int
// 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 {
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)
if err != nil {
@ -174,7 +189,7 @@ func RESTClientFor(config *Config) (*RESTClient, error) {
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
@ -214,12 +229,6 @@ func SetKubernetesDefaults(config *Config) error {
if len(config.UserAgent) == 0 {
config.UserAgent = DefaultKubernetesUserAgent()
}
if config.QPS == 0.0 {
config.QPS = 5.0
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -69,13 +69,6 @@ func NewClient(conf *restclient.Config) (*Client, error) {
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)
if err != nil {
return nil, err

View File

@ -73,11 +73,5 @@ func setAppsDefaults(config *restclient.Config) error {
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
config.NegotiatedSerializer = api.Codecs
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -74,11 +74,5 @@ func setAutoscalingDefaults(config *restclient.Config) error {
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
config.NegotiatedSerializer = api.Codecs
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -104,11 +104,5 @@ func setBatchDefaults(config *restclient.Config, gv *unversioned.GroupVersion) e
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
config.NegotiatedSerializer = api.Codecs
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -128,11 +128,5 @@ func setExtensionsDefaults(config *restclient.Config) error {
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
config.NegotiatedSerializer = api.Codecs
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -44,8 +44,6 @@ func TestSetKubernetesDefaults(t *testing.T) {
Codec: testapi.Default.Codec(),
NegotiatedSerializer: testapi.Default.NegotiatedSerializer(),
},
QPS: 5,
Burst: 10,
},
false,
},

View File

@ -73,11 +73,5 @@ func setPolicyDefaults(config *restclient.Config) error {
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
config.NegotiatedSerializer = api.Codecs
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}

View File

@ -93,11 +93,5 @@ func setRbacDefaults(config *restclient.Config) error {
config.Codec = api.Codecs.LegacyCodec(*config.GroupVersion)
config.NegotiatedSerializer = api.Codecs
if config.QPS == 0 {
config.QPS = 5
}
if config.Burst == 0 {
config.Burst = 10
}
return nil
}