Merge pull request #50094 from sttts/sttts-no-importprefix

Automatic merge from submit-queue (batch tested with PRs 50094, 48966, 49478, 50593, 49140)

apimachinery: remove pre-apigroups import path logic

Replacing #50093.
This commit is contained in:
Kubernetes Submit Queue 2017-08-14 12:14:55 -07:00 committed by GitHub
commit 9f902fef24
39 changed files with 26 additions and 108 deletions

View File

@ -35,7 +35,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: kubeadm.GroupName, GroupName: kubeadm.GroupName,
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm",
AddInternalObjectsToScheme: kubeadm.AddToScheme, AddInternalObjectsToScheme: kubeadm.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -35,7 +35,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: core.GroupName, GroupName: core.GroupName,
VersionPreferenceOrder: []string{corev1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{corev1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/kubernetes/federation/apis/core",
AddInternalObjectsToScheme: core.AddToScheme, AddInternalObjectsToScheme: core.AddToScheme,
RootScopedKinds: sets.NewString( RootScopedKinds: sets.NewString(
"Namespace", "Namespace",

View File

@ -37,7 +37,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: federation.GroupName, GroupName: federation.GroupName,
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/kubernetes/federation/apis/federation",
AddInternalObjectsToScheme: federation.AddToScheme, AddInternalObjectsToScheme: federation.AddToScheme,
RootScopedKinds: sets.NewString( RootScopedKinds: sets.NewString(
"Cluster", "Cluster",

View File

@ -37,7 +37,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: api.GroupName, GroupName: api.GroupName,
VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/core",
AddInternalObjectsToScheme: api.AddToScheme, AddInternalObjectsToScheme: api.AddToScheme,
RootScopedKinds: sets.NewString( RootScopedKinds: sets.NewString(
"Node", "Node",

View File

@ -38,7 +38,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: admission.GroupName, GroupName: admission.GroupName,
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/admission",
RootScopedKinds: sets.NewString("AdmissionReview"), RootScopedKinds: sets.NewString("AdmissionReview"),
AddInternalObjectsToScheme: admission.AddToScheme, AddInternalObjectsToScheme: admission.AddToScheme,
}, },

View File

@ -37,7 +37,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
GroupName: admissionregistration.GroupName, GroupName: admissionregistration.GroupName,
RootScopedKinds: sets.NewString("InitializerConfiguration", "ExternalAdmissionHookConfiguration"), RootScopedKinds: sets.NewString("InitializerConfiguration", "ExternalAdmissionHookConfiguration"),
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/admissionregistration",
AddInternalObjectsToScheme: admissionregistration.AddToScheme, AddInternalObjectsToScheme: admissionregistration.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -38,7 +38,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: apps.GroupName, GroupName: apps.GroupName,
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version, v1beta2.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version, v1beta2.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/apps",
AddInternalObjectsToScheme: apps.AddToScheme, AddInternalObjectsToScheme: apps.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -39,7 +39,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: authentication.GroupName, GroupName: authentication.GroupName,
VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version, v1beta1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version, v1beta1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/authentication",
RootScopedKinds: sets.NewString("TokenReview"), RootScopedKinds: sets.NewString("TokenReview"),
AddInternalObjectsToScheme: authentication.AddToScheme, AddInternalObjectsToScheme: authentication.AddToScheme,
}, },

View File

@ -39,7 +39,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: authorization.GroupName, GroupName: authorization.GroupName,
VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version, v1beta1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version, v1beta1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/authorization",
RootScopedKinds: sets.NewString("SubjectAccessReview", "SelfSubjectAccessReview"), RootScopedKinds: sets.NewString("SubjectAccessReview", "SelfSubjectAccessReview"),
AddInternalObjectsToScheme: authorization.AddToScheme, AddInternalObjectsToScheme: authorization.AddToScheme,
}, },

View File

@ -38,7 +38,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: autoscaling.GroupName, GroupName: autoscaling.GroupName,
VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version, v2alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version, v2alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/autoscaling",
AddInternalObjectsToScheme: autoscaling.AddToScheme, AddInternalObjectsToScheme: autoscaling.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -38,7 +38,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: batch.GroupName, GroupName: batch.GroupName,
VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version, v2alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version, v2alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/batch",
AddInternalObjectsToScheme: batch.AddToScheme, AddInternalObjectsToScheme: batch.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -38,7 +38,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: certificates.GroupName, GroupName: certificates.GroupName,
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/certificates",
RootScopedKinds: sets.NewString("CertificateSigningRequest"), RootScopedKinds: sets.NewString("CertificateSigningRequest"),
AddInternalObjectsToScheme: certificates.AddToScheme, AddInternalObjectsToScheme: certificates.AddToScheme,
}, },

View File

@ -37,7 +37,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: componentconfig.GroupName, GroupName: componentconfig.GroupName,
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/kubernetes/pkg/apis/componentconfig",
AddInternalObjectsToScheme: componentconfig.AddToScheme, AddInternalObjectsToScheme: componentconfig.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -38,7 +38,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: extensions.GroupName, GroupName: extensions.GroupName,
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/extensions",
RootScopedKinds: sets.NewString("PodSecurityPolicy", "ThirdPartyResource"), RootScopedKinds: sets.NewString("PodSecurityPolicy", "ThirdPartyResource"),
AddInternalObjectsToScheme: extensions.AddToScheme, AddInternalObjectsToScheme: extensions.AddToScheme,
}, },

View File

@ -38,7 +38,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: imagepolicy.GroupName, GroupName: imagepolicy.GroupName,
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/imagepolicy",
RootScopedKinds: sets.NewString("ImageReview"), RootScopedKinds: sets.NewString("ImageReview"),
AddInternalObjectsToScheme: imagepolicy.AddToScheme, AddInternalObjectsToScheme: imagepolicy.AddToScheme,
}, },

View File

@ -37,7 +37,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: networking.GroupName, GroupName: networking.GroupName,
VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/networking",
AddInternalObjectsToScheme: networking.AddToScheme, AddInternalObjectsToScheme: networking.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -37,7 +37,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: policy.GroupName, GroupName: policy.GroupName,
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/policy",
AddInternalObjectsToScheme: policy.AddToScheme, AddInternalObjectsToScheme: policy.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -50,7 +50,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
// 1.10 (once all stored objects are at v1): // 1.10 (once all stored objects are at v1):
// * remove v1alpha1 // * remove v1alpha1
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version, v1.SchemeGroupVersion.Version, v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version, v1.SchemeGroupVersion.Version, v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/rbac",
RootScopedKinds: sets.NewString("ClusterRole", "ClusterRoleBinding"), RootScopedKinds: sets.NewString("ClusterRole", "ClusterRoleBinding"),
AddInternalObjectsToScheme: rbac.AddToScheme, AddInternalObjectsToScheme: rbac.AddToScheme,
}, },

View File

@ -38,7 +38,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: scheduling.GroupName, GroupName: scheduling.GroupName,
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/scheduling",
RootScopedKinds: sets.NewString("PriorityClass"), RootScopedKinds: sets.NewString("PriorityClass"),
AddInternalObjectsToScheme: scheduling.AddToScheme, AddInternalObjectsToScheme: scheduling.AddToScheme,
}, },

View File

@ -37,7 +37,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: settings.GroupName, GroupName: settings.GroupName,
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/settings",
AddInternalObjectsToScheme: settings.AddToScheme, AddInternalObjectsToScheme: settings.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -39,7 +39,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: storage.GroupName, GroupName: storage.GroupName,
VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version, v1beta1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version, v1beta1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/api/storage",
RootScopedKinds: sets.NewString("StorageClass"), RootScopedKinds: sets.NewString("StorageClass"),
AddInternalObjectsToScheme: storage.AddToScheme, AddInternalObjectsToScheme: storage.AddToScheme,
}, },

View File

@ -32,7 +32,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: internalapi.GroupName, GroupName: internalapi.GroupName,
VersionPreferenceOrder: []string{versionedapi.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{versionedapi.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/kubernetes/plugin/pkg/admission/podtolerationrestriction/apis/podtolerationrestriction",
AddInternalObjectsToScheme: internalapi.AddToScheme, AddInternalObjectsToScheme: internalapi.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -32,7 +32,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: resourcequotaapi.GroupName, GroupName: resourcequotaapi.GroupName,
VersionPreferenceOrder: []string{resourcequotav1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{resourcequotav1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/kubernetes/plugin/pkg/admission/resourcequota/apis/resourcequota",
AddInternalObjectsToScheme: resourcequotaapi.AddToScheme, AddInternalObjectsToScheme: resourcequotaapi.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -32,7 +32,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
GroupName: apiextensions.GroupName, GroupName: apiextensions.GroupName,
RootScopedKinds: sets.NewString("CustomResourceDefinition"), RootScopedKinds: sets.NewString("CustomResourceDefinition"),
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/apiextensions-apiserver/pkg/apis/apiextension",
AddInternalObjectsToScheme: apiextensions.AddToScheme, AddInternalObjectsToScheme: apiextensions.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -28,7 +28,6 @@ go_test(
go_library( go_library(
name = "go_default_library", name = "go_default_library",
srcs = [ srcs = [
"default.go",
"doc.go", "doc.go",
"errors.go", "errors.go",
"firsthit_restmapper.go", "firsthit_restmapper.go",
@ -50,7 +49,6 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library", "//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library", "//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
], ],
) )

View File

@ -1,51 +0,0 @@
/*
Copyright 2015 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package meta
import (
"strings"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
)
// NewDefaultRESTMapperFromScheme instantiates a DefaultRESTMapper based on types registered in the given scheme.
func NewDefaultRESTMapperFromScheme(defaultGroupVersions []schema.GroupVersion, interfacesFunc VersionInterfacesFunc,
importPathPrefix string, ignoredKinds, rootScoped sets.String, scheme *runtime.Scheme) *DefaultRESTMapper {
mapper := NewDefaultRESTMapper(defaultGroupVersions, interfacesFunc)
// enumerate all supported versions, get the kinds, and register with the mapper how to address
// our resources.
for _, gv := range defaultGroupVersions {
for kind, oType := range scheme.KnownTypes(gv) {
gvk := gv.WithKind(kind)
// TODO: Remove import path check.
// We check the import path because we currently stuff both "api" and "extensions" objects
// into the same group within Scheme since Scheme has no notion of groups yet.
if !strings.Contains(oType.PkgPath(), importPathPrefix) || ignoredKinds.Has(kind) {
continue
}
scope := RESTScopeNamespace
if rootScoped.Has(kind) {
scope = RESTScopeRoot
}
mapper.Add(gvk, scope)
}
}
return mapper
}

View File

@ -30,7 +30,6 @@ func TestFactoryRegistry(t *testing.T) {
if err := regA.AnnounceGroup(&GroupMetaFactoryArgs{ if err := regA.AnnounceGroup(&GroupMetaFactoryArgs{
GroupName: "foo", GroupName: "foo",
VersionPreferenceOrder: []string{"v2", "v1"}, VersionPreferenceOrder: []string{"v2", "v1"},
ImportPrefix: "pkg/apis/foo",
RootScopedKinds: sets.NewString("namespaces"), RootScopedKinds: sets.NewString("namespaces"),
}); err != nil { }); err != nil {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
@ -52,7 +51,6 @@ func TestFactoryRegistry(t *testing.T) {
&GroupMetaFactoryArgs{ &GroupMetaFactoryArgs{
GroupName: "foo", GroupName: "foo",
VersionPreferenceOrder: []string{"v2", "v1"}, VersionPreferenceOrder: []string{"v2", "v1"},
ImportPrefix: "pkg/apis/foo",
RootScopedKinds: sets.NewString("namespaces"), RootScopedKinds: sets.NewString("namespaces"),
}, },
VersionToSchemeFunc{"v1": nil, "v2": nil}, VersionToSchemeFunc{"v1": nil, "v2": nil},

View File

@ -47,10 +47,6 @@ type GroupMetaFactoryArgs struct {
// example: 'servicecatalog.k8s.io' // example: 'servicecatalog.k8s.io'
GroupName string GroupName string
VersionPreferenceOrder []string VersionPreferenceOrder []string
// ImportPrefix is the base go package of the API-Group
//
// example: 'k8s.io/kubernetes/pkg/apis/autoscaling'
ImportPrefix string
// RootScopedKinds are resources that are not namespaced. // RootScopedKinds are resources that are not namespaced.
RootScopedKinds sets.String // nil is allowed RootScopedKinds sets.String // nil is allowed
IgnoredKinds sets.String // nil is allowed IgnoredKinds sets.String // nil is allowed
@ -176,14 +172,21 @@ func (gmf *GroupMetaFactory) newRESTMapper(scheme *runtime.Scheme, externalVersi
ignoredKinds = gmf.GroupArgs.IgnoredKinds ignoredKinds = gmf.GroupArgs.IgnoredKinds
} }
return meta.NewDefaultRESTMapperFromScheme( mapper := meta.NewDefaultRESTMapper(externalVersions, groupMeta.InterfacesFor)
externalVersions, for _, gv := range externalVersions {
groupMeta.InterfacesFor, for kind := range scheme.KnownTypes(gv) {
gmf.GroupArgs.ImportPrefix, if ignoredKinds.Has(kind) {
ignoredKinds, continue
rootScoped, }
scheme, scope := meta.RESTScopeNamespace
) if rootScoped.Has(kind) {
scope = meta.RESTScopeRoot
}
mapper.Add(gv.WithKind(kind), scope)
}
}
return mapper
} }
// Enable enables group versions that are allowed, adds methods to the scheme, etc. // Enable enables group versions that are allowed, adds methods to the scheme, etc.

View File

@ -32,7 +32,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: testapigroup.GroupName, GroupName: testapigroup.GroupName,
VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/apimachinery/pkg/apis/testapigroup",
AddInternalObjectsToScheme: testapigroup.AddToScheme, AddInternalObjectsToScheme: testapigroup.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -32,7 +32,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
GroupName: apiserver.GroupName, GroupName: apiserver.GroupName,
RootScopedKinds: sets.NewString("APIService"), RootScopedKinds: sets.NewString("APIService"),
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/apiserver/pkg/apis/apiserver",
AddInternalObjectsToScheme: apiserver.AddToScheme, AddInternalObjectsToScheme: apiserver.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -33,7 +33,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: audit.GroupName, GroupName: audit.GroupName,
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/apiserver/pkg/apis/audit",
// Any Kind that is not namespaced must be cluster scoped. // Any Kind that is not namespaced must be cluster scoped.
RootScopedKinds: sets.NewString("Event", "Policy"), RootScopedKinds: sets.NewString("Event", "Policy"),
AddInternalObjectsToScheme: audit.AddToScheme, AddInternalObjectsToScheme: audit.AddToScheme,

View File

@ -32,7 +32,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: example.GroupName, GroupName: example.GroupName,
VersionPreferenceOrder: []string{examplev1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{examplev1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/apiserver/pkg/apis/example",
AddInternalObjectsToScheme: example.AddToScheme, AddInternalObjectsToScheme: example.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -167,7 +167,10 @@ func TestInstallAPIGroups(t *testing.T) {
}, nil }, nil
} }
mapper := meta.NewDefaultRESTMapperFromScheme([]schema.GroupVersion{gv}, interfacesFor, "", sets.NewString(), sets.NewString(), scheme) mapper := meta.NewDefaultRESTMapper([]schema.GroupVersion{gv}, interfacesFor)
for kind := range scheme.KnownTypes(gv) {
mapper.Add(gv.WithKind(kind), meta.RESTScopeNamespace)
}
groupMeta := apimachinery.GroupMeta{ groupMeta := apimachinery.GroupMeta{
GroupVersion: gv, GroupVersion: gv,
GroupVersions: []schema.GroupVersion{gv}, GroupVersions: []schema.GroupVersion{gv},

View File

@ -32,7 +32,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
GroupName: apiregistration.GroupName, GroupName: apiregistration.GroupName,
RootScopedKinds: sets.NewString("APIService"), RootScopedKinds: sets.NewString("APIService"),
VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1beta1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/kube-aggregator/pkg/apis/apiregistration",
AddInternalObjectsToScheme: apiregistration.AddToScheme, AddInternalObjectsToScheme: apiregistration.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -32,7 +32,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: testgroup.SchemeGroupVersion.Group, GroupName: testgroup.SchemeGroupVersion.Group,
VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/kube-gen/test/apis/testgroup",
AddInternalObjectsToScheme: testgroup.AddToScheme, AddInternalObjectsToScheme: testgroup.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -32,7 +32,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: custom_metrics.GroupName, GroupName: custom_metrics.GroupName,
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/metrics/pkg/apis/custom_metrics",
AddInternalObjectsToScheme: custom_metrics.AddToScheme, AddInternalObjectsToScheme: custom_metrics.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -33,7 +33,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
&announced.GroupMetaFactoryArgs{ &announced.GroupMetaFactoryArgs{
GroupName: metrics.GroupName, GroupName: metrics.GroupName,
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/metrics/pkg/apis/metrics",
RootScopedKinds: sets.NewString("NodeMetrics"), RootScopedKinds: sets.NewString("NodeMetrics"),
AddInternalObjectsToScheme: metrics.AddToScheme, AddInternalObjectsToScheme: metrics.AddToScheme,
}, },

View File

@ -32,7 +32,6 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
GroupName: wardle.GroupName, GroupName: wardle.GroupName,
RootScopedKinds: sets.NewString("Fischer", "FischerList"), RootScopedKinds: sets.NewString("Fischer", "FischerList"),
VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version}, VersionPreferenceOrder: []string{v1alpha1.SchemeGroupVersion.Version},
ImportPrefix: "k8s.io/sample-apiserver/pkg/apis/wardle",
AddInternalObjectsToScheme: wardle.AddToScheme, AddInternalObjectsToScheme: wardle.AddToScheme,
}, },
announced.VersionToSchemeFunc{ announced.VersionToSchemeFunc{

View File

@ -438,7 +438,7 @@ var ephemeralWhiteList = createEphemeralWhiteList(
// -- // --
) )
// Only add kinds to this list when there is no mapping from GVK to GVR (and thus there is no way to create the object) // Only add kinds to this list when there is no way to create the object
var kindWhiteList = sets.NewString( var kindWhiteList = sets.NewString(
// k8s.io/kubernetes/pkg/api/v1 // k8s.io/kubernetes/pkg/api/v1
"DeleteOptions", "DeleteOptions",
@ -496,14 +496,14 @@ func TestEtcdStoragePath(t *testing.T) {
kind := gvk.Kind kind := gvk.Kind
pkgPath := apiType.PkgPath() pkgPath := apiType.PkgPath()
if kindWhiteList.Has(kind) {
kindSeen.Insert(kind)
continue
}
mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version) mapping, err := mapper.RESTMapping(gvk.GroupKind(), gvk.Version)
if err != nil { if err != nil {
kindSeen.Insert(kind) t.Errorf("unexpected error getting mapping for %s from %s with GVK %s: %v", kind, pkgPath, gvk, err)
if kindWhiteList.Has(kind) {
// t.Logf("skipping test for %s from %s because its GVK %s is whitelisted and has no mapping", kind, pkgPath, gvk)
} else {
t.Errorf("no mapping found for %s from %s but its GVK %s is not whitelisted", kind, pkgPath, gvk)
}
continue continue
} }