From 4e3b79aa5908c4e4b1c814e5f2e7c7c3c10d444b Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Wed, 4 Oct 2017 18:42:54 -0400 Subject: [PATCH] [client-go] avoid Registry in fake REST client Previously, the fake RESTClient in client-go required a Registry. It used the Registry to fetch the GroupVersion for the fake client. However, the way it did so was dubious in some cases (it hard-coded the default API group in places), and not strictly necssary. This updates the fake client to just recieve the GroupVersion and internal group name directly, instead of requiring a Registry, so that it can be consumed in unit tests where a Registry isn't necessarily readily available (e.g. elsewhere in client-go). Kubernetes-commit: eac2049fc9a151a7cbd6652e039506376574e0a9 --- rest/fake/BUILD | 1 - rest/fake/fake.go | 16 ++++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/rest/fake/BUILD b/rest/fake/BUILD index 524701f1..e511b207 100644 --- a/rest/fake/BUILD +++ b/rest/fake/BUILD @@ -10,7 +10,6 @@ go_library( srcs = ["fake.go"], importpath = "k8s.io/client-go/rest/fake", deps = [ - "//vendor/k8s.io/apimachinery/pkg/apimachinery/registered:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/types:go_default_library", diff --git a/rest/fake/fake.go b/rest/fake/fake.go index 2e1bc55a..db2c01c7 100644 --- a/rest/fake/fake.go +++ b/rest/fake/fake.go @@ -22,7 +22,6 @@ import ( "net/http" "net/url" - "k8s.io/apimachinery/pkg/apimachinery/registered" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/types" @@ -46,8 +45,7 @@ func (f roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) { type RESTClient struct { Client *http.Client NegotiatedSerializer runtime.NegotiatedSerializer - GroupName string - APIRegistry *registered.APIRegistrationManager + GroupVersion schema.GroupVersion VersionedAPIPath string Req *http.Request @@ -80,7 +78,7 @@ func (c *RESTClient) Verb(verb string) *restclient.Request { } func (c *RESTClient) APIVersion() schema.GroupVersion { - return c.APIRegistry.GroupOrDie("").GroupVersion + return c.GroupVersion } func (c *RESTClient) GetRateLimiter() flowcontrol.RateLimiter { @@ -89,22 +87,20 @@ func (c *RESTClient) GetRateLimiter() flowcontrol.RateLimiter { func (c *RESTClient) request(verb string) *restclient.Request { config := restclient.ContentConfig{ - ContentType: runtime.ContentTypeJSON, - // TODO this was hardcoded before, but it doesn't look right - GroupVersion: &c.APIRegistry.GroupOrDie("").GroupVersion, + ContentType: runtime.ContentTypeJSON, + GroupVersion: &c.GroupVersion, NegotiatedSerializer: c.NegotiatedSerializer, } ns := c.NegotiatedSerializer info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON) internalVersion := schema.GroupVersion{ - Group: c.APIRegistry.GroupOrDie(c.GroupName).GroupVersion.Group, + Group: c.GroupVersion.Group, Version: runtime.APIVersionInternal, } - internalVersion.Version = runtime.APIVersionInternal serializers := restclient.Serializers{ // TODO this was hardcoded before, but it doesn't look right - Encoder: ns.EncoderForVersion(info.Serializer, c.APIRegistry.GroupOrDie("").GroupVersion), + Encoder: ns.EncoderForVersion(info.Serializer, c.GroupVersion), Decoder: ns.DecoderToVersion(info.Serializer, internalVersion), } if info.StreamSerializer != nil {