github.com/aclisp/heapster@v0.19.2-0.20160613100040-51756f899a96/Godeps/_workspace/src/k8s.io/kubernetes/pkg/api/mapper.go (about) 1 /* 2 Copyright 2015 The Kubernetes Authors All rights reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package api 18 19 import ( 20 "strings" 21 22 "k8s.io/kubernetes/pkg/api/meta" 23 "k8s.io/kubernetes/pkg/api/unversioned" 24 "k8s.io/kubernetes/pkg/util/sets" 25 ) 26 27 var RESTMapper meta.RESTMapper 28 29 func init() { 30 RESTMapper = meta.MultiRESTMapper{} 31 } 32 33 func RegisterRESTMapper(m meta.RESTMapper) { 34 RESTMapper = append(RESTMapper.(meta.MultiRESTMapper), m) 35 } 36 37 func NewDefaultRESTMapper(defaultGroupVersions []unversioned.GroupVersion, interfacesFunc meta.VersionInterfacesFunc, 38 importPathPrefix string, ignoredKinds, rootScoped sets.String) *meta.DefaultRESTMapper { 39 40 mapper := meta.NewDefaultRESTMapper(defaultGroupVersions, interfacesFunc) 41 // enumerate all supported versions, get the kinds, and register with the mapper how to address 42 // our resources. 43 for _, gv := range defaultGroupVersions { 44 for kind, oType := range Scheme.KnownTypes(gv) { 45 gvk := gv.WithKind(kind) 46 // TODO: Remove import path check. 47 // We check the import path because we currently stuff both "api" and "extensions" objects 48 // into the same group within Scheme since Scheme has no notion of groups yet. 49 if !strings.Contains(oType.PkgPath(), importPathPrefix) || ignoredKinds.Has(kind) { 50 continue 51 } 52 scope := meta.RESTScopeNamespace 53 if rootScoped.Has(kind) { 54 scope = meta.RESTScopeRoot 55 } 56 mapper.Add(gvk, scope) 57 } 58 } 59 return mapper 60 }