@@ -5,24 +5,26 @@ import (
5
5
"io"
6
6
"strings"
7
7
8
- "github.com/openshift/api/build"
9
- "github.com/openshift/origin/pkg/api/legacy"
10
- "github.com/openshift/origin/pkg/build/buildscheme"
8
+ authorizationv1 "k8s.io/api/authorization/v1"
11
9
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12
10
"k8s.io/apimachinery/pkg/runtime/schema"
11
+ utilruntime "k8s.io/apimachinery/pkg/util/runtime"
13
12
"k8s.io/apiserver/pkg/admission"
13
+ "k8s.io/client-go/kubernetes"
14
+ authorizationclient "k8s.io/client-go/kubernetes/typed/authorization/v1"
15
+ "k8s.io/client-go/rest"
14
16
kapihelper "k8s.io/kubernetes/pkg/apis/core/helper"
15
- "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
16
- authorizationclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/typed/authorization/internalversion"
17
- kubeadmission "k8s.io/kubernetes/pkg/kubeapiserver/admission"
18
17
rbacregistry "k8s.io/kubernetes/pkg/registry/rbac"
19
18
19
+ "github.com/openshift/api/build"
20
20
buildclient "github.com/openshift/client-go/build/clientset/versioned"
21
+ "github.com/openshift/origin/pkg/api/legacy"
21
22
"github.com/openshift/origin/pkg/authorization/util"
22
23
buildapi "github.com/openshift/origin/pkg/build/apis/build"
24
+ "github.com/openshift/origin/pkg/build/buildscheme"
23
25
oadmission "github.com/openshift/origin/pkg/cmd/server/admission"
24
26
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
25
- "k8s.io/kubernetes /pkg/apis/authorization "
27
+ "k8s.io/apiserver /pkg/admission/initializer "
26
28
)
27
29
28
30
func Register (plugins * admission.Plugins ) {
@@ -38,8 +40,8 @@ type buildByStrategy struct {
38
40
buildClient buildclient.Interface
39
41
}
40
42
41
- var _ = kubeadmission . WantsInternalKubeClientSet (& buildByStrategy {})
42
- var _ = oadmission .WantsOpenshiftInternalBuildClient (& buildByStrategy {})
43
+ var _ = initializer . WantsExternalKubeClientSet (& buildByStrategy {})
44
+ var _ = oadmission .WantsRESTClientConfig (& buildByStrategy {})
43
45
44
46
// NewBuildByStrategy returns an admission control for builds that checks
45
47
// on policy based on the build strategy type
@@ -84,12 +86,17 @@ func (a *buildByStrategy) Admit(attr admission.Attributes) error {
84
86
}
85
87
}
86
88
87
- func (a * buildByStrategy ) SetInternalKubeClientSet (c internalclientset .Interface ) {
88
- a .sarClient = c .Authorization ().SubjectAccessReviews ()
89
+ func (a * buildByStrategy ) SetExternalKubeClientSet (c kubernetes .Interface ) {
90
+ a .sarClient = c .AuthorizationV1 ().SubjectAccessReviews ()
89
91
}
90
92
91
- func (a * buildByStrategy ) SetOpenshiftInternalBuildClient (c buildclient.Interface ) {
92
- a .buildClient = c
93
+ func (a * buildByStrategy ) SetRESTClientConfig (restClientConfig rest.Config ) {
94
+ var err error
95
+ a .buildClient , err = buildclient .NewForConfig (& restClientConfig )
96
+ if err != nil {
97
+ utilruntime .HandleError (err )
98
+ return
99
+ }
93
100
}
94
101
95
102
func (a * buildByStrategy ) ValidateInitialization () error {
@@ -139,9 +146,9 @@ func (a *buildByStrategy) checkBuildAuthorization(build *buildapi.Build, attr ad
139
146
subresource = tokens [1 ]
140
147
}
141
148
142
- sar := util .AddUserToSAR (attr .GetUserInfo (), & authorization .SubjectAccessReview {
143
- Spec : authorization .SubjectAccessReviewSpec {
144
- ResourceAttributes : & authorization .ResourceAttributes {
149
+ sar := util .AddUserToSAR (attr .GetUserInfo (), & authorizationv1 .SubjectAccessReview {
150
+ Spec : authorizationv1 .SubjectAccessReviewSpec {
151
+ ResourceAttributes : & authorizationv1 .ResourceAttributes {
145
152
Namespace : attr .GetNamespace (),
146
153
Verb : "create" ,
147
154
Group : resource .Group ,
@@ -167,9 +174,9 @@ func (a *buildByStrategy) checkBuildConfigAuthorization(buildConfig *buildapi.Bu
167
174
subresource = tokens [1 ]
168
175
}
169
176
170
- sar := util .AddUserToSAR (attr .GetUserInfo (), & authorization .SubjectAccessReview {
171
- Spec : authorization .SubjectAccessReviewSpec {
172
- ResourceAttributes : & authorization .ResourceAttributes {
177
+ sar := util .AddUserToSAR (attr .GetUserInfo (), & authorizationv1 .SubjectAccessReview {
178
+ Spec : authorizationv1 .SubjectAccessReviewSpec {
179
+ ResourceAttributes : & authorizationv1 .ResourceAttributes {
173
180
Namespace : attr .GetNamespace (),
174
181
Verb : "create" ,
175
182
Group : resource .Group ,
@@ -213,7 +220,7 @@ func (a *buildByStrategy) checkBuildRequestAuthorization(req *buildapi.BuildRequ
213
220
}
214
221
}
215
222
216
- func (a * buildByStrategy ) checkAccess (strategy buildapi.BuildStrategy , subjectAccessReview * authorization .SubjectAccessReview , attr admission.Attributes ) error {
223
+ func (a * buildByStrategy ) checkAccess (strategy buildapi.BuildStrategy , subjectAccessReview * authorizationv1 .SubjectAccessReview , attr admission.Attributes ) error {
217
224
resp , err := a .sarClient .Create (subjectAccessReview )
218
225
if err != nil {
219
226
return admission .NewForbidden (attr , err )
0 commit comments