@@ -11,13 +11,17 @@ import (
11
11
"k8s.io/apiserver/pkg/admission"
12
12
"k8s.io/apiserver/pkg/authentication/user"
13
13
clientgotesting "k8s.io/client-go/testing"
14
+ kapi "k8s.io/kubernetes/pkg/api"
14
15
"k8s.io/kubernetes/pkg/apis/authorization"
15
16
fakekubeclient "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
16
17
kubeadmission "k8s.io/kubernetes/pkg/kubeapiserver/admission"
17
18
18
19
buildapi "github.com/openshift/origin/pkg/build/apis/build"
19
- fakebuildclient "github.com/openshift/origin/pkg/build/generated/internalclientset/fake"
20
+ buildapiv1 "github.com/openshift/origin/pkg/build/apis/build/v1"
21
+ fakebuildclient "github.com/openshift/origin/pkg/build/generated/clientset/fake"
20
22
oadmission "github.com/openshift/origin/pkg/cmd/server/admission"
23
+
24
+ _ "github.com/openshift/origin/pkg/build/apis/build/install"
21
25
)
22
26
23
27
func TestBuildAdmission (t * testing.T ) {
@@ -48,7 +52,7 @@ func TestBuildAdmission(t *testing.T) {
48
52
{
49
53
name : "allowed source build clone" ,
50
54
object : testBuildRequest ("test-build" ),
51
- responseObject : testBuild (buildapi.BuildStrategy {SourceStrategy : & buildapi.SourceBuildStrategy {}}),
55
+ responseObject : asV1Build ( testBuild (buildapi.BuildStrategy {SourceStrategy : & buildapi.SourceBuildStrategy {}}) ),
52
56
kind : buildapi .Kind ("Build" ),
53
57
resource : buildapi .Resource ("builds" ),
54
58
subResource : "clone" ,
@@ -70,7 +74,7 @@ func TestBuildAdmission(t *testing.T) {
70
74
{
71
75
name : "denied docker build clone" ,
72
76
object : testBuildRequest ("buildname" ),
73
- responseObject : testBuild (buildapi.BuildStrategy {DockerStrategy : & buildapi.DockerBuildStrategy {}}),
77
+ responseObject : asV1Build ( testBuild (buildapi.BuildStrategy {DockerStrategy : & buildapi.DockerBuildStrategy {}}) ),
74
78
kind : buildapi .Kind ("Build" ),
75
79
resource : buildapi .Resource ("builds" ),
76
80
subResource : "clone" ,
@@ -101,7 +105,7 @@ func TestBuildAdmission(t *testing.T) {
101
105
},
102
106
{
103
107
name : "allowed build config instantiate" ,
104
- responseObject : testBuildConfig (buildapi.BuildStrategy {DockerStrategy : & buildapi.DockerBuildStrategy {}}),
108
+ responseObject : asV1BuildConfig ( testBuildConfig (buildapi.BuildStrategy {DockerStrategy : & buildapi.DockerBuildStrategy {}}) ),
105
109
object : testBuildRequest ("test-buildconfig" ),
106
110
kind : buildapi .Kind ("Build" ),
107
111
resource : buildapi .Resource ("buildconfigs" ),
@@ -123,7 +127,7 @@ func TestBuildAdmission(t *testing.T) {
123
127
},
124
128
{
125
129
name : "forbidden build config instantiate" ,
126
- responseObject : testBuildConfig (buildapi.BuildStrategy {CustomStrategy : & buildapi.CustomBuildStrategy {}}),
130
+ responseObject : asV1BuildConfig ( testBuildConfig (buildapi.BuildStrategy {CustomStrategy : & buildapi.CustomBuildStrategy {}}) ),
127
131
object : testBuildRequest ("buildname" ),
128
132
kind : buildapi .Kind ("Build" ),
129
133
resource : buildapi .Resource ("buildconfigs" ),
@@ -164,7 +168,7 @@ func TestBuildAdmission(t *testing.T) {
164
168
{
165
169
name : "allowed jenkins pipeline build clone" ,
166
170
object : testBuildRequest ("test-build" ),
167
- responseObject : testBuild (buildapi.BuildStrategy {JenkinsPipelineStrategy : & buildapi.JenkinsPipelineBuildStrategy {}}),
171
+ responseObject : asV1Build ( testBuild (buildapi.BuildStrategy {JenkinsPipelineStrategy : & buildapi.JenkinsPipelineBuildStrategy {}}) ),
168
172
kind : buildapi .Kind ("Build" ),
169
173
resource : buildapi .Resource ("builds" ),
170
174
subResource : "clone" ,
@@ -250,6 +254,15 @@ func testBuild(strategy buildapi.BuildStrategy) *buildapi.Build {
250
254
}
251
255
}
252
256
257
+ func asV1Build (in * buildapi.Build ) * buildapiv1.Build {
258
+ out := & buildapiv1.Build {}
259
+ err := kapi .Scheme .Convert (in , out , nil )
260
+ if err != nil {
261
+ panic (err )
262
+ }
263
+ return out
264
+ }
265
+
253
266
func testBuildConfig (strategy buildapi.BuildStrategy ) * buildapi.BuildConfig {
254
267
return & buildapi.BuildConfig {
255
268
ObjectMeta : metav1.ObjectMeta {
@@ -264,6 +277,15 @@ func testBuildConfig(strategy buildapi.BuildStrategy) *buildapi.BuildConfig {
264
277
}
265
278
}
266
279
280
+ func asV1BuildConfig (in * buildapi.BuildConfig ) * buildapiv1.BuildConfig {
281
+ out := & buildapiv1.BuildConfig {}
282
+ err := kapi .Scheme .Convert (in , out , nil )
283
+ if err != nil {
284
+ panic (err )
285
+ }
286
+ return out
287
+ }
288
+
267
289
func reviewResponse (allowed bool , msg string ) * authorization.SubjectAccessReview {
268
290
return & authorization.SubjectAccessReview {
269
291
Status : authorization.SubjectAccessReviewStatus {
0 commit comments