From 8ea8479b92afe437270f5b9162839f8a2740e0af Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Fri, 27 Oct 2017 04:22:39 -0400 Subject: [PATCH 1/2] Specify correct subresource discovery info Kubernetes-commit: 729a0da155871de445ea2116cf6457e29e313d08 --- pkg/endpoints/installer.go | 2 +- pkg/registry/rest/rest.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/endpoints/installer.go b/pkg/endpoints/installer.go index b6c0ccad4..bb82e4139 100644 --- a/pkg/endpoints/installer.go +++ b/pkg/endpoints/installer.go @@ -878,7 +878,7 @@ func (a *APIInstaller) registerResourceHandlers(path string, storage rest.Storag apiResource.Categories = categoriesProvider.Categories() } if gvkProvider, ok := storage.(rest.GroupVersionKindProvider); ok { - gvk := gvkProvider.GroupVersionKind() + gvk := gvkProvider.GroupVersionKind(a.group.GroupVersion) apiResource.Group = gvk.Group apiResource.Version = gvk.Version apiResource.Kind = gvk.Kind diff --git a/pkg/registry/rest/rest.go b/pkg/registry/rest/rest.go index 42a3b0973..21673110f 100644 --- a/pkg/registry/rest/rest.go +++ b/pkg/registry/rest/rest.go @@ -82,7 +82,7 @@ type CategoriesProvider interface { // This trumps KindProvider since it is capable of providing the information required. // TODO KindProvider (only used by federation) should be removed and replaced with this, but that presents greater risk late in 1.8. type GroupVersionKindProvider interface { - GroupVersionKind() schema.GroupVersionKind + GroupVersionKind(containingGV schema.GroupVersion) schema.GroupVersionKind } // Lister is an object that can retrieve resources that match the provided field and label criteria. From 198ca9b2e06f7d169b7a68d8d4a2e942f37ccc46 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Fri, 27 Oct 2017 04:29:04 -0400 Subject: [PATCH 2/2] Use GVK from storage in API registration Kubernetes-commit: 5913fccada6097c984b168ab15c243a8b20876e5 --- pkg/endpoints/apiserver_test.go | 14 +++++++++----- pkg/endpoints/groupversion.go | 6 ------ pkg/endpoints/installer.go | 11 +++-------- pkg/server/genericapiserver.go | 11 ++--------- 4 files changed, 14 insertions(+), 28 deletions(-) diff --git a/pkg/endpoints/apiserver_test.go b/pkg/endpoints/apiserver_test.go index f6ac5353f..4dd05a8be 100644 --- a/pkg/endpoints/apiserver_test.go +++ b/pkg/endpoints/apiserver_test.go @@ -3867,7 +3867,8 @@ func TestUpdateChecksAPIVersion(t *testing.T) { } type SimpleXGSubresourceRESTStorage struct { - item genericapitesting.SimpleXGSubresource + item genericapitesting.SimpleXGSubresource + itemGVK schema.GroupVersionKind } func (storage *SimpleXGSubresourceRESTStorage) New() runtime.Object { @@ -3878,6 +3879,12 @@ func (storage *SimpleXGSubresourceRESTStorage) Get(ctx request.Context, id strin return storage.item.DeepCopyObject(), nil } +var _ = rest.GroupVersionKindProvider(&SimpleXGSubresourceRESTStorage{}) + +func (storage *SimpleXGSubresourceRESTStorage) GroupVersionKind(containingGV schema.GroupVersion) schema.GroupVersionKind { + return storage.itemGVK +} + func TestXGSubresource(t *testing.T) { container := restful.NewContainer() container.Router(restful.CurlyRouter{}) @@ -3888,6 +3895,7 @@ func TestXGSubresource(t *testing.T) { item: genericapitesting.SimpleXGSubresource{ SubresourceInfo: "foo", }, + itemGVK: testGroup2Version.WithKind("SimpleXGSubresource"), } storage := map[string]rest.Storage{ "simple": &SimpleRESTStorage{}, @@ -3913,10 +3921,6 @@ func TestXGSubresource(t *testing.T) { GroupVersion: testGroupVersion, OptionsExternalVersion: &testGroupVersion, Serializer: codecs, - - SubresourceGroupVersionKind: map[string]schema.GroupVersionKind{ - "simple/subsimple": testGroup2Version.WithKind("SimpleXGSubresource"), - }, } if err := (&group).InstallREST(container); err != nil { diff --git a/pkg/endpoints/groupversion.go b/pkg/endpoints/groupversion.go index a60e45631..4b8823758 100644 --- a/pkg/endpoints/groupversion.go +++ b/pkg/endpoints/groupversion.go @@ -75,12 +75,6 @@ type APIGroupVersion struct { MinRequestTimeout time.Duration - // SubresourceGroupVersionKind contains the GroupVersionKind overrides for each subresource that is - // accessible from this API group version. The GroupVersionKind is that of the external version of - // the subresource. The key of this map should be the path of the subresource. The keys here should - // match the keys in the Storage map above for subresources. - SubresourceGroupVersionKind map[string]schema.GroupVersionKind - // EnableAPIResponseCompression indicates whether API Responses should support compression // if the client requests it via Accept-Encoding EnableAPIResponseCompression bool diff --git a/pkg/endpoints/installer.go b/pkg/endpoints/installer.go index bb82e4139..87bf1700d 100644 --- a/pkg/endpoints/installer.go +++ b/pkg/endpoints/installer.go @@ -144,8 +144,9 @@ func (a *APIInstaller) newWebService() *restful.WebService { // object. If the storage object is a subresource and has an override supplied for it, it returns // the group version kind supplied in the override. func (a *APIInstaller) getResourceKind(path string, storage rest.Storage) (schema.GroupVersionKind, error) { - if fqKindToRegister, ok := a.group.SubresourceGroupVersionKind[path]; ok { - return fqKindToRegister, nil + // Let the storage tell us exactly what GVK it has + if gvkProvider, ok := storage.(rest.GroupVersionKindProvider); ok { + return gvkProvider.GroupVersionKind(a.group.GroupVersion), nil } object := storage.New() @@ -162,12 +163,6 @@ func (a *APIInstaller) getResourceKind(path string, storage rest.Storage) (schem fqKindToRegister = a.group.GroupVersion.WithKind(fqKind.Kind) break } - - // TODO: keep rid of extensions api group dependency here - // This keeps it doing what it was doing before, but it doesn't feel right. - if fqKind.Group == "extensions" && fqKind.Kind == "ThirdPartyResourceData" { - fqKindToRegister = a.group.GroupVersion.WithKind(fqKind.Kind) - } } if fqKindToRegister.Empty() { return schema.GroupVersionKind{}, fmt.Errorf("unable to locate fully qualified kind for %v: found %v when registering for %v", reflect.TypeOf(object), fqKinds, a.group.GroupVersion) diff --git a/pkg/server/genericapiserver.go b/pkg/server/genericapiserver.go index 6dc65a20c..3109bb356 100644 --- a/pkg/server/genericapiserver.go +++ b/pkg/server/genericapiserver.go @@ -70,12 +70,6 @@ type APIGroupInfo struct { NegotiatedSerializer runtime.NegotiatedSerializer // ParameterCodec performs conversions for query parameters passed to API calls ParameterCodec runtime.ParameterCodec - - // SubresourceGroupVersionKind contains the GroupVersionKind overrides for each subresource that is - // accessible from this API group version. The GroupVersionKind is that of the external version of - // the subresource. The key of this map should be the path of the subresource. The keys here should - // match the keys in the Storage map above for subresources. - SubresourceGroupVersionKind map[string]schema.GroupVersionKind } // GenericAPIServer contains state for a Kubernetes cluster api server. @@ -435,9 +429,8 @@ func (s *GenericAPIServer) newAPIGroupVersion(apiGroupInfo *APIGroupInfo, groupV UnsafeConvertor: runtime.UnsafeObjectConvertor(apiGroupInfo.Scheme), Defaulter: apiGroupInfo.Scheme, Typer: apiGroupInfo.Scheme, - SubresourceGroupVersionKind: apiGroupInfo.SubresourceGroupVersionKind, - Linker: apiGroupInfo.GroupMeta.SelfLinker, - Mapper: apiGroupInfo.GroupMeta.RESTMapper, + Linker: apiGroupInfo.GroupMeta.SelfLinker, + Mapper: apiGroupInfo.GroupMeta.RESTMapper, Admit: s.admissionControl, Context: s.RequestContextMapper(),