From b3d8d79e9aa7a25a38d66dd1ef36b02ed8bf4d84 Mon Sep 17 00:00:00 2001 From: yaqi Date: Thu, 11 Jul 2019 20:34:46 +0800 Subject: [PATCH 1/2] add check when qps > 0 but burst <=0 --- .../cmd/client-gen/generators/generator_for_clientset.go | 5 +++++ .../metrics/pkg/client/custom_metrics/versioned_client.go | 3 +++ .../src/k8s.io/metrics/pkg/client/external_metrics/client.go | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_clientset.go b/staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_clientset.go index a1e67dcbdf2..f7254343bd1 100644 --- a/staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_clientset.go +++ b/staging/src/k8s.io/code-generator/cmd/client-gen/generators/generator_for_clientset.go @@ -134,9 +134,14 @@ func (c *Clientset) Discovery() $.DiscoveryInterface|raw$ { var newClientsetForConfigTemplate = ` // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *$.Config|raw$) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = $.flowcontrolNewTokenBucketRateLimiter|raw$(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/metrics/pkg/client/custom_metrics/versioned_client.go b/staging/src/k8s.io/metrics/pkg/client/custom_metrics/versioned_client.go index fae4bf8dc11..bfe9ff2922d 100644 --- a/staging/src/k8s.io/metrics/pkg/client/custom_metrics/versioned_client.go +++ b/staging/src/k8s.io/metrics/pkg/client/custom_metrics/versioned_client.go @@ -56,6 +56,9 @@ func NewForVersion(client rest.Interface, mapper meta.RESTMapper, version schema func NewForVersionForConfig(c *rest.Config, mapper meta.RESTMapper, version schema.GroupVersion) (CustomMetricsClient, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } configShallowCopy.APIPath = "/apis" diff --git a/staging/src/k8s.io/metrics/pkg/client/external_metrics/client.go b/staging/src/k8s.io/metrics/pkg/client/external_metrics/client.go index a6235e02f6a..d6add5c3949 100644 --- a/staging/src/k8s.io/metrics/pkg/client/external_metrics/client.go +++ b/staging/src/k8s.io/metrics/pkg/client/external_metrics/client.go @@ -17,6 +17,8 @@ limitations under the License. package external_metrics import ( + "fmt" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/kubernetes/scheme" @@ -38,6 +40,9 @@ func New(client rest.Interface) ExternalMetricsClient { func NewForConfig(c *rest.Config) (ExternalMetricsClient, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } configShallowCopy.APIPath = "/apis" From aa71695be1006c843de836104006a724451fa9a0 Mon Sep 17 00:00:00 2001 From: yaqi Date: Thu, 11 Jul 2019 20:34:59 +0800 Subject: [PATCH 2/2] execute hack/update-codegen.sh, sync updates --- .../client-go/pkg/client/clientset/versioned/clientset.go | 7 +++++++ .../pkg/client/clientset/clientset/clientset.go | 7 +++++++ .../pkg/client/clientset/internalclientset/clientset.go | 7 +++++++ staging/src/k8s.io/client-go/kubernetes/clientset.go | 7 +++++++ .../_examples/MixedCase/clientset/versioned/clientset.go | 7 +++++++ .../apiserver/clientset/internalversion/clientset.go | 7 +++++++ .../_examples/apiserver/clientset/versioned/clientset.go | 7 +++++++ .../_examples/crd/clientset/versioned/clientset.go | 7 +++++++ .../pkg/client/clientset_generated/clientset/clientset.go | 7 +++++++ .../clientset_generated/internalclientset/clientset.go | 7 +++++++ .../metrics/pkg/client/clientset/versioned/clientset.go | 7 +++++++ .../node-api/pkg/client/clientset/versioned/clientset.go | 7 +++++++ .../pkg/generated/clientset/versioned/clientset.go | 7 +++++++ .../pkg/generated/clientset/versioned/clientset.go | 7 +++++++ 14 files changed, 98 insertions(+) diff --git a/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/clientset/versioned/clientset.go b/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/clientset/versioned/clientset.go index f6ffae326db..5214359db79 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/clientset/versioned/clientset.go +++ b/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/clientset/versioned/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package versioned import ( + "fmt" + crv1 "k8s.io/apiextensions-apiserver/examples/client-go/pkg/client/clientset/versioned/typed/cr/v1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" @@ -51,9 +53,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/clientset.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/clientset.go index aa2dbcbb088..3bbe82469d5 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/clientset.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package clientset import ( + "fmt" + apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1beta1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" @@ -51,9 +53,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/apiextensions-apiserver/pkg/client/clientset/internalclientset/clientset.go b/staging/src/k8s.io/apiextensions-apiserver/pkg/client/clientset/internalclientset/clientset.go index 152a9fea005..af78ee5ad32 100644 --- a/staging/src/k8s.io/apiextensions-apiserver/pkg/client/clientset/internalclientset/clientset.go +++ b/staging/src/k8s.io/apiextensions-apiserver/pkg/client/clientset/internalclientset/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package internalclientset import ( + "fmt" + apiextensionsinternalversion "k8s.io/apiextensions-apiserver/pkg/client/clientset/internalclientset/typed/apiextensions/internalversion" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" @@ -51,9 +53,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/client-go/kubernetes/clientset.go b/staging/src/k8s.io/client-go/kubernetes/clientset.go index fb889e6df53..07a3fc489df 100644 --- a/staging/src/k8s.io/client-go/kubernetes/clientset.go +++ b/staging/src/k8s.io/client-go/kubernetes/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package kubernetes import ( + "fmt" + discovery "k8s.io/client-go/discovery" admissionregistrationv1beta1 "k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1" appsv1 "k8s.io/client-go/kubernetes/typed/apps/v1" @@ -331,9 +333,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/code-generator/_examples/MixedCase/clientset/versioned/clientset.go b/staging/src/k8s.io/code-generator/_examples/MixedCase/clientset/versioned/clientset.go index c2052dfd405..99b43e3c6ce 100644 --- a/staging/src/k8s.io/code-generator/_examples/MixedCase/clientset/versioned/clientset.go +++ b/staging/src/k8s.io/code-generator/_examples/MixedCase/clientset/versioned/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package versioned import ( + "fmt" + discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -51,9 +53,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/clientset.go b/staging/src/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/clientset.go index ff88d121cdd..a9dc68d887b 100644 --- a/staging/src/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/clientset.go +++ b/staging/src/k8s.io/code-generator/_examples/apiserver/clientset/internalversion/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package internalversion import ( + "fmt" + discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -59,9 +61,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/code-generator/_examples/apiserver/clientset/versioned/clientset.go b/staging/src/k8s.io/code-generator/_examples/apiserver/clientset/versioned/clientset.go index 7039a827b50..7136f17a1d1 100644 --- a/staging/src/k8s.io/code-generator/_examples/apiserver/clientset/versioned/clientset.go +++ b/staging/src/k8s.io/code-generator/_examples/apiserver/clientset/versioned/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package versioned import ( + "fmt" + discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -59,9 +61,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/code-generator/_examples/crd/clientset/versioned/clientset.go b/staging/src/k8s.io/code-generator/_examples/crd/clientset/versioned/clientset.go index 812dbd12464..0cb38bfa2b9 100644 --- a/staging/src/k8s.io/code-generator/_examples/crd/clientset/versioned/clientset.go +++ b/staging/src/k8s.io/code-generator/_examples/crd/clientset/versioned/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package versioned import ( + "fmt" + discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -59,9 +61,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/clientset.go b/staging/src/k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/clientset.go index f0b0b670ed3..6190163460c 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/clientset.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package clientset import ( + "fmt" + discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -59,9 +61,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/kube-aggregator/pkg/client/clientset_generated/internalclientset/clientset.go b/staging/src/k8s.io/kube-aggregator/pkg/client/clientset_generated/internalclientset/clientset.go index 7359abf4ec7..c61ed599b46 100644 --- a/staging/src/k8s.io/kube-aggregator/pkg/client/clientset_generated/internalclientset/clientset.go +++ b/staging/src/k8s.io/kube-aggregator/pkg/client/clientset_generated/internalclientset/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package internalclientset import ( + "fmt" + discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -51,9 +53,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/metrics/pkg/client/clientset/versioned/clientset.go b/staging/src/k8s.io/metrics/pkg/client/clientset/versioned/clientset.go index ef64f637311..0c98f1db85a 100644 --- a/staging/src/k8s.io/metrics/pkg/client/clientset/versioned/clientset.go +++ b/staging/src/k8s.io/metrics/pkg/client/clientset/versioned/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package versioned import ( + "fmt" + discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -59,9 +61,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/node-api/pkg/client/clientset/versioned/clientset.go b/staging/src/k8s.io/node-api/pkg/client/clientset/versioned/clientset.go index 4f38604723e..a538dc8ad8f 100644 --- a/staging/src/k8s.io/node-api/pkg/client/clientset/versioned/clientset.go +++ b/staging/src/k8s.io/node-api/pkg/client/clientset/versioned/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package versioned import ( + "fmt" + discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -51,9 +53,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/sample-apiserver/pkg/generated/clientset/versioned/clientset.go b/staging/src/k8s.io/sample-apiserver/pkg/generated/clientset/versioned/clientset.go index e8723c4d4db..1dbba8d3003 100644 --- a/staging/src/k8s.io/sample-apiserver/pkg/generated/clientset/versioned/clientset.go +++ b/staging/src/k8s.io/sample-apiserver/pkg/generated/clientset/versioned/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package versioned import ( + "fmt" + discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -59,9 +61,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset diff --git a/staging/src/k8s.io/sample-controller/pkg/generated/clientset/versioned/clientset.go b/staging/src/k8s.io/sample-controller/pkg/generated/clientset/versioned/clientset.go index 9e1bd6319eb..62d21b12c66 100644 --- a/staging/src/k8s.io/sample-controller/pkg/generated/clientset/versioned/clientset.go +++ b/staging/src/k8s.io/sample-controller/pkg/generated/clientset/versioned/clientset.go @@ -19,6 +19,8 @@ limitations under the License. package versioned import ( + "fmt" + discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -51,9 +53,14 @@ func (c *Clientset) Discovery() discovery.DiscoveryInterface { } // NewForConfig creates a new Clientset for the given config. +// If config's RateLimiter is not set and QPS and Burst are acceptable, +// NewForConfig will generate a rate-limiter in configShallowCopy. func NewForConfig(c *rest.Config) (*Clientset, error) { configShallowCopy := *c if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + if configShallowCopy.Burst <= 0 { + return nil, fmt.Errorf("Burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0") + } configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) } var cs Clientset