Merge pull request #38320 from liggitt/golang-ratelimit

Automatic merge from submit-queue (batch tested with PRs 59158, 38320, 59059, 55516, 59357). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Switch from juju/ratelimit to golang.org/x/time/rate

Replaces juju/ratelimit with golang.org/x/time/rate
xref https://github.com/kubernetes/steering/issues/21

Requires removing the Saturation() method on the rate limiter. In the process of attempting to contribute it to the `golang.org/x/time/rate` implementation, it became clear that what it was calculating was not very useful when combined with periodic polling. See discussion in https://go-review.googlesource.com/c/time/+/29958#message-4caffc11669cadd90e2da4c05122cfec50ea6a22

```release-note
NONE
```

Kubernetes-commit: 0656d030a7d131ca8088a9f0ecd12596eb90d2fd
This commit is contained in:
Kubernetes Publisher 2018-02-05 12:40:34 -08:00
commit 7df7717190
15 changed files with 581 additions and 803 deletions

244
Godeps/Godeps.json generated
View File

@ -86,10 +86,6 @@
"ImportPath": "github.com/json-iterator/go",
"Rev": "13f86432b882000a51c6e610c620974462691a97"
},
{
"ImportPath": "github.com/juju/ratelimit",
"Rev": "5b9ff866471762aa2ab2dced63c9fb6f53921342"
},
{
"ImportPath": "github.com/spf13/pflag",
"Rev": "4c012f6dcd9546820e378d0bdda4d8fc772cdfea"
@ -142,6 +138,10 @@
"ImportPath": "golang.org/x/text/unicode/norm",
"Rev": "b19bf474d317b857955b12035d2c5acb57ce8b01"
},
{
"ImportPath": "golang.org/x/time/rate",
"Rev": "f51c12702a4d776e4c1fa9b0fabab841babae631"
},
{
"ImportPath": "gopkg.in/inf.v0",
"Rev": "3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4"
@ -428,475 +428,475 @@
},
{
"ImportPath": "k8s.io/client-go/discovery",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/discovery/fake",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/admissionregistration",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/admissionregistration/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/admissionregistration/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/apps",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/apps/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/apps/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/apps/v1beta2",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/autoscaling",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/autoscaling/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/autoscaling/v2beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/batch",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/batch/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/batch/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/batch/v2alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/certificates",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/certificates/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/core",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/core/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/events",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/events/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/extensions",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/extensions/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/internalinterfaces",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/networking",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/networking/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/policy",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/policy/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/rbac",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/rbac/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/rbac/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/rbac/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/scheduling",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/scheduling/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/settings",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/settings/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/storage",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/storage/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/storage/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/informers/storage/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/scheme",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/admissionregistration/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/apps/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/apps/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/apps/v1beta2",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/authentication/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/authentication/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/authorization/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/authorization/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/autoscaling/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/autoscaling/v2beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/batch/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/batch/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/batch/v2alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/certificates/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/core/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/events/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/extensions/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/networking/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/policy/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/rbac/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/rbac/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/rbac/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/scheduling/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/settings/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/storage/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/storage/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/kubernetes/typed/storage/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/admissionregistration/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/admissionregistration/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/apps/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/apps/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/apps/v1beta2",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/autoscaling/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/autoscaling/v2beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/batch/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/batch/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/batch/v2alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/certificates/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/core/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/events/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/extensions/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/networking/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/policy/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/rbac/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/rbac/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/rbac/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/scheduling/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/settings/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/storage/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/storage/v1alpha1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/listers/storage/v1beta1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/pkg/version",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/rest",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/rest/watch",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/testing",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/tools/auth",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/tools/cache",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/tools/clientcmd",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/tools/clientcmd/api",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/tools/clientcmd/api/latest",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/tools/clientcmd/api/v1",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/tools/metrics",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/tools/pager",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/tools/record",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/tools/reference",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/transport",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/util/buffer",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/util/cert",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/util/flowcontrol",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/util/homedir",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/util/integer",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/util/retry",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/client-go/util/workqueue",
"Rev": "e2d750fcad023e759abc09adcbe3706a6126020d"
"Rev": "bd9218ea5f0138235c0edfaf013b41445840f913"
},
{
"ImportPath": "k8s.io/kube-openapi/pkg/util/proto",

View File

@ -1,191 +0,0 @@
All files in this repository are licensed as follows. If you contribute
to this repository, it is assumed that you license your contribution
under the same license unless you state otherwise.
All files Copyright (C) 2015 Canonical Ltd. unless otherwise specified in the file.
This software is licensed under the LGPLv3, included below.
As a special exception to the GNU Lesser General Public License version 3
("LGPL3"), the copyright holders of this Library give you permission to
convey to a third party a Combined Work that links statically or dynamically
to this Library without providing any Minimal Corresponding Source or
Minimal Application Code as set out in 4d or providing the installation
information set out in section 4e, provided that you comply with the other
provisions of LGPL3 and provided that you meet, for the Application the
terms and conditions of the license(s) which apply to the Application.
Except as stated in this special exception, the provisions of LGPL3 will
continue to comply in full to this Library. If you modify this Library, you
may apply this exception to your version of this Library, but you are not
obliged to do so. If you do not wish to do so, delete this exception
statement from your version. This exception does not (and cannot) modify any
license terms which apply to the Application, with which you must still
comply.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

View File

@ -1,117 +0,0 @@
# ratelimit
--
import "github.com/juju/ratelimit"
The ratelimit package provides an efficient token bucket implementation. See
http://en.wikipedia.org/wiki/Token_bucket.
## Usage
#### func Reader
```go
func Reader(r io.Reader, bucket *Bucket) io.Reader
```
Reader returns a reader that is rate limited by the given token bucket. Each
token in the bucket represents one byte.
#### func Writer
```go
func Writer(w io.Writer, bucket *Bucket) io.Writer
```
Writer returns a writer that is rate limited by the given token bucket. Each
token in the bucket represents one byte.
#### type Bucket
```go
type Bucket struct {
}
```
Bucket represents a token bucket that fills at a predetermined rate. Methods on
Bucket may be called concurrently.
#### func NewBucket
```go
func NewBucket(fillInterval time.Duration, capacity int64) *Bucket
```
NewBucket returns a new token bucket that fills at the rate of one token every
fillInterval, up to the given maximum capacity. Both arguments must be positive.
The bucket is initially full.
#### func NewBucketWithQuantum
```go
func NewBucketWithQuantum(fillInterval time.Duration, capacity, quantum int64) *Bucket
```
NewBucketWithQuantum is similar to NewBucket, but allows the specification of
the quantum size - quantum tokens are added every fillInterval.
#### func NewBucketWithRate
```go
func NewBucketWithRate(rate float64, capacity int64) *Bucket
```
NewBucketWithRate returns a token bucket that fills the bucket at the rate of
rate tokens per second up to the given maximum capacity. Because of limited
clock resolution, at high rates, the actual rate may be up to 1% different from
the specified rate.
#### func (*Bucket) Rate
```go
func (tb *Bucket) Rate() float64
```
Rate returns the fill rate of the bucket, in tokens per second.
#### func (*Bucket) Take
```go
func (tb *Bucket) Take(count int64) time.Duration
```
Take takes count tokens from the bucket without blocking. It returns the time
that the caller should wait until the tokens are actually available.
Note that if the request is irrevocable - there is no way to return tokens to
the bucket once this method commits us to taking them.
#### func (*Bucket) TakeAvailable
```go
func (tb *Bucket) TakeAvailable(count int64) int64
```
TakeAvailable takes up to count immediately available tokens from the bucket. It
returns the number of tokens removed, or zero if there are no available tokens.
It does not block.
#### func (*Bucket) TakeMaxDuration
```go
func (tb *Bucket) TakeMaxDuration(count int64, maxWait time.Duration) (time.Duration, bool)
```
TakeMaxDuration is like Take, except that it will only take tokens from the
bucket if the wait time for the tokens is no greater than maxWait.
If it would take longer than maxWait for the tokens to become available, it does
nothing and reports false, otherwise it returns the time that the caller should
wait until the tokens are actually available, and reports true.
#### func (*Bucket) Wait
```go
func (tb *Bucket) Wait(count int64)
```
Wait takes count tokens from the bucket, waiting until they are available.
#### func (*Bucket) WaitMaxDuration
```go
func (tb *Bucket) WaitMaxDuration(count int64, maxWait time.Duration) bool
```
WaitMaxDuration is like Wait except that it will only take tokens from the
bucket if it needs to wait for no greater than maxWait. It reports whether any
tokens have been removed from the bucket If no tokens have been removed, it
returns immediately.

View File

@ -1,284 +0,0 @@
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.
// Package ratelimit provides an efficient token bucket implementation
// that can be used to limit the rate of arbitrary things.
// See http://en.wikipedia.org/wiki/Token_bucket.
package ratelimit
import (
"math"
"strconv"
"sync"
"time"
)
// Bucket represents a token bucket that fills at a predetermined rate.
// Methods on Bucket may be called concurrently.
type Bucket struct {
startTime time.Time
capacity int64
quantum int64
fillInterval time.Duration
clock Clock
// The mutex guards the fields following it.
mu sync.Mutex
// avail holds the number of available tokens
// in the bucket, as of availTick ticks from startTime.
// It will be negative when there are consumers
// waiting for tokens.
avail int64
availTick int64
}
// Clock is used to inject testable fakes.
type Clock interface {
Now() time.Time
Sleep(d time.Duration)
}
// realClock implements Clock in terms of standard time functions.
type realClock struct{}
// Now is identical to time.Now.
func (realClock) Now() time.Time {
return time.Now()
}
// Sleep is identical to time.Sleep.
func (realClock) Sleep(d time.Duration) {
time.Sleep(d)
}
// NewBucket returns a new token bucket that fills at the
// rate of one token every fillInterval, up to the given
// maximum capacity. Both arguments must be
// positive. The bucket is initially full.
func NewBucket(fillInterval time.Duration, capacity int64) *Bucket {
return NewBucketWithClock(fillInterval, capacity, realClock{})
}
// NewBucketWithClock is identical to NewBucket but injects a testable clock
// interface.
func NewBucketWithClock(fillInterval time.Duration, capacity int64, clock Clock) *Bucket {
return NewBucketWithQuantumAndClock(fillInterval, capacity, 1, clock)
}
// rateMargin specifes the allowed variance of actual
// rate from specified rate. 1% seems reasonable.
const rateMargin = 0.01
// NewBucketWithRate returns a token bucket that fills the bucket
// at the rate of rate tokens per second up to the given
// maximum capacity. Because of limited clock resolution,
// at high rates, the actual rate may be up to 1% different from the
// specified rate.
func NewBucketWithRate(rate float64, capacity int64) *Bucket {
return NewBucketWithRateAndClock(rate, capacity, realClock{})
}
// NewBucketWithRateAndClock is identical to NewBucketWithRate but injects a
// testable clock interface.
func NewBucketWithRateAndClock(rate float64, capacity int64, clock Clock) *Bucket {
for quantum := int64(1); quantum < 1<<50; quantum = nextQuantum(quantum) {
fillInterval := time.Duration(1e9 * float64(quantum) / rate)
if fillInterval <= 0 {
continue
}
tb := NewBucketWithQuantumAndClock(fillInterval, capacity, quantum, clock)
if diff := math.Abs(tb.Rate() - rate); diff/rate <= rateMargin {
return tb
}
}
panic("cannot find suitable quantum for " + strconv.FormatFloat(rate, 'g', -1, 64))
}
// nextQuantum returns the next quantum to try after q.
// We grow the quantum exponentially, but slowly, so we
// get a good fit in the lower numbers.
func nextQuantum(q int64) int64 {
q1 := q * 11 / 10
if q1 == q {
q1++
}
return q1
}
// NewBucketWithQuantum is similar to NewBucket, but allows
// the specification of the quantum size - quantum tokens
// are added every fillInterval.
func NewBucketWithQuantum(fillInterval time.Duration, capacity, quantum int64) *Bucket {
return NewBucketWithQuantumAndClock(fillInterval, capacity, quantum, realClock{})
}
// NewBucketWithQuantumAndClock is identical to NewBucketWithQuantum but injects
// a testable clock interface.
func NewBucketWithQuantumAndClock(fillInterval time.Duration, capacity, quantum int64, clock Clock) *Bucket {
if fillInterval <= 0 {
panic("token bucket fill interval is not > 0")
}
if capacity <= 0 {
panic("token bucket capacity is not > 0")
}
if quantum <= 0 {
panic("token bucket quantum is not > 0")
}
return &Bucket{
clock: clock,
startTime: clock.Now(),
capacity: capacity,
quantum: quantum,
avail: capacity,
fillInterval: fillInterval,
}
}
// Wait takes count tokens from the bucket, waiting until they are
// available.
func (tb *Bucket) Wait(count int64) {
if d := tb.Take(count); d > 0 {
tb.clock.Sleep(d)
}
}
// WaitMaxDuration is like Wait except that it will
// only take tokens from the bucket if it needs to wait
// for no greater than maxWait. It reports whether
// any tokens have been removed from the bucket
// If no tokens have been removed, it returns immediately.
func (tb *Bucket) WaitMaxDuration(count int64, maxWait time.Duration) bool {
d, ok := tb.TakeMaxDuration(count, maxWait)
if d > 0 {
tb.clock.Sleep(d)
}
return ok
}
const infinityDuration time.Duration = 0x7fffffffffffffff
// Take takes count tokens from the bucket without blocking. It returns
// the time that the caller should wait until the tokens are actually
// available.
//
// Note that if the request is irrevocable - there is no way to return
// tokens to the bucket once this method commits us to taking them.
func (tb *Bucket) Take(count int64) time.Duration {
d, _ := tb.take(tb.clock.Now(), count, infinityDuration)
return d
}
// TakeMaxDuration is like Take, except that
// it will only take tokens from the bucket if the wait
// time for the tokens is no greater than maxWait.
//
// If it would take longer than maxWait for the tokens
// to become available, it does nothing and reports false,
// otherwise it returns the time that the caller should
// wait until the tokens are actually available, and reports
// true.
func (tb *Bucket) TakeMaxDuration(count int64, maxWait time.Duration) (time.Duration, bool) {
return tb.take(tb.clock.Now(), count, maxWait)
}
// TakeAvailable takes up to count immediately available tokens from the
// bucket. It returns the number of tokens removed, or zero if there are
// no available tokens. It does not block.
func (tb *Bucket) TakeAvailable(count int64) int64 {
return tb.takeAvailable(tb.clock.Now(), count)
}
// takeAvailable is the internal version of TakeAvailable - it takes the
// current time as an argument to enable easy testing.
func (tb *Bucket) takeAvailable(now time.Time, count int64) int64 {
if count <= 0 {
return 0
}
tb.mu.Lock()
defer tb.mu.Unlock()
tb.adjust(now)
if tb.avail <= 0 {
return 0
}
if count > tb.avail {
count = tb.avail
}
tb.avail -= count
return count
}
// Available returns the number of available tokens. It will be negative
// when there are consumers waiting for tokens. Note that if this
// returns greater than zero, it does not guarantee that calls that take
// tokens from the buffer will succeed, as the number of available
// tokens could have changed in the meantime. This method is intended
// primarily for metrics reporting and debugging.
func (tb *Bucket) Available() int64 {
return tb.available(tb.clock.Now())
}
// available is the internal version of available - it takes the current time as
// an argument to enable easy testing.
func (tb *Bucket) available(now time.Time) int64 {
tb.mu.Lock()
defer tb.mu.Unlock()
tb.adjust(now)
return tb.avail
}
// Capacity returns the capacity that the bucket was created with.
func (tb *Bucket) Capacity() int64 {
return tb.capacity
}
// Rate returns the fill rate of the bucket, in tokens per second.
func (tb *Bucket) Rate() float64 {
return 1e9 * float64(tb.quantum) / float64(tb.fillInterval)
}
// take is the internal version of Take - it takes the current time as
// an argument to enable easy testing.
func (tb *Bucket) take(now time.Time, count int64, maxWait time.Duration) (time.Duration, bool) {
if count <= 0 {
return 0, true
}
tb.mu.Lock()
defer tb.mu.Unlock()
currentTick := tb.adjust(now)
avail := tb.avail - count
if avail >= 0 {
tb.avail = avail
return 0, true
}
// Round up the missing tokens to the nearest multiple
// of quantum - the tokens won't be available until
// that tick.
endTick := currentTick + (-avail+tb.quantum-1)/tb.quantum
endTime := tb.startTime.Add(time.Duration(endTick) * tb.fillInterval)
waitTime := endTime.Sub(now)
if waitTime > maxWait {
return 0, false
}
tb.avail = avail
return waitTime, true
}
// adjust adjusts the current bucket capacity based on the current time.
// It returns the current tick.
func (tb *Bucket) adjust(now time.Time) (currentTick int64) {
currentTick = int64(now.Sub(tb.startTime) / tb.fillInterval)
if tb.avail >= tb.capacity {
return
}
tb.avail += (currentTick - tb.availTick) * tb.quantum
if tb.avail > tb.capacity {
tb.avail = tb.capacity
}
tb.availTick = currentTick
return
}

View File

@ -1,51 +0,0 @@
// Copyright 2014 Canonical Ltd.
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.
package ratelimit
import "io"
type reader struct {
r io.Reader
bucket *Bucket
}
// Reader returns a reader that is rate limited by
// the given token bucket. Each token in the bucket
// represents one byte.
func Reader(r io.Reader, bucket *Bucket) io.Reader {
return &reader{
r: r,
bucket: bucket,
}
}
func (r *reader) Read(buf []byte) (int, error) {
n, err := r.r.Read(buf)
if n <= 0 {
return n, err
}
r.bucket.Wait(int64(n))
return n, err
}
type writer struct {
w io.Writer
bucket *Bucket
}
// Writer returns a reader that is rate limited by
// the given token bucket. Each token in the bucket
// represents one byte.
func Writer(w io.Writer, bucket *Bucket) io.Writer {
return &writer{
w: w,
bucket: bucket,
}
}
func (w *writer) Write(buf []byte) (int, error) {
w.bucket.Wait(int64(len(buf)))
return w.w.Write(buf)
}

3
vendor/golang.org/x/time/AUTHORS generated vendored Normal file
View File

@ -0,0 +1,3 @@
# This source code refers to The Go Authors for copyright purposes.
# The master list of authors is in the main Go distribution,
# visible at http://tip.golang.org/AUTHORS.

3
vendor/golang.org/x/time/CONTRIBUTORS generated vendored Normal file
View File

@ -0,0 +1,3 @@
# This source code was written by the Go contributors.
# The master list of contributors is in the main Go distribution,
# visible at http://tip.golang.org/CONTRIBUTORS.

27
vendor/golang.org/x/time/LICENSE generated vendored Normal file
View File

@ -0,0 +1,27 @@
Copyright (c) 2009 The Go Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

22
vendor/golang.org/x/time/PATENTS generated vendored Normal file
View File

@ -0,0 +1,22 @@
Additional IP Rights Grant (Patents)
"This implementation" means the copyrightable works distributed by
Google as part of the Go project.
Google hereby grants to You a perpetual, worldwide, non-exclusive,
no-charge, royalty-free, irrevocable (except as stated in this section)
patent license to make, have made, use, offer to sell, sell, import,
transfer and otherwise run, modify and propagate the contents of this
implementation of Go, where such license applies only to those patent
claims, both currently owned or controlled by Google and acquired in
the future, licensable by Google that are necessarily infringed by this
implementation of Go. This grant does not include claims that would be
infringed only as a consequence of further modification of this
implementation. If you or your agent or exclusive licensee institute or
order or agree to the institution of patent litigation against any
entity (including a cross-claim or counterclaim in a lawsuit) alleging
that this implementation of Go or any code incorporated within this
implementation of Go constitutes direct or contributory patent
infringement, or inducement of patent infringement, then any patent
rights granted to you under this License for this implementation of Go
shall terminate as of the date such litigation is filed.

371
vendor/golang.org/x/time/rate/rate.go generated vendored Normal file
View File

@ -0,0 +1,371 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package rate provides a rate limiter.
package rate
import (
"fmt"
"math"
"sync"
"time"
"golang.org/x/net/context"
)
// Limit defines the maximum frequency of some events.
// Limit is represented as number of events per second.
// A zero Limit allows no events.
type Limit float64
// Inf is the infinite rate limit; it allows all events (even if burst is zero).
const Inf = Limit(math.MaxFloat64)
// Every converts a minimum time interval between events to a Limit.
func Every(interval time.Duration) Limit {
if interval <= 0 {
return Inf
}
return 1 / Limit(interval.Seconds())
}
// A Limiter controls how frequently events are allowed to happen.
// It implements a "token bucket" of size b, initially full and refilled
// at rate r tokens per second.
// Informally, in any large enough time interval, the Limiter limits the
// rate to r tokens per second, with a maximum burst size of b events.
// As a special case, if r == Inf (the infinite rate), b is ignored.
// See https://en.wikipedia.org/wiki/Token_bucket for more about token buckets.
//
// The zero value is a valid Limiter, but it will reject all events.
// Use NewLimiter to create non-zero Limiters.
//
// Limiter has three main methods, Allow, Reserve, and Wait.
// Most callers should use Wait.
//
// Each of the three methods consumes a single token.
// They differ in their behavior when no token is available.
// If no token is available, Allow returns false.
// If no token is available, Reserve returns a reservation for a future token
// and the amount of time the caller must wait before using it.
// If no token is available, Wait blocks until one can be obtained
// or its associated context.Context is canceled.
//
// The methods AllowN, ReserveN, and WaitN consume n tokens.
type Limiter struct {
limit Limit
burst int
mu sync.Mutex
tokens float64
// last is the last time the limiter's tokens field was updated
last time.Time
// lastEvent is the latest time of a rate-limited event (past or future)
lastEvent time.Time
}
// Limit returns the maximum overall event rate.
func (lim *Limiter) Limit() Limit {
lim.mu.Lock()
defer lim.mu.Unlock()
return lim.limit
}
// Burst returns the maximum burst size. Burst is the maximum number of tokens
// that can be consumed in a single call to Allow, Reserve, or Wait, so higher
// Burst values allow more events to happen at once.
// A zero Burst allows no events, unless limit == Inf.
func (lim *Limiter) Burst() int {
return lim.burst
}
// NewLimiter returns a new Limiter that allows events up to rate r and permits
// bursts of at most b tokens.
func NewLimiter(r Limit, b int) *Limiter {
return &Limiter{
limit: r,
burst: b,
}
}
// Allow is shorthand for AllowN(time.Now(), 1).
func (lim *Limiter) Allow() bool {
return lim.AllowN(time.Now(), 1)
}
// AllowN reports whether n events may happen at time now.
// Use this method if you intend to drop / skip events that exceed the rate limit.
// Otherwise use Reserve or Wait.
func (lim *Limiter) AllowN(now time.Time, n int) bool {
return lim.reserveN(now, n, 0).ok
}
// A Reservation holds information about events that are permitted by a Limiter to happen after a delay.
// A Reservation may be canceled, which may enable the Limiter to permit additional events.
type Reservation struct {
ok bool
lim *Limiter
tokens int
timeToAct time.Time
// This is the Limit at reservation time, it can change later.
limit Limit
}
// OK returns whether the limiter can provide the requested number of tokens
// within the maximum wait time. If OK is false, Delay returns InfDuration, and
// Cancel does nothing.
func (r *Reservation) OK() bool {
return r.ok
}
// Delay is shorthand for DelayFrom(time.Now()).
func (r *Reservation) Delay() time.Duration {
return r.DelayFrom(time.Now())
}
// InfDuration is the duration returned by Delay when a Reservation is not OK.
const InfDuration = time.Duration(1<<63 - 1)
// DelayFrom returns the duration for which the reservation holder must wait
// before taking the reserved action. Zero duration means act immediately.
// InfDuration means the limiter cannot grant the tokens requested in this
// Reservation within the maximum wait time.
func (r *Reservation) DelayFrom(now time.Time) time.Duration {
if !r.ok {
return InfDuration
}
delay := r.timeToAct.Sub(now)
if delay < 0 {
return 0
}
return delay
}
// Cancel is shorthand for CancelAt(time.Now()).
func (r *Reservation) Cancel() {
r.CancelAt(time.Now())
return
}
// CancelAt indicates that the reservation holder will not perform the reserved action
// and reverses the effects of this Reservation on the rate limit as much as possible,
// considering that other reservations may have already been made.
func (r *Reservation) CancelAt(now time.Time) {
if !r.ok {
return
}
r.lim.mu.Lock()
defer r.lim.mu.Unlock()
if r.lim.limit == Inf || r.tokens == 0 || r.timeToAct.Before(now) {
return
}
// calculate tokens to restore
// The duration between lim.lastEvent and r.timeToAct tells us how many tokens were reserved
// after r was obtained. These tokens should not be restored.
restoreTokens := float64(r.tokens) - r.limit.tokensFromDuration(r.lim.lastEvent.Sub(r.timeToAct))
if restoreTokens <= 0 {
return
}
// advance time to now
now, _, tokens := r.lim.advance(now)
// calculate new number of tokens
tokens += restoreTokens
if burst := float64(r.lim.burst); tokens > burst {
tokens = burst
}
// update state
r.lim.last = now
r.lim.tokens = tokens
if r.timeToAct == r.lim.lastEvent {
prevEvent := r.timeToAct.Add(r.limit.durationFromTokens(float64(-r.tokens)))
if !prevEvent.Before(now) {
r.lim.lastEvent = prevEvent
}
}
return
}
// Reserve is shorthand for ReserveN(time.Now(), 1).
func (lim *Limiter) Reserve() *Reservation {
return lim.ReserveN(time.Now(), 1)
}
// ReserveN returns a Reservation that indicates how long the caller must wait before n events happen.
// The Limiter takes this Reservation into account when allowing future events.
// ReserveN returns false if n exceeds the Limiter's burst size.
// Usage example:
// r := lim.ReserveN(time.Now(), 1)
// if !r.OK() {
// // Not allowed to act! Did you remember to set lim.burst to be > 0 ?
// return
// }
// time.Sleep(r.Delay())
// Act()
// Use this method if you wish to wait and slow down in accordance with the rate limit without dropping events.
// If you need to respect a deadline or cancel the delay, use Wait instead.
// To drop or skip events exceeding rate limit, use Allow instead.
func (lim *Limiter) ReserveN(now time.Time, n int) *Reservation {
r := lim.reserveN(now, n, InfDuration)
return &r
}
// Wait is shorthand for WaitN(ctx, 1).
func (lim *Limiter) Wait(ctx context.Context) (err error) {
return lim.WaitN(ctx, 1)
}
// WaitN blocks until lim permits n events to happen.
// It returns an error if n exceeds the Limiter's burst size, the Context is
// canceled, or the expected wait time exceeds the Context's Deadline.
// The burst limit is ignored if the rate limit is Inf.
func (lim *Limiter) WaitN(ctx context.Context, n int) (err error) {
if n > lim.burst && lim.limit != Inf {
return fmt.Errorf("rate: Wait(n=%d) exceeds limiter's burst %d", n, lim.burst)
}
// Check if ctx is already cancelled
select {
case <-ctx.Done():
return ctx.Err()
default:
}
// Determine wait limit
now := time.Now()
waitLimit := InfDuration
if deadline, ok := ctx.Deadline(); ok {
waitLimit = deadline.Sub(now)
}
// Reserve
r := lim.reserveN(now, n, waitLimit)
if !r.ok {
return fmt.Errorf("rate: Wait(n=%d) would exceed context deadline", n)
}
// Wait
t := time.NewTimer(r.DelayFrom(now))
defer t.Stop()
select {
case <-t.C:
// We can proceed.
return nil
case <-ctx.Done():
// Context was canceled before we could proceed. Cancel the
// reservation, which may permit other events to proceed sooner.
r.Cancel()
return ctx.Err()
}
}
// SetLimit is shorthand for SetLimitAt(time.Now(), newLimit).
func (lim *Limiter) SetLimit(newLimit Limit) {
lim.SetLimitAt(time.Now(), newLimit)
}
// SetLimitAt sets a new Limit for the limiter. The new Limit, and Burst, may be violated
// or underutilized by those which reserved (using Reserve or Wait) but did not yet act
// before SetLimitAt was called.
func (lim *Limiter) SetLimitAt(now time.Time, newLimit Limit) {
lim.mu.Lock()
defer lim.mu.Unlock()
now, _, tokens := lim.advance(now)
lim.last = now
lim.tokens = tokens
lim.limit = newLimit
}
// reserveN is a helper method for AllowN, ReserveN, and WaitN.
// maxFutureReserve specifies the maximum reservation wait duration allowed.
// reserveN returns Reservation, not *Reservation, to avoid allocation in AllowN and WaitN.
func (lim *Limiter) reserveN(now time.Time, n int, maxFutureReserve time.Duration) Reservation {
lim.mu.Lock()
if lim.limit == Inf {
lim.mu.Unlock()
return Reservation{
ok: true,
lim: lim,
tokens: n,
timeToAct: now,
}
}
now, last, tokens := lim.advance(now)
// Calculate the remaining number of tokens resulting from the request.
tokens -= float64(n)
// Calculate the wait duration
var waitDuration time.Duration
if tokens < 0 {
waitDuration = lim.limit.durationFromTokens(-tokens)
}
// Decide result
ok := n <= lim.burst && waitDuration <= maxFutureReserve
// Prepare reservation
r := Reservation{
ok: ok,
lim: lim,
limit: lim.limit,
}
if ok {
r.tokens = n
r.timeToAct = now.Add(waitDuration)
}
// Update state
if ok {
lim.last = now
lim.tokens = tokens
lim.lastEvent = r.timeToAct
} else {
lim.last = last
}
lim.mu.Unlock()
return r
}
// advance calculates and returns an updated state for lim resulting from the passage of time.
// lim is not changed.
func (lim *Limiter) advance(now time.Time) (newNow time.Time, newLast time.Time, newTokens float64) {
last := lim.last
if now.Before(last) {
last = now
}
// Avoid making delta overflow below when last is very old.
maxElapsed := lim.limit.durationFromTokens(float64(lim.burst) - lim.tokens)
elapsed := now.Sub(last)
if elapsed > maxElapsed {
elapsed = maxElapsed
}
// Calculate the new number of tokens, due to time that passed.
delta := lim.limit.tokensFromDuration(elapsed)
tokens := lim.tokens + delta
if burst := float64(lim.burst); tokens > burst {
tokens = burst
}
return now, last, tokens
}
// durationFromTokens is a unit conversion function from the number of tokens to the duration
// of time it takes to accumulate them at a rate of limit tokens per second.
func (limit Limit) durationFromTokens(tokens float64) time.Duration {
seconds := tokens / float64(limit)
return time.Nanosecond * time.Duration(1e9*seconds)
}
// tokensFromDuration is a unit conversion function from a time duration to the number of tokens
// which could be accumulated during that duration at a rate of limit tokens per second.
func (limit Limit) tokensFromDuration(d time.Duration) float64 {
return d.Seconds() * float64(limit)
}

View File

@ -145,9 +145,9 @@ func (d *DiscoveryClient) ServerGroups() (apiGroupList *metav1.APIGroupList, err
apiGroupList = &metav1.APIGroupList{}
}
// append the group retrieved from /api to the list if not empty
// prepend the group retrieved from /api to the list if not empty
if len(v.Versions) != 0 {
apiGroupList.Groups = append(apiGroupList.Groups, apiGroup)
apiGroupList.Groups = append([]metav1.APIGroup{apiGroup}, apiGroupList.Groups...)
}
return apiGroupList, nil
}

View File

@ -25,7 +25,7 @@ go_library(
],
importpath = "k8s.io/client-go/util/flowcontrol",
deps = [
"//vendor/github.com/juju/ratelimit:go_default_library",
"//vendor/golang.org/x/time/rate:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library",
"//vendor/k8s.io/client-go/util/integer:go_default_library",
],

View File

@ -18,8 +18,9 @@ package flowcontrol
import (
"sync"
"time"
"github.com/juju/ratelimit"
"golang.org/x/time/rate"
)
type RateLimiter interface {
@ -30,17 +31,13 @@ type RateLimiter interface {
Accept()
// Stop stops the rate limiter, subsequent calls to CanAccept will return false
Stop()
// Saturation returns a percentage number which describes how saturated
// this rate limiter is.
// Usually we use token bucket rate limiter. In that case,
// 1.0 means no tokens are available; 0.0 means we have a full bucket of tokens to use.
Saturation() float64
// QPS returns QPS of this rate limiter
QPS() float32
}
type tokenBucketRateLimiter struct {
limiter *ratelimit.Bucket
limiter *rate.Limiter
clock Clock
qps float32
}
@ -50,42 +47,48 @@ type tokenBucketRateLimiter struct {
// The bucket is initially filled with 'burst' tokens, and refills at a rate of 'qps'.
// The maximum number of tokens in the bucket is capped at 'burst'.
func NewTokenBucketRateLimiter(qps float32, burst int) RateLimiter {
limiter := ratelimit.NewBucketWithRate(float64(qps), int64(burst))
return newTokenBucketRateLimiter(limiter, qps)
limiter := rate.NewLimiter(rate.Limit(qps), burst)
return newTokenBucketRateLimiter(limiter, realClock{}, qps)
}
// An injectable, mockable clock interface.
type Clock interface {
ratelimit.Clock
Now() time.Time
Sleep(time.Duration)
}
type realClock struct{}
func (realClock) Now() time.Time {
return time.Now()
}
func (realClock) Sleep(d time.Duration) {
time.Sleep(d)
}
// NewTokenBucketRateLimiterWithClock is identical to NewTokenBucketRateLimiter
// but allows an injectable clock, for testing.
func NewTokenBucketRateLimiterWithClock(qps float32, burst int, clock Clock) RateLimiter {
limiter := ratelimit.NewBucketWithRateAndClock(float64(qps), int64(burst), clock)
return newTokenBucketRateLimiter(limiter, qps)
func NewTokenBucketRateLimiterWithClock(qps float32, burst int, c Clock) RateLimiter {
limiter := rate.NewLimiter(rate.Limit(qps), burst)
return newTokenBucketRateLimiter(limiter, c, qps)
}
func newTokenBucketRateLimiter(limiter *ratelimit.Bucket, qps float32) RateLimiter {
func newTokenBucketRateLimiter(limiter *rate.Limiter, c Clock, qps float32) RateLimiter {
return &tokenBucketRateLimiter{
limiter: limiter,
clock: c,
qps: qps,
}
}
func (t *tokenBucketRateLimiter) TryAccept() bool {
return t.limiter.TakeAvailable(1) == 1
}
func (t *tokenBucketRateLimiter) Saturation() float64 {
capacity := t.limiter.Capacity()
avail := t.limiter.Available()
return float64(capacity-avail) / float64(capacity)
return t.limiter.AllowN(t.clock.Now(), 1)
}
// Accept will block until a token becomes available
func (t *tokenBucketRateLimiter) Accept() {
t.limiter.Wait(1)
now := t.clock.Now()
t.clock.Sleep(t.limiter.ReserveN(now, 1).DelayFrom(now))
}
func (t *tokenBucketRateLimiter) Stop() {
@ -105,10 +108,6 @@ func (t *fakeAlwaysRateLimiter) TryAccept() bool {
return true
}
func (t *fakeAlwaysRateLimiter) Saturation() float64 {
return 0
}
func (t *fakeAlwaysRateLimiter) Stop() {}
func (t *fakeAlwaysRateLimiter) Accept() {}
@ -131,10 +130,6 @@ func (t *fakeNeverRateLimiter) TryAccept() bool {
return false
}
func (t *fakeNeverRateLimiter) Saturation() float64 {
return 1
}
func (t *fakeNeverRateLimiter) Stop() {
t.wg.Done()
}

View File

@ -34,7 +34,7 @@ go_library(
],
importpath = "k8s.io/client-go/util/workqueue",
deps = [
"//vendor/github.com/juju/ratelimit:go_default_library",
"//vendor/golang.org/x/time/rate:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/clock:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
],

View File

@ -21,7 +21,7 @@ import (
"sync"
"time"
"github.com/juju/ratelimit"
"golang.org/x/time/rate"
)
type RateLimiter interface {
@ -40,19 +40,19 @@ func DefaultControllerRateLimiter() RateLimiter {
return NewMaxOfRateLimiter(
NewItemExponentialFailureRateLimiter(5*time.Millisecond, 1000*time.Second),
// 10 qps, 100 bucket size. This is only for retry speed and its only the overall factor (not per item)
&BucketRateLimiter{Bucket: ratelimit.NewBucketWithRate(float64(10), int64(100))},
&BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(10), 100)},
)
}
// BucketRateLimiter adapts a standard bucket to the workqueue ratelimiter API
type BucketRateLimiter struct {
*ratelimit.Bucket
*rate.Limiter
}
var _ RateLimiter = &BucketRateLimiter{}
func (r *BucketRateLimiter) When(item interface{}) time.Duration {
return r.Bucket.Take(1)
return r.Limiter.Reserve().Delay()
}
func (r *BucketRateLimiter) NumRequeues(item interface{}) int {