github.com/timstclair/heapster@v0.20.0-alpha1/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.String()) {
    45  			gvk := gv.WithKind(kind)
    46  
    47  			// TODO: Remove import path prefix check.
    48  			// We check the import path prefix because we currently stuff both "api" and "extensions" objects
    49  			// into the same group within Scheme since Scheme has no notion of groups yet.
    50  			if !strings.HasPrefix(oType.PkgPath(), importPathPrefix) || ignoredKinds.Has(kind) {
    51  				continue
    52  			}
    53  			scope := meta.RESTScopeNamespace
    54  			if rootScoped.Has(kind) {
    55  				scope = meta.RESTScopeRoot
    56  			}
    57  			mapper.Add(gvk, scope, false)
    58  		}
    59  	}
    60  	return mapper
    61  }