forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.go
84 lines (68 loc) · 2.64 KB
/
install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package install
import (
"fmt"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api/meta"
"k8s.io/kubernetes/pkg/api/unversioned"
configapi "github.com/openshift/origin/pkg/cmd/server/api"
configapiv1 "github.com/openshift/origin/pkg/cmd/server/api/v1"
_ "github.com/openshift/origin/pkg/build/admission/defaults/api/install"
_ "github.com/openshift/origin/pkg/build/admission/overrides/api/install"
_ "github.com/openshift/origin/pkg/project/admission/requestlimit/api/install"
_ "github.com/openshift/origin/pkg/quota/admission/clusterresourceoverride/api/install"
_ "github.com/openshift/origin/pkg/quota/admission/runonceduration/api/install"
_ "github.com/openshift/origin/pkg/scheduler/admission/podnodeconstraints/api/install"
)
const importPrefix = "github.com/openshift/origin/pkg/cmd/server/api"
var accessor = meta.NewAccessor()
// availableVersions lists all known external versions for this group from most preferred to least preferred
var availableVersions = []unversioned.GroupVersion{configapiv1.SchemeGroupVersion}
func init() {
if err := enableVersions(availableVersions); err != nil {
panic(err)
}
}
// TODO: enableVersions should be centralized rather than spread in each API
// group.
// We can combine registered.RegisterVersions, registered.EnableVersions and
// registered.RegisterGroup once we have moved enableVersions there.
func enableVersions(externalVersions []unversioned.GroupVersion) error {
addVersionsToScheme(externalVersions...)
return nil
}
func addVersionsToScheme(externalVersions ...unversioned.GroupVersion) {
// add the internal version to Scheme
configapi.AddToScheme(configapi.Scheme)
// add the enabled external versions to Scheme
for _, v := range externalVersions {
switch v {
case configapiv1.SchemeGroupVersion:
configapiv1.AddToScheme(configapi.Scheme)
default:
glog.Errorf("Version %s is not known, so it will not be added to the Scheme.", v)
continue
}
}
}
func interfacesFor(version unversioned.GroupVersion) (*meta.VersionInterfaces, error) {
switch version {
case configapiv1.SchemeGroupVersion:
return &meta.VersionInterfaces{
ObjectConvertor: configapi.Scheme,
MetadataAccessor: accessor,
}, nil
default:
return nil, fmt.Errorf("unsupported storage version: %s", version)
}
}
func NewRESTMapper() meta.RESTMapper {
mapper := meta.NewDefaultRESTMapper(availableVersions, interfacesFor)
// enumerate all supported versions, get the kinds, and register with the mapper how to address
// our resources.
for _, gv := range availableVersions {
for kind := range configapi.Scheme.KnownTypes(gv) {
mapper.Add(gv.WithKind(kind), meta.RESTScopeRoot)
}
}
return mapper
}