mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-11 20:21:34 +00:00
[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:
parent
d198d1dc19
commit
4e3b79aa59
@ -10,7 +10,6 @@ go_library(
|
|||||||
srcs = ["fake.go"],
|
srcs = ["fake.go"],
|
||||||
importpath = "k8s.io/client-go/rest/fake",
|
importpath = "k8s.io/client-go/rest/fake",
|
||||||
deps = [
|
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:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||||
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/apimachinery/registered"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
@ -46,8 +45,7 @@ func (f roundTripperFunc) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||||||
type RESTClient struct {
|
type RESTClient struct {
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
NegotiatedSerializer runtime.NegotiatedSerializer
|
NegotiatedSerializer runtime.NegotiatedSerializer
|
||||||
GroupName string
|
GroupVersion schema.GroupVersion
|
||||||
APIRegistry *registered.APIRegistrationManager
|
|
||||||
VersionedAPIPath string
|
VersionedAPIPath string
|
||||||
|
|
||||||
Req *http.Request
|
Req *http.Request
|
||||||
@ -80,7 +78,7 @@ func (c *RESTClient) Verb(verb string) *restclient.Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *RESTClient) APIVersion() schema.GroupVersion {
|
func (c *RESTClient) APIVersion() schema.GroupVersion {
|
||||||
return c.APIRegistry.GroupOrDie("").GroupVersion
|
return c.GroupVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RESTClient) GetRateLimiter() flowcontrol.RateLimiter {
|
func (c *RESTClient) GetRateLimiter() flowcontrol.RateLimiter {
|
||||||
@ -90,21 +88,19 @@ func (c *RESTClient) GetRateLimiter() flowcontrol.RateLimiter {
|
|||||||
func (c *RESTClient) request(verb string) *restclient.Request {
|
func (c *RESTClient) request(verb string) *restclient.Request {
|
||||||
config := restclient.ContentConfig{
|
config := restclient.ContentConfig{
|
||||||
ContentType: runtime.ContentTypeJSON,
|
ContentType: runtime.ContentTypeJSON,
|
||||||
// TODO this was hardcoded before, but it doesn't look right
|
GroupVersion: &c.GroupVersion,
|
||||||
GroupVersion: &c.APIRegistry.GroupOrDie("").GroupVersion,
|
|
||||||
NegotiatedSerializer: c.NegotiatedSerializer,
|
NegotiatedSerializer: c.NegotiatedSerializer,
|
||||||
}
|
}
|
||||||
|
|
||||||
ns := c.NegotiatedSerializer
|
ns := c.NegotiatedSerializer
|
||||||
info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON)
|
info, _ := runtime.SerializerInfoForMediaType(ns.SupportedMediaTypes(), runtime.ContentTypeJSON)
|
||||||
internalVersion := schema.GroupVersion{
|
internalVersion := schema.GroupVersion{
|
||||||
Group: c.APIRegistry.GroupOrDie(c.GroupName).GroupVersion.Group,
|
Group: c.GroupVersion.Group,
|
||||||
Version: runtime.APIVersionInternal,
|
Version: runtime.APIVersionInternal,
|
||||||
}
|
}
|
||||||
internalVersion.Version = runtime.APIVersionInternal
|
|
||||||
serializers := restclient.Serializers{
|
serializers := restclient.Serializers{
|
||||||
// TODO this was hardcoded before, but it doesn't look right
|
// 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),
|
Decoder: ns.DecoderToVersion(info.Serializer, internalVersion),
|
||||||
}
|
}
|
||||||
if info.StreamSerializer != nil {
|
if info.StreamSerializer != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user