From 456cbc011814120fb36f5dbfb75a09480edcdb37 Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Wed, 4 Oct 2017 18:42:54 -0400 Subject: [PATCH] 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: af2bb704411263e725c360f68d13c8cf233ecf91 --- 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 9b013d3e4..4cdf74821 100644 --- a/rest/fake/BUILD +++ b/rest/fake/BUILD @@ -9,7 +9,6 @@ go_library( name = "go_default_library", srcs = ["fake.go"], 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 2e1bc55a9..db2c01c71 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 {