diff --git a/cmd/libs/go2idl/client-gen/generators/generator_for_group.go b/cmd/libs/go2idl/client-gen/generators/generator_for_group.go index 7ae31d9fafe7b..23424c6b0e746 100644 --- a/cmd/libs/go2idl/client-gen/generators/generator_for_group.go +++ b/cmd/libs/go2idl/client-gen/generators/generator_for_group.go @@ -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 } ` diff --git a/federation/client/clientset_generated/federation_release_1_3/typed/core/v1/core_client.go b/federation/client/clientset_generated/federation_release_1_3/typed/core/v1/core_client.go index 19593ab6799af..5ec32b2d54dd5 100644 --- a/federation/client/clientset_generated/federation_release_1_3/typed/core/v1/core_client.go +++ b/federation/client/clientset_generated/federation_release_1_3/typed/core/v1/core_client.go @@ -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 } diff --git a/federation/client/clientset_generated/federation_release_1_3/typed/federation/v1beta1/federation_client.go b/federation/client/clientset_generated/federation_release_1_3/typed/federation/v1beta1/federation_client.go index 381aa9f8d995c..952fa6896f4c9 100644 --- a/federation/client/clientset_generated/federation_release_1_3/typed/federation/v1beta1/federation_client.go +++ b/federation/client/clientset_generated/federation_release_1_3/typed/federation/v1beta1/federation_client.go @@ -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 } diff --git a/pkg/client/clientset_generated/release_1_3/typed/autoscaling/v1/autoscaling_client.go b/pkg/client/clientset_generated/release_1_3/typed/autoscaling/v1/autoscaling_client.go index a0fb01144eef2..2072ff9bbd8b0 100644 --- a/pkg/client/clientset_generated/release_1_3/typed/autoscaling/v1/autoscaling_client.go +++ b/pkg/client/clientset_generated/release_1_3/typed/autoscaling/v1/autoscaling_client.go @@ -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 } diff --git a/pkg/client/clientset_generated/release_1_3/typed/batch/v1/batch_client.go b/pkg/client/clientset_generated/release_1_3/typed/batch/v1/batch_client.go index 018d2c688ac3f..527d53e568326 100644 --- a/pkg/client/clientset_generated/release_1_3/typed/batch/v1/batch_client.go +++ b/pkg/client/clientset_generated/release_1_3/typed/batch/v1/batch_client.go @@ -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 } diff --git a/pkg/client/clientset_generated/release_1_3/typed/core/v1/core_client.go b/pkg/client/clientset_generated/release_1_3/typed/core/v1/core_client.go index 3804b8cb3b65d..201aa94d8be30 100644 --- a/pkg/client/clientset_generated/release_1_3/typed/core/v1/core_client.go +++ b/pkg/client/clientset_generated/release_1_3/typed/core/v1/core_client.go @@ -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 } diff --git a/pkg/client/clientset_generated/release_1_3/typed/extensions/v1beta1/extensions_client.go b/pkg/client/clientset_generated/release_1_3/typed/extensions/v1beta1/extensions_client.go index 23aa5b219ed8f..3389f4ace2dbc 100644 --- a/pkg/client/clientset_generated/release_1_3/typed/extensions/v1beta1/extensions_client.go +++ b/pkg/client/clientset_generated/release_1_3/typed/extensions/v1beta1/extensions_client.go @@ -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 } diff --git a/pkg/client/restclient/config.go b/pkg/client/restclient/config.go index 0741e3c2d8f44..5a62371558068 100644 --- a/pkg/client/restclient/config.go +++ b/pkg/client/restclient/config.go @@ -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 } diff --git a/pkg/client/typed/dynamic/client.go b/pkg/client/typed/dynamic/client.go index 26369bd582340..be223210531c2 100644 --- a/pkg/client/typed/dynamic/client.go +++ b/pkg/client/typed/dynamic/client.go @@ -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 diff --git a/pkg/client/unversioned/apps.go b/pkg/client/unversioned/apps.go index 1905c29c2467f..a355e6f9b8d68 100644 --- a/pkg/client/unversioned/apps.go +++ b/pkg/client/unversioned/apps.go @@ -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 } diff --git a/pkg/client/unversioned/autoscaling.go b/pkg/client/unversioned/autoscaling.go index 9e543c9d3aeba..af166886e62d1 100644 --- a/pkg/client/unversioned/autoscaling.go +++ b/pkg/client/unversioned/autoscaling.go @@ -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 } diff --git a/pkg/client/unversioned/batch.go b/pkg/client/unversioned/batch.go index 40fc49dc121f0..6cb4393190c72 100644 --- a/pkg/client/unversioned/batch.go +++ b/pkg/client/unversioned/batch.go @@ -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 } diff --git a/pkg/client/unversioned/extensions.go b/pkg/client/unversioned/extensions.go index 3c9114d9a88c2..393b09fb26f22 100644 --- a/pkg/client/unversioned/extensions.go +++ b/pkg/client/unversioned/extensions.go @@ -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 } diff --git a/pkg/client/unversioned/helper_test.go b/pkg/client/unversioned/helper_test.go index 0e186e4c78eff..365734ffd0736 100644 --- a/pkg/client/unversioned/helper_test.go +++ b/pkg/client/unversioned/helper_test.go @@ -44,8 +44,6 @@ func TestSetKubernetesDefaults(t *testing.T) { Codec: testapi.Default.Codec(), NegotiatedSerializer: testapi.Default.NegotiatedSerializer(), }, - QPS: 5, - Burst: 10, }, false, }, diff --git a/pkg/client/unversioned/policy.go b/pkg/client/unversioned/policy.go index 8b06ce275ac43..1edc4b7786a73 100644 --- a/pkg/client/unversioned/policy.go +++ b/pkg/client/unversioned/policy.go @@ -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 } diff --git a/pkg/client/unversioned/rbac.go b/pkg/client/unversioned/rbac.go index 76ec392c3e47a..27bc5c1edbbf9 100644 --- a/pkg/client/unversioned/rbac.go +++ b/pkg/client/unversioned/rbac.go @@ -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 }