mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-07 01:50:46 +00:00
Always negotiate a decoder using ClientNegotiator
This commit performs two refactors and fixes a bug. Refactor 1 changes the signature of Request to take a RESTClient, which removes the extra copy of everything on RESTClient from Request. A pair of optional constructors are added for testing. The major functional change is that Request no longer has the shim HTTPClient interface and so some test cases change slightly because we are now going through http.Client code paths instead of direct to our test stubs. Refactor 2 changes the signature of RESTClient to take a ClientContentConfig instead of ContentConfig - the primary difference being that ClientContentConfig uses ClientNegotiator instead of NegotiatedSerializer and the old Serializers type. We also collapse some redundancies (like the rate limiter can be created outside the constructor). The bug fix is to negotiate the streaming content type on a Watch() like we do for requests. We stop caching the decoder and simply resolve it on the request. We also clean up the dynamic client and remove the extra WatchSpecificVersions() method by providing a properly wrapped dynamic client. Kubernetes-commit: 3b780c64b89606f4e6b21f48fb9c305d5998b9e5
This commit is contained in:
committed by
Kubernetes Publisher
parent
881cd219a8
commit
9bbcc2938d
@@ -155,6 +155,59 @@ func TestRESTClientRequires(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRESTClientLimiter(t *testing.T) {
|
||||
testCases := []struct {
|
||||
Name string
|
||||
Config Config
|
||||
Limiter flowcontrol.RateLimiter
|
||||
}{
|
||||
{
|
||||
Config: Config{},
|
||||
Limiter: flowcontrol.NewTokenBucketRateLimiter(5, 10),
|
||||
},
|
||||
{
|
||||
Config: Config{QPS: 10},
|
||||
Limiter: flowcontrol.NewTokenBucketRateLimiter(10, 10),
|
||||
},
|
||||
{
|
||||
Config: Config{QPS: -1},
|
||||
Limiter: nil,
|
||||
},
|
||||
{
|
||||
Config: Config{
|
||||
RateLimiter: flowcontrol.NewTokenBucketRateLimiter(11, 12),
|
||||
},
|
||||
Limiter: flowcontrol.NewTokenBucketRateLimiter(11, 12),
|
||||
},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
t.Run("Versioned_"+testCase.Name, func(t *testing.T) {
|
||||
config := testCase.Config
|
||||
config.Host = "127.0.0.1"
|
||||
config.ContentConfig = ContentConfig{GroupVersion: &v1.SchemeGroupVersion, NegotiatedSerializer: scheme.Codecs}
|
||||
client, err := RESTClientFor(&config)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(testCase.Limiter, client.rateLimiter) {
|
||||
t.Fatalf("unexpected rate limiter: %#v", client.rateLimiter)
|
||||
}
|
||||
})
|
||||
t.Run("Unversioned_"+testCase.Name, func(t *testing.T) {
|
||||
config := testCase.Config
|
||||
config.Host = "127.0.0.1"
|
||||
config.ContentConfig = ContentConfig{GroupVersion: &v1.SchemeGroupVersion, NegotiatedSerializer: scheme.Codecs}
|
||||
client, err := UnversionedRESTClientFor(&config)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if !reflect.DeepEqual(testCase.Limiter, client.rateLimiter) {
|
||||
t.Fatalf("unexpected rate limiter: %#v", client.rateLimiter)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type fakeLimiter struct {
|
||||
FakeSaturation float64
|
||||
FakeQPS float32
|
||||
|
Reference in New Issue
Block a user