From 3fa442d40a3bce900be5652512578d4cb73ca41c Mon Sep 17 00:00:00 2001 From: David Eads Date: Thu, 26 Apr 2018 09:38:43 -0400 Subject: [PATCH] stop duplicating preferred version order Kubernetes-commit: a89291a5dec0b63809b875e912b1563d50f86dba --- pkg/server/genericapiserver.go | 10 +++++----- pkg/server/genericapiserver_test.go | 11 +++++------ pkg/server/resourceconfig/helpers_test.go | 2 -- pkg/server/storage/resource_encoding_config.go | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pkg/server/genericapiserver.go b/pkg/server/genericapiserver.go index 60402c9b7..6e25a9391 100644 --- a/pkg/server/genericapiserver.go +++ b/pkg/server/genericapiserver.go @@ -358,10 +358,10 @@ func (s *GenericAPIServer) InstallLegacyAPIGroup(apiPrefix string, apiGroupInfo func (s *GenericAPIServer) InstallAPIGroup(apiGroupInfo *APIGroupInfo) error { // Do not register empty group or empty version. Doing so claims /apis/ for the wrong entity to be returned. // Catching these here places the error much closer to its origin - if len(apiGroupInfo.GroupMeta.GroupVersion.Group) == 0 { + if len(apiGroupInfo.GroupMeta.GroupVersions[0].Group) == 0 { return fmt.Errorf("cannot register handler with an empty group for %#v", *apiGroupInfo) } - if len(apiGroupInfo.GroupMeta.GroupVersion.Version) == 0 { + if len(apiGroupInfo.GroupMeta.GroupVersions[0].Version) == 0 { return fmt.Errorf("cannot register handler with an empty version for %#v", *apiGroupInfo) } @@ -384,11 +384,11 @@ func (s *GenericAPIServer) InstallAPIGroup(apiGroupInfo *APIGroupInfo) error { }) } preferredVersionForDiscovery := metav1.GroupVersionForDiscovery{ - GroupVersion: apiGroupInfo.GroupMeta.GroupVersion.String(), - Version: apiGroupInfo.GroupMeta.GroupVersion.Version, + GroupVersion: apiGroupInfo.GroupMeta.GroupVersions[0].String(), + Version: apiGroupInfo.GroupMeta.GroupVersions[0].Version, } apiGroup := metav1.APIGroup{ - Name: apiGroupInfo.GroupMeta.GroupVersion.Group, + Name: apiGroupInfo.GroupMeta.GroupVersions[0].Group, Versions: apiVersionsForDiscovery, PreferredVersion: preferredVersionForDiscovery, } diff --git a/pkg/server/genericapiserver_test.go b/pkg/server/genericapiserver_test.go index 455e7d589..82046c952 100644 --- a/pkg/server/genericapiserver_test.go +++ b/pkg/server/genericapiserver_test.go @@ -164,7 +164,6 @@ func TestInstallAPIGroups(t *testing.T) { mapper.Add(gv.WithKind(kind), meta.RESTScopeNamespace) } groupMeta := apimachinery.GroupMeta{ - GroupVersion: gv, GroupVersions: []schema.GroupVersion{gv}, RESTMapper: mapper, InterfacesFor: interfacesFor, @@ -199,7 +198,7 @@ func TestInstallAPIGroups(t *testing.T) { for _, api := range apis[1:] { err = s.InstallAPIGroup(&api) assert.NoError(err) - groupPaths = append(groupPaths, APIGroupPrefix+"/"+api.GroupMeta.GroupVersion.Group) // /apis/ + groupPaths = append(groupPaths, APIGroupPrefix+"/"+api.GroupMeta.GroupVersions[0].Group) // /apis/ } server := httptest.NewServer(s.Handler) @@ -240,19 +239,19 @@ func TestInstallAPIGroups(t *testing.T) { continue } - if got, expected := group.Name, info.GroupMeta.GroupVersion.Group; got != expected { + if got, expected := group.Name, info.GroupMeta.GroupVersions[0].Group; got != expected { t.Errorf("[%d] unexpected group name at path %q: got=%q expected=%q", i, path, got, expected) continue } - if got, expected := group.PreferredVersion.Version, info.GroupMeta.GroupVersion.Version; got != expected { + if got, expected := group.PreferredVersion.Version, info.GroupMeta.GroupVersions[0].Version; got != expected { t.Errorf("[%d] unexpected group version at path %q: got=%q expected=%q", i, path, got, expected) continue } } // should serve APIResourceList at group path + / - path = path + "/" + info.GroupMeta.GroupVersion.Version + path = path + "/" + info.GroupMeta.GroupVersions[0].Version resp, err = http.Get(server.URL + path) if err != nil { t.Errorf("[%d] unexpected error getting path %q path: %v", i, path, err) @@ -274,7 +273,7 @@ func TestInstallAPIGroups(t *testing.T) { continue } - if got, expected := resources.GroupVersion, info.GroupMeta.GroupVersion.String(); got != expected { + if got, expected := resources.GroupVersion, info.GroupMeta.GroupVersions[0].String(); got != expected { t.Errorf("[%d] unexpected groupVersion at path %q: got=%q expected=%q", i, path, got, expected) continue } diff --git a/pkg/server/resourceconfig/helpers_test.go b/pkg/server/resourceconfig/helpers_test.go index 29a44cc1e..76a1086e6 100644 --- a/pkg/server/resourceconfig/helpers_test.go +++ b/pkg/server/resourceconfig/helpers_test.go @@ -169,11 +169,9 @@ func newFakeRegistry() *registered.APIRegistrationManager { registry := registered.NewAPIRegistrationManager() registry.RegisterGroup(apimachinery.GroupMeta{ - GroupVersion: apiv1.SchemeGroupVersion, GroupVersions: []schema.GroupVersion{apiv1.SchemeGroupVersion}, }) registry.RegisterGroup(apimachinery.GroupMeta{ - GroupVersion: extensionsapiv1beta1.SchemeGroupVersion, GroupVersions: []schema.GroupVersion{extensionsapiv1beta1.SchemeGroupVersion}, }) registry.RegisterVersions([]schema.GroupVersion{apiv1.SchemeGroupVersion, extensionsapiv1beta1.SchemeGroupVersion}) diff --git a/pkg/server/storage/resource_encoding_config.go b/pkg/server/storage/resource_encoding_config.go index 78cb865b7..554cb6c35 100644 --- a/pkg/server/storage/resource_encoding_config.go +++ b/pkg/server/storage/resource_encoding_config.go @@ -89,7 +89,7 @@ func (o *DefaultResourceEncodingConfig) StorageEncodingFor(resource schema.Group if !groupExists { // return the most preferred external version for the group - return groupMeta.GroupVersion, nil + return groupMeta.GroupVersions[0], nil } resourceOverride, resourceExists := groupEncoding.ExternalResourceEncodings[resource.Resource]