@@ -16,16 +16,19 @@ import (
16
16
quotautil "github.com/openshift/origin/pkg/quota/util"
17
17
imagesutil "github.com/openshift/origin/test/extended/images"
18
18
exutil "github.com/openshift/origin/test/extended/util"
19
- testutil "github.com/openshift/origin/test/util"
20
19
)
21
20
22
- const limitRangeName = "limits"
21
+ const (
22
+ limitRangeName = "limits"
23
+ imageSize = 100
24
+ )
23
25
24
- var _ = g .Describe ("[Feature:ImageQuota][registry][Serial][Suite:openshift/registry/serial][local] Image limit range" , func () {
26
+ var _ = g .Describe ("[Feature:ImageQuota][registry][Serial][Suite:openshift/registry/serial] Image limit range" , func () {
25
27
defer g .GinkgoRecover ()
28
+
26
29
var oc = exutil .NewCLI ("limitrange-admission" , exutil .KubeConfigPath ())
27
30
28
- g .JustBeforeEach (func () {
31
+ g .BeforeEach (func () {
29
32
g .By ("waiting for default service account" )
30
33
err := exutil .WaitForServiceAccount (oc .KubeClient ().Core ().ServiceAccounts (oc .Namespace ()), "default" )
31
34
o .Expect (err ).NotTo (o .HaveOccurred ())
@@ -34,102 +37,77 @@ var _ = g.Describe("[Feature:ImageQuota][registry][Serial][Suite:openshift/regis
34
37
o .Expect (err ).NotTo (o .HaveOccurred ())
35
38
})
36
39
37
- // needs to be run at the of of each It; cannot be run in AfterEach which is run after the project
38
- // is destroyed
39
- tearDown := func (oc * exutil.CLI ) {
40
- g .By (fmt .Sprintf ("Deleting limit range %s" , limitRangeName ))
41
- oc .AdminKubeClient ().Core ().LimitRanges (oc .Namespace ()).Delete (limitRangeName , nil )
42
-
43
- deleteTestImagesAndStreams (oc )
44
- }
45
-
46
- g .It (fmt .Sprintf ("[Skipped] should deny a push of built image exceeding %s limit" , imageapi .LimitTypeImage ), func () {
47
- g .Skip ("FIXME: fill image metadata for schema1 in the registry" )
48
-
49
- defer tearDown (oc )
50
-
51
- dClient , err := testutil .NewDockerClient ()
52
- o .Expect (err ).NotTo (o .HaveOccurred ())
53
-
54
- _ , err = createLimitRangeOfType (oc , imageapi .LimitTypeImage , kapi.ResourceList {
40
+ g .It (fmt .Sprintf ("should deny a push of built image exceeding %s limit" , imageapi .LimitTypeImage ), func () {
41
+ _ , err := createLimitRangeOfType (oc , imageapi .LimitTypeImage , kapi.ResourceList {
55
42
kapi .ResourceStorage : resource .MustParse ("10Ki" ),
56
43
})
57
44
o .Expect (err ).NotTo (o .HaveOccurred ())
58
45
59
46
g .By (fmt .Sprintf ("trying to push an image exceeding size limit with just 1 layer" ))
60
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "sized" , "middle" , 16000 , 1 , false )
47
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "sized" , "middle" , 16000 , 1 , false )
61
48
o .Expect (err ).NotTo (o .HaveOccurred ())
62
49
63
50
g .By (fmt .Sprintf ("trying to push an image exceeding size limit in total" ))
64
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "sized" , "middle" , 16000 , 5 , false )
51
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "sized" , "middle" , 16000 , 5 , false )
65
52
o .Expect (err ).NotTo (o .HaveOccurred ())
66
53
67
54
g .By (fmt .Sprintf ("trying to push an image with one big layer below size limit" ))
68
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "sized" , "small" , 8000 , 1 , true )
55
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "sized" , "small" , 8000 , 1 , true )
69
56
o .Expect (err ).NotTo (o .HaveOccurred ())
70
57
71
58
g .By (fmt .Sprintf ("trying to push an image below size limit" ))
72
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "sized" , "small" , 8000 , 2 , true )
59
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "sized" , "small" , 8000 , 2 , true )
73
60
o .Expect (err ).NotTo (o .HaveOccurred ())
74
61
})
75
62
76
63
g .It (fmt .Sprintf ("should deny a push of built image exceeding limit on %s resource" , imageapi .ResourceImageStreamImages ), func () {
77
-
78
- defer tearDown (oc )
79
-
80
64
limits := kapi.ResourceList {
81
65
imageapi .ResourceImageStreamTags : resource .MustParse ("0" ),
82
66
imageapi .ResourceImageStreamImages : resource .MustParse ("0" ),
83
67
}
84
68
_ , err := createLimitRangeOfType (oc , imageapi .LimitTypeImageStream , limits )
85
69
o .Expect (err ).NotTo (o .HaveOccurred ())
86
70
87
- dClient , err := testutil .NewDockerClient ()
88
- o .Expect (err ).NotTo (o .HaveOccurred ())
89
-
90
71
g .By (fmt .Sprintf ("trying to push image exceeding limits %v" , limits ))
91
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "sized" , "refused" , imageSize , 1 , false )
72
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "sized" , "refused" , imageSize , 1 , false )
92
73
o .Expect (err ).NotTo (o .HaveOccurred ())
93
74
94
75
limits , err = bumpLimit (oc , imageapi .ResourceImageStreamImages , "1" )
95
76
o .Expect (err ).NotTo (o .HaveOccurred ())
96
77
97
78
g .By (fmt .Sprintf ("trying to push image below limits %v" , limits ))
98
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "sized" , "first" , imageSize , 2 , true )
79
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "sized" , "first" , imageSize , 2 , true )
99
80
o .Expect (err ).NotTo (o .HaveOccurred ())
100
81
101
82
g .By (fmt .Sprintf ("trying to push image exceeding limits %v" , limits ))
102
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "sized" , "second" , imageSize , 2 , false )
83
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "sized" , "second" , imageSize , 2 , false )
103
84
o .Expect (err ).NotTo (o .HaveOccurred ())
104
85
105
86
g .By (fmt .Sprintf ("trying to push image below limits %v to another image stream" , limits ))
106
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "another" , "second" , imageSize , 1 , true )
87
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "another" , "second" , imageSize , 1 , true )
107
88
o .Expect (err ).NotTo (o .HaveOccurred ())
108
89
109
90
limits , err = bumpLimit (oc , imageapi .ResourceImageStreamImages , "2" )
110
91
o .Expect (err ).NotTo (o .HaveOccurred ())
111
92
112
93
g .By (fmt .Sprintf ("trying to push image below limits %v" , limits ))
113
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "another" , "third" , imageSize , 1 , true )
94
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "another" , "third" , imageSize , 1 , true )
114
95
o .Expect (err ).NotTo (o .HaveOccurred ())
115
96
116
97
g .By (fmt .Sprintf ("trying to push image exceeding limits %v" , limits ))
117
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "another" , "fourth" , imageSize , 1 , false )
98
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "another" , "fourth" , imageSize , 1 , false )
118
99
o .Expect (err ).NotTo (o .HaveOccurred ())
119
100
120
101
g .By (`removing tag "second" from "another" image stream` )
121
102
err = oc .ImageClient ().Image ().ImageStreamTags (oc .Namespace ()).Delete ("another:second" , nil )
122
103
o .Expect (err ).NotTo (o .HaveOccurred ())
123
104
124
105
g .By (fmt .Sprintf ("trying to push image below limits %v" , limits ))
125
- err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , dClient , oc .Namespace (), "another" , "replenish" , imageSize , 1 , true )
106
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc .Namespace (), "another" , "replenish" , imageSize , 1 , true )
126
107
o .Expect (err ).NotTo (o .HaveOccurred ())
127
108
})
128
109
129
110
g .It (fmt .Sprintf ("should deny a docker image reference exceeding limit on %s resource" , imageapi .ResourceImageStreamTags ), func () {
130
-
131
- defer tearDown (oc )
132
-
133
111
tag2Image , err := buildAndPushTestImagesTo (oc , "src" , "tag" , 2 )
134
112
o .Expect (err ).NotTo (o .HaveOccurred ())
135
113
@@ -187,15 +165,12 @@ var _ = g.Describe("[Feature:ImageQuota][registry][Serial][Suite:openshift/regis
187
165
})
188
166
189
167
g .It (fmt .Sprintf ("should deny an import of a repository exceeding limit on %s resource" , imageapi .ResourceImageStreamTags ), func () {
190
-
191
168
maxBulkImport , err := getMaxImagesBulkImportedPerRepository ()
192
169
if err != nil {
193
170
g .Skip (err .Error ())
194
171
return
195
172
}
196
173
197
- defer tearDown (oc )
198
-
199
174
s1tag2Image , err := buildAndPushTestImagesTo (oc , "src1st" , "tag" , maxBulkImport + 1 )
200
175
s2tag2Image , err := buildAndPushTestImagesTo (oc , "src2nd" , "t" , 2 )
201
176
o .Expect (err ).NotTo (o .HaveOccurred ())
@@ -234,25 +209,18 @@ var _ = g.Describe("[Feature:ImageQuota][registry][Serial][Suite:openshift/regis
234
209
// buildAndPushTestImagesTo builds a given number of test images. The images are pushed to a new image stream
235
210
// of given name under <tagPrefix><X> where X is a number of image starting from 1.
236
211
func buildAndPushTestImagesTo (oc * exutil.CLI , isName string , tagPrefix string , numberOfImages int ) (tag2Image map [string ]imageapi.Image , err error ) {
237
- dClient , err := testutil .NewDockerClient ()
238
- if err != nil {
239
- return
240
- }
241
212
tag2Image = make (map [string ]imageapi.Image )
242
213
243
214
for i := 1 ; i <= numberOfImages ; i ++ {
244
215
tag := fmt .Sprintf ("%s%d" , tagPrefix , i )
245
- dgst , _ , err : = imagesutil .BuildAndPushImageOfSizeWithDocker (oc , dClient , isName , tag , imageSize , 2 , g . GinkgoWriter , true , true )
216
+ err = imagesutil .BuildAndPushImageOfSizeWithBuilder (oc , nil , oc . Namespace (), isName , tag , imageSize , 2 , true )
246
217
if err != nil {
247
218
return nil , err
248
219
}
249
220
ist , err := oc .ImageClient ().Image ().ImageStreamTags (oc .Namespace ()).Get (isName + ":" + tag , metav1.GetOptions {})
250
221
if err != nil {
251
222
return nil , err
252
223
}
253
- if dgst != ist .Image .Name {
254
- return nil , fmt .Errorf ("digest of built image does not match stored: %s != %s" , dgst , ist .Image .Name )
255
- }
256
224
tag2Image [tag ] = ist .Image
257
225
}
258
226
@@ -316,7 +284,7 @@ func bumpLimit(oc *exutil.CLI, resourceName kapi.ResourceName, limit string) (ka
316
284
func getMaxImagesBulkImportedPerRepository () (int , error ) {
317
285
max := os .Getenv ("MAX_IMAGES_BULK_IMPORTED_PER_REPOSITORY" )
318
286
if len (max ) == 0 {
319
- return 0 , fmt .Errorf ("MAX_IMAGES_BULK_IMAGES_IMPORTED_PER_REPOSITORY is not set" )
287
+ return 0 , fmt .Errorf ("MAX_IMAGES_BULK_IMPORTED_PER_REPOSITORY is not set" )
320
288
}
321
289
return strconv .Atoi (max )
322
290
}
0 commit comments