Skip to content

Commit

Permalink
Merge pull request kubernetes#26756 from hongchaodeng/cli
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Change client default value of qps and burst to constant
  • Loading branch information
k8s-merge-robot authored Jun 30, 2016
2 parents 5dfbc76 + 55d3597 commit d8d5ab2
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 96 deletions.
6 changes: 0 additions & 6 deletions cmd/libs/go2idl/client-gen/generators/generator_for_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
`
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
27 changes: 18 additions & 9 deletions pkg/client/restclient/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 0 additions & 7 deletions pkg/client/typed/dynamic/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions pkg/client/unversioned/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 0 additions & 6 deletions pkg/client/unversioned/autoscaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 0 additions & 6 deletions pkg/client/unversioned/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 0 additions & 6 deletions pkg/client/unversioned/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 0 additions & 2 deletions pkg/client/unversioned/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ func TestSetKubernetesDefaults(t *testing.T) {
Codec: testapi.Default.Codec(),
NegotiatedSerializer: testapi.Default.NegotiatedSerializer(),
},
QPS: 5,
Burst: 10,
},
false,
},
Expand Down
6 changes: 0 additions & 6 deletions pkg/client/unversioned/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 0 additions & 6 deletions pkg/client/unversioned/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit d8d5ab2

Please sign in to comment.