mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	apimachinery: remove misleading NewDefaultRESTMapper
This commit is contained in:
		@@ -31,7 +31,6 @@ go_test(
 | 
			
		||||
go_library(
 | 
			
		||||
    name = "go_default_library",
 | 
			
		||||
    srcs = [
 | 
			
		||||
        "default.go",
 | 
			
		||||
        "doc.go",
 | 
			
		||||
        "errors.go",
 | 
			
		||||
        "firsthit_restmapper.go",
 | 
			
		||||
@@ -54,7 +53,6 @@ go_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/util/errors:go_default_library",
 | 
			
		||||
        "//vendor/k8s.io/apimachinery/pkg/util/sets:go_default_library",
 | 
			
		||||
    ],
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,46 +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 (
 | 
			
		||||
	"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,
 | 
			
		||||
	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 := range scheme.KnownTypes(gv) {
 | 
			
		||||
			gvk := gv.WithKind(kind)
 | 
			
		||||
			if ignoredKinds.Has(kind) {
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			scope := RESTScopeNamespace
 | 
			
		||||
			if rootScoped.Has(kind) {
 | 
			
		||||
				scope = RESTScopeRoot
 | 
			
		||||
			}
 | 
			
		||||
			mapper.Add(gvk, scope)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return mapper
 | 
			
		||||
}
 | 
			
		||||
@@ -172,13 +172,21 @@ func (gmf *GroupMetaFactory) newRESTMapper(scheme *runtime.Scheme, externalVersi
 | 
			
		||||
		ignoredKinds = gmf.GroupArgs.IgnoredKinds
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return meta.NewDefaultRESTMapperFromScheme(
 | 
			
		||||
		externalVersions,
 | 
			
		||||
		groupMeta.InterfacesFor,
 | 
			
		||||
		ignoredKinds,
 | 
			
		||||
		rootScoped,
 | 
			
		||||
		scheme,
 | 
			
		||||
	)
 | 
			
		||||
	mapper := meta.NewDefaultRESTMapper(externalVersions, groupMeta.InterfacesFor)
 | 
			
		||||
	for _, gv := range externalVersions {
 | 
			
		||||
		for kind := range scheme.KnownTypes(gv) {
 | 
			
		||||
			if ignoredKinds.Has(kind) {
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			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.
 | 
			
		||||
 
 | 
			
		||||
@@ -167,7 +167,10 @@ func TestInstallAPIGroups(t *testing.T) {
 | 
			
		||||
			}, 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{
 | 
			
		||||
			GroupVersion:  gv,
 | 
			
		||||
			GroupVersions: []schema.GroupVersion{gv},
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user