forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.go
139 lines (120 loc) · 5.56 KB
/
convert.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package util
import (
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/kubernetes/pkg/apis/rbac"
authorizationapi "github.com/openshift/origin/pkg/authorization/apis/authorization"
"github.com/openshift/origin/pkg/authorization/apis/authorization/rbacconversion"
)
// ClusterRoleToRBAC turns an OpenShift ClusterRole into a Kubernetes RBAC
// ClusterRole, the returned object is safe to mutate
func ClusterRoleToRBAC(obj *authorizationapi.ClusterRole) (*rbac.ClusterRole, error) {
convertedObj := &rbac.ClusterRole{}
if err := rbacconversion.Convert_authorization_ClusterRole_To_rbac_ClusterRole(obj, convertedObj, nil); err != nil {
return nil, err
}
// do a deep copy here since conversion does not guarantee a new object.
deepcopiedObj := &rbac.ClusterRole{}
if err := rbac.DeepCopy_rbac_ClusterRole(convertedObj, deepcopiedObj, cloner); err != nil {
return nil, err
}
return deepcopiedObj, nil
}
// ClusterRoleBindingToRBAC turns an OpenShift ClusterRoleBinding into a Kubernetes
// RBAC ClusterRoleBinding, the returned object is safe to mutate
func ClusterRoleBindingToRBAC(obj *authorizationapi.ClusterRoleBinding) (*rbac.ClusterRoleBinding, error) {
convertedObj := &rbac.ClusterRoleBinding{}
if err := rbacconversion.Convert_authorization_ClusterRoleBinding_To_rbac_ClusterRoleBinding(obj, convertedObj, nil); err != nil {
return nil, err
}
// do a deep copy here since conversion does not guarantee a new object.
deepcopiedObj := &rbac.ClusterRoleBinding{}
if err := rbac.DeepCopy_rbac_ClusterRoleBinding(convertedObj, deepcopiedObj, cloner); err != nil {
return nil, err
}
return deepcopiedObj, nil
}
// RoleToRBAC turns an OpenShift Role into a Kubernetes RBAC Role,
// the returned object is safe to mutate
func RoleToRBAC(obj *authorizationapi.Role) (*rbac.Role, error) {
convertedObj := &rbac.Role{}
if err := rbacconversion.Convert_authorization_Role_To_rbac_Role(obj, convertedObj, nil); err != nil {
return nil, err
}
// do a deep copy here since conversion does not guarantee a new object.
deepcopiedObj := &rbac.Role{}
if err := rbac.DeepCopy_rbac_Role(convertedObj, deepcopiedObj, cloner); err != nil {
return nil, err
}
return deepcopiedObj, nil
}
// RoleBindingToRBAC turns an OpenShift RoleBinding into a Kubernetes RBAC
// Rolebinding, the returned object is safe to mutate
func RoleBindingToRBAC(obj *authorizationapi.RoleBinding) (*rbac.RoleBinding, error) {
convertedObj := &rbac.RoleBinding{}
if err := rbacconversion.Convert_authorization_RoleBinding_To_rbac_RoleBinding(obj, convertedObj, nil); err != nil {
return nil, err
}
// do a deep copy here since conversion does not guarantee a new object.
deepcopiedObj := &rbac.RoleBinding{}
if err := rbac.DeepCopy_rbac_RoleBinding(convertedObj, deepcopiedObj, cloner); err != nil {
return nil, err
}
return deepcopiedObj, nil
}
// ClusterRoleFromRBAC turns a Kubernetes RBAC ClusterRole into an Openshift
// ClusterRole, the returned object is safe to mutate
func ClusterRoleFromRBAC(obj *rbac.ClusterRole) (*authorizationapi.ClusterRole, error) {
convertedObj := &authorizationapi.ClusterRole{}
if err := rbacconversion.Convert_rbac_ClusterRole_To_authorization_ClusterRole(obj, convertedObj, nil); err != nil {
return nil, err
}
// do a deep copy here since conversion does not guarantee a new object.
deepcopiedObj := &authorizationapi.ClusterRole{}
if err := authorizationapi.DeepCopy_authorization_ClusterRole(convertedObj, deepcopiedObj, cloner); err != nil {
return nil, err
}
return deepcopiedObj, nil
}
// ClusterRoleBindingFromRBAC turns a Kuberenets RBAC ClusterRoleBinding into
// an Openshift ClusterRoleBinding, the returned object is safe to mutate
func ClusterRoleBindingFromRBAC(obj *rbac.ClusterRoleBinding) (*authorizationapi.ClusterRoleBinding, error) {
convertedObj := &authorizationapi.ClusterRoleBinding{}
if err := rbacconversion.Convert_rbac_ClusterRoleBinding_To_authorization_ClusterRoleBinding(obj, convertedObj, nil); err != nil {
return nil, err
}
// do a deep copy here since conversion does not guarantee a new object.
deepcopiedObj := &authorizationapi.ClusterRoleBinding{}
if err := authorizationapi.DeepCopy_authorization_ClusterRoleBinding(convertedObj, deepcopiedObj, cloner); err != nil {
return nil, err
}
return deepcopiedObj, nil
}
// RoleFromRBAC turns a Kubernetes RBAC Role into an OpenShift Role,
// the returned object is safe to mutate
func RoleFromRBAC(obj *rbac.Role) (*authorizationapi.Role, error) {
convertedObj := &authorizationapi.Role{}
if err := rbacconversion.Convert_rbac_Role_To_authorization_Role(obj, convertedObj, nil); err != nil {
return nil, err
}
// do a deep copy here since conversion does not guarantee a new object.
deepcopiedObj := &authorizationapi.Role{}
if err := authorizationapi.DeepCopy_authorization_Role(convertedObj, deepcopiedObj, cloner); err != nil {
return nil, err
}
return deepcopiedObj, nil
}
// RoleBindingFromRBAC turns a Kubernetes RBAC RoleBinding into an OpenShift
// Rolebinding, the returned object is safe to mutate
func RoleBindingFromRBAC(obj *rbac.RoleBinding) (*authorizationapi.RoleBinding, error) {
convertedObj := &authorizationapi.RoleBinding{}
if err := rbacconversion.Convert_rbac_RoleBinding_To_authorization_RoleBinding(obj, convertedObj, nil); err != nil {
return nil, err
}
// do a deep copy here since conversion does not guarantee a new object.
deepcopiedObj := &authorizationapi.RoleBinding{}
if err := authorizationapi.DeepCopy_authorization_RoleBinding(convertedObj, deepcopiedObj, cloner); err != nil {
return nil, err
}
return deepcopiedObj, nil
}
var cloner = conversion.NewCloner()