github.com/enmand/kubernetes@v1.2.0-alpha.0/pkg/apis/experimental/install/install.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 install installs the experimental API group, making it available as 18 // an option to all of the API encoding/decoding machinery. 19 package install 20 21 import ( 22 "fmt" 23 "strings" 24 25 "github.com/golang/glog" 26 27 "k8s.io/kubernetes/pkg/api" 28 "k8s.io/kubernetes/pkg/api/latest" 29 "k8s.io/kubernetes/pkg/api/meta" 30 "k8s.io/kubernetes/pkg/api/registered" 31 apiutil "k8s.io/kubernetes/pkg/api/util" 32 _ "k8s.io/kubernetes/pkg/apis/experimental" 33 "k8s.io/kubernetes/pkg/apis/experimental/v1alpha1" 34 "k8s.io/kubernetes/pkg/runtime" 35 "k8s.io/kubernetes/pkg/util/sets" 36 ) 37 38 const importPrefix = "k8s.io/kubernetes/pkg/apis/experimental" 39 40 var accessor = meta.NewAccessor() 41 42 func init() { 43 groupMeta, err := latest.RegisterGroup("experimental") 44 if err != nil { 45 glog.V(4).Infof("%v", err) 46 return 47 } 48 registeredGroupVersions := registered.GroupVersionsForGroup("experimental") 49 groupVersion := registeredGroupVersions[0] 50 *groupMeta = latest.GroupMeta{ 51 GroupVersion: groupVersion, 52 Group: apiutil.GetGroup(groupVersion), 53 Version: apiutil.GetVersion(groupVersion), 54 Codec: runtime.CodecFor(api.Scheme, groupVersion), 55 } 56 var versions []string 57 var groupVersions []string 58 for i := len(registeredGroupVersions) - 1; i >= 0; i-- { 59 versions = append(versions, apiutil.GetVersion(registeredGroupVersions[i])) 60 groupVersions = append(groupVersions, registeredGroupVersions[i]) 61 } 62 groupMeta.Versions = versions 63 groupMeta.GroupVersions = groupVersions 64 65 groupMeta.SelfLinker = runtime.SelfLinker(accessor) 66 67 // the list of kinds that are scoped at the root of the api hierarchy 68 // if a kind is not enumerated here, it is assumed to have a namespace scope 69 rootScoped := sets.NewString() 70 71 ignoredKinds := sets.NewString() 72 73 groupMeta.RESTMapper = api.NewDefaultRESTMapper("experimental", groupVersions, interfacesFor, importPrefix, ignoredKinds, rootScoped) 74 api.RegisterRESTMapper(groupMeta.RESTMapper) 75 groupMeta.InterfacesFor = interfacesFor 76 } 77 78 // InterfacesFor returns the default Codec and ResourceVersioner for a given version 79 // string, or an error if the version is not known. 80 func interfacesFor(version string) (*meta.VersionInterfaces, error) { 81 switch version { 82 case "experimental/v1alpha1": 83 return &meta.VersionInterfaces{ 84 Codec: v1alpha1.Codec, 85 ObjectConvertor: api.Scheme, 86 MetadataAccessor: accessor, 87 }, nil 88 default: 89 g, _ := latest.Group("experimental") 90 return nil, fmt.Errorf("unsupported storage version: %s (valid: %s)", version, strings.Join(g.Versions, ", ")) 91 } 92 }