mirror of
https://github.com/kubernetes/client-go.git
synced 2025-12-25 22:22:28 +00:00
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
This commit is contained in:
committed by
Kubernetes Publisher
parent
8b23653518
commit
456cbc0118
@@ -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",
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user