[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
This commit is contained in:
Solly Ross 2017-10-04 18:42:54 -04:00 committed by Kubernetes Publisher
parent d198d1dc19
commit 4e3b79aa59
2 changed files with 6 additions and 11 deletions

View File

@ -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",

View File

@ -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 {