From 7fd5822a0856433177a4a0dc7bb1c20ebc5cb087 Mon Sep 17 00:00:00 2001 From: David Eads Date: Mon, 21 Feb 2022 16:10:25 -0500 Subject: [PATCH] migrate more rest handlers to select by resource enablement Kubernetes-commit: 0ec20f97d27e08be8d8bbbbff52e68a4409ab43c --- pkg/server/genericapiserver.go | 14 ++++++++++---- pkg/server/storage/resource_config.go | 1 - 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/server/genericapiserver.go b/pkg/server/genericapiserver.go index c530bb599..d736465bd 100644 --- a/pkg/server/genericapiserver.go +++ b/pkg/server/genericapiserver.go @@ -539,7 +539,10 @@ func (s *GenericAPIServer) installAPIResources(apiPrefix string, apiGroupInfo *A continue } - apiGroupVersion := s.getAPIGroupVersion(apiGroupInfo, groupVersion, apiPrefix) + apiGroupVersion, err := s.getAPIGroupVersion(apiGroupInfo, groupVersion, apiPrefix) + if err != nil { + return err + } if apiGroupInfo.OptionsExternalVersion != nil { apiGroupVersion.OptionsExternalVersion = apiGroupInfo.OptionsExternalVersion } @@ -652,15 +655,18 @@ func (s *GenericAPIServer) InstallAPIGroup(apiGroupInfo *APIGroupInfo) error { return s.InstallAPIGroups(apiGroupInfo) } -func (s *GenericAPIServer) getAPIGroupVersion(apiGroupInfo *APIGroupInfo, groupVersion schema.GroupVersion, apiPrefix string) *genericapi.APIGroupVersion { +func (s *GenericAPIServer) getAPIGroupVersion(apiGroupInfo *APIGroupInfo, groupVersion schema.GroupVersion, apiPrefix string) (*genericapi.APIGroupVersion, error) { storage := make(map[string]rest.Storage) for k, v := range apiGroupInfo.VersionedResourcesStorageMap[groupVersion.Version] { - storage[strings.ToLower(k)] = v + if strings.ToLower(k) != k { + return nil, fmt.Errorf("resource names must be lowercase only, not %q", k) + } + storage[k] = v } version := s.newAPIGroupVersion(apiGroupInfo, groupVersion) version.Root = apiPrefix version.Storage = storage - return version + return version, nil } func (s *GenericAPIServer) newAPIGroupVersion(apiGroupInfo *APIGroupInfo, groupVersion schema.GroupVersion) *genericapi.APIGroupVersion { diff --git a/pkg/server/storage/resource_config.go b/pkg/server/storage/resource_config.go index 78771148d..7a409f566 100644 --- a/pkg/server/storage/resource_config.go +++ b/pkg/server/storage/resource_config.go @@ -22,7 +22,6 @@ import ( // APIResourceConfigSource is the interface to determine which groups and versions are enabled type APIResourceConfigSource interface { - VersionEnabled(version schema.GroupVersion) bool ResourceEnabled(resource schema.GroupVersionResource) bool AnyResourceForGroupEnabled(group string) bool }