stop duplicating preferred version order
Kubernetes-commit: a89291a5dec0b63809b875e912b1563d50f86dba
This commit is contained in:
parent
9bda5f118f
commit
3fa442d40a
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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/<group>
|
||||
groupPaths = append(groupPaths, APIGroupPrefix+"/"+api.GroupMeta.GroupVersions[0].Group) // /apis/<group>
|
||||
}
|
||||
|
||||
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 + /<group-version>
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue