|
1 | 1 | package install
|
2 | 2 |
|
3 | 3 | import (
|
4 |
| - "fmt" |
5 |
| - |
6 |
| - "github.com/golang/glog" |
7 |
| - |
8 |
| - "k8s.io/apimachinery/pkg/api/meta" |
9 |
| - "k8s.io/apimachinery/pkg/apimachinery" |
| 4 | + "k8s.io/apimachinery/pkg/apimachinery/announced" |
| 5 | + "k8s.io/apimachinery/pkg/apimachinery/registered" |
10 | 6 | "k8s.io/apimachinery/pkg/runtime"
|
11 |
| - "k8s.io/apimachinery/pkg/runtime/schema" |
12 | 7 | "k8s.io/apimachinery/pkg/util/sets"
|
13 | 8 | kapi "k8s.io/kubernetes/pkg/api"
|
14 | 9 |
|
| 10 | + "github.com/openshift/origin/pkg/api/legacy" |
15 | 11 | authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
|
16 | 12 | authorizationapiv1 "github.com/openshift/origin/pkg/authorization/apis/authorization/v1"
|
17 | 13 | )
|
18 | 14 |
|
19 |
| -var accessor = meta.NewAccessor() |
20 |
| - |
21 |
| -// availableVersions lists all known external versions for this group from most preferred to least preferred |
22 |
| -var availableVersions = []schema.GroupVersion{authorizationapiv1.LegacySchemeGroupVersion} |
23 |
| - |
24 | 15 | func init() {
|
25 |
| - kapi.Registry.RegisterVersions(availableVersions) |
26 |
| - externalVersions := []schema.GroupVersion{} |
27 |
| - for _, v := range availableVersions { |
28 |
| - if kapi.Registry.IsAllowedVersion(v) { |
29 |
| - externalVersions = append(externalVersions, v) |
30 |
| - } |
31 |
| - } |
32 |
| - if len(externalVersions) == 0 { |
33 |
| - glog.Infof("No version is registered for group %v", authorizationapi.GroupName) |
34 |
| - return |
35 |
| - } |
36 |
| - |
37 |
| - if err := kapi.Registry.EnableVersions(externalVersions...); err != nil { |
38 |
| - panic(err) |
39 |
| - } |
40 |
| - if err := enableVersions(externalVersions); err != nil { |
41 |
| - panic(err) |
42 |
| - } |
43 |
| - |
44 |
| - installApiGroup() |
45 |
| -} |
46 |
| - |
47 |
| -// TODO: enableVersions should be centralized rather than spread in each API |
48 |
| -// group. |
49 |
| -// We can combine registered.RegisterVersions, registered.EnableVersions and |
50 |
| -// registered.RegisterGroup once we have moved enableVersions there. |
51 |
| -func enableVersions(externalVersions []schema.GroupVersion) error { |
52 |
| - addVersionsToScheme(externalVersions...) |
53 |
| - preferredExternalVersion := externalVersions[0] |
54 |
| - |
55 |
| - groupMeta := apimachinery.GroupMeta{ |
56 |
| - GroupVersion: preferredExternalVersion, |
57 |
| - GroupVersions: externalVersions, |
58 |
| - RESTMapper: newRESTMapper(externalVersions), |
59 |
| - SelfLinker: runtime.SelfLinker(accessor), |
60 |
| - InterfacesFor: interfacesFor, |
61 |
| - } |
62 |
| - |
63 |
| - if err := kapi.Registry.RegisterGroup(groupMeta); err != nil { |
64 |
| - return err |
65 |
| - } |
66 |
| - return nil |
| 16 | + Install(kapi.GroupFactoryRegistry, kapi.Registry, kapi.Scheme) |
| 17 | + legacy.InstallLegacy(authorizationapi.GroupName, authorizationapi.AddToSchemeInCoreGroup, authorizationapiv1.AddToSchemeInCoreGroup, kapi.GroupFactoryRegistry, kapi.Registry, kapi.Scheme) |
67 | 18 | }
|
68 | 19 |
|
69 |
| -func addVersionsToScheme(externalVersions ...schema.GroupVersion) { |
70 |
| - // add the internal version to Scheme |
71 |
| - authorizationapi.AddToSchemeInCoreGroup(kapi.Scheme) |
72 |
| - // add the enabled external versions to Scheme |
73 |
| - for _, v := range externalVersions { |
74 |
| - if !kapi.Registry.IsEnabledVersion(v) { |
75 |
| - glog.Errorf("Version %s is not enabled, so it will not be added to the Scheme.", v) |
76 |
| - continue |
77 |
| - } |
78 |
| - switch v { |
79 |
| - case authorizationapiv1.LegacySchemeGroupVersion: |
80 |
| - authorizationapiv1.AddToSchemeInCoreGroup(kapi.Scheme) |
81 |
| - |
82 |
| - default: |
83 |
| - glog.Errorf("Version %s is not known, so it will not be added to the Scheme.", v) |
84 |
| - continue |
85 |
| - } |
86 |
| - } |
87 |
| -} |
88 |
| - |
89 |
| -func newRESTMapper(externalVersions []schema.GroupVersion) meta.RESTMapper { |
90 |
| - rootScoped := sets.NewString("ClusterRole", "ClusterRoleBinding", "ClusterPolicy", "ClusterPolicyBinding") |
91 |
| - ignoredKinds := sets.NewString() |
92 |
| - return meta.NewDefaultRESTMapperFromScheme(externalVersions, interfacesFor, ignoredKinds, rootScoped, kapi.Scheme) |
93 |
| -} |
94 |
| - |
95 |
| -func interfacesFor(version schema.GroupVersion) (*meta.VersionInterfaces, error) { |
96 |
| - switch version { |
97 |
| - case authorizationapiv1.LegacySchemeGroupVersion: |
98 |
| - return &meta.VersionInterfaces{ |
99 |
| - ObjectConvertor: kapi.Scheme, |
100 |
| - MetadataAccessor: accessor, |
101 |
| - }, nil |
102 |
| - |
103 |
| - default: |
104 |
| - g, _ := kapi.Registry.Group(authorizationapi.GroupName) |
105 |
| - return nil, fmt.Errorf("unsupported storage version: %s (valid: %v)", version, g.GroupVersions) |
| 20 | +// Install registers the API group and adds types to a scheme |
| 21 | +func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *registered.APIRegistrationManager, scheme *runtime.Scheme) { |
| 22 | + if err := announced.NewGroupMetaFactory( |
| 23 | + &announced.GroupMetaFactoryArgs{ |
| 24 | + GroupName: authorizationapi.GroupName, |
| 25 | + VersionPreferenceOrder: []string{authorizationapiv1.SchemeGroupVersion.Version}, |
| 26 | + AddInternalObjectsToScheme: authorizationapi.AddToScheme, |
| 27 | + RootScopedKinds: sets.NewString("ClusterRole", "ClusterRoleBinding", "ClusterPolicy", "ClusterPolicyBinding", "SubjectAccessReview", "ResourceAccessReview"), |
| 28 | + }, |
| 29 | + announced.VersionToSchemeFunc{ |
| 30 | + authorizationapiv1.SchemeGroupVersion.Version: authorizationapiv1.AddToScheme, |
| 31 | + }, |
| 32 | + ).Announce(groupFactoryRegistry).RegisterAndEnable(registry, scheme); err != nil { |
| 33 | + panic(err) |
106 | 34 | }
|
107 | 35 | }
|
0 commit comments