@@ -40,25 +40,31 @@ import (
40
40
41
41
// Note: This test must run on an OCP v4.17 or later cluster.
42
42
// The Validating Admission Policy feature gate is GA and enabled by default from OCP v4.17 (k8s v1.30)
43
+
44
+ var (
45
+ ns * corev1.Namespace
46
+ nsNoLabel * corev1.Namespace
47
+ rf * kueuev1beta1.ResourceFlavor
48
+ cq * kueuev1beta1.ClusterQueue
49
+ lq * kueuev1beta1.LocalQueue
50
+ rc * rayv1.RayCluster
51
+ aw * awv1beta2.AppWrapper
52
+ vapb * vapv1.ValidatingAdmissionPolicyBinding
53
+ vapbCopy * vapv1.ValidatingAdmissionPolicyBinding
54
+ awWithLQName = "aw-with-lq"
55
+ awNoLQName = "aw-no-lq"
56
+ rcWithLQName = "rc-with-lq"
57
+ rcNoLQName = "rc-no-lq"
58
+ )
59
+
60
+ const (
61
+ withLQ = true
62
+ noLQ = false
63
+ )
64
+
43
65
func TestValidatingAdmissionPolicy (t * testing.T ) {
44
66
test := With (t )
45
67
46
- var (
47
- ns * corev1.Namespace
48
- nsNoLabel * corev1.Namespace
49
- rf * kueuev1beta1.ResourceFlavor
50
- cq * kueuev1beta1.ClusterQueue
51
- lq * kueuev1beta1.LocalQueue
52
- rc * rayv1.RayCluster
53
- aw * awv1beta2.AppWrapper
54
- vapb * vapv1.ValidatingAdmissionPolicyBinding
55
- vapbCopy * vapv1.ValidatingAdmissionPolicyBinding
56
- awWithLQName = "aw-with-lq"
57
- awNoLQName = "aw-no-lq"
58
- rcWithLQName = "rc-with-lq"
59
- rcNoLQName = "rc-no-lq"
60
- )
61
-
62
68
// Register RayCluster types with the scheme
63
69
err := rayv1 .AddToScheme (scheme .Scheme )
64
70
test .Expect (err ).ToNot (HaveOccurred ())
@@ -128,45 +134,26 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
128
134
t .Run ("Default ValidatingAdmissionPolicyBinding" , func (t * testing.T ) {
129
135
t .Run ("RayCluster Tests" , func (t * testing.T ) {
130
136
t .Run ("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
131
- rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), ns .Name ).Queue (lq .Name ).Obj ()
132
- _ , err = test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
137
+ err = createRayCluster (test , ns .Name , withLQ )
133
138
test .Expect (err ).ToNot (HaveOccurred ())
134
139
defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
135
140
})
136
141
t .Run ("RayCluster should not be admitted without the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
137
- rc = testingraycluster .MakeCluster (uniqueSuffix (rcNoLQName ), ns .Name ).Obj ()
138
- _ , err = test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
142
+ err = createRayCluster (test , ns .Name , noLQ )
139
143
test .Expect (err ).ToNot (BeNil ())
140
144
defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
141
145
})
142
146
})
143
147
t .Run ("AppWrapper Tests" , func (t * testing.T ) {
144
148
t .Run ("AppWrapper should be admitted with the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
145
- awName := uniqueSuffix (awWithLQName )
146
- rcName := uniqueSuffix (rcNoLQName )
147
-
148
- aw = newAppWrapperWithRayCluster (awName , rcName , ns .Name )
149
- if aw .Labels == nil {
150
- aw .Labels = make (map [string ]string )
151
- }
152
- aw .Labels ["kueue.x-k8s.io/queue-name" ] = lq .Name
153
-
154
- // Create the AppWrapper with the 'kueue.x-k8s.io/queue-name' label set
155
- awMap , _ := runtime .DefaultUnstructuredConverter .ToUnstructured (aw )
156
- _ , err = test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Create (test .Ctx (), & unstructured.Unstructured {Object : awMap }, metav1.CreateOptions {})
149
+ err = createAppWrapper (test , ns .Name , withLQ )
157
150
test .Expect (err ).ToNot (HaveOccurred ())
158
- defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), awName , metav1.DeleteOptions {})
151
+ defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), aw . Name , metav1.DeleteOptions {})
159
152
})
160
153
t .Run ("AppWrapper should be admitted without the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
161
- awName := uniqueSuffix (awNoLQName )
162
- rcName := uniqueSuffix (rcNoLQName )
163
-
164
- // Create the AppWrapper without the 'kueue.x-k8s.io/queue-name' label set
165
- aw = newAppWrapperWithRayCluster (awName , rcName , ns .Name )
166
- awMap , _ := runtime .DefaultUnstructuredConverter .ToUnstructured (aw )
167
- _ , err = test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Create (test .Ctx (), & unstructured.Unstructured {Object : awMap }, metav1.CreateOptions {})
154
+ err = createAppWrapper (test , ns .Name , noLQ )
168
155
test .Expect (err ).ToNot (HaveOccurred ())
169
- defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), awName , metav1.DeleteOptions {})
156
+ defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), aw . Name , metav1.DeleteOptions {})
170
157
})
171
158
})
172
159
})
@@ -184,48 +171,29 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
184
171
defer revertVAPB (test , vapbCopy )
185
172
t .Run ("RayCluster Tests" , func (t * testing.T ) {
186
173
t .Run ("RayCluster should be admitted without the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
187
- rc = testingraycluster .MakeCluster (uniqueSuffix (rcNoLQName ), ns .Name ).Obj ()
188
174
// Eventually is used here to allow time for the ValidatingAdmissionPolicyBinding updates to be propagated.
189
175
test .Eventually (func () error {
190
- _ , err := test . Client (). Ray (). RayV1 (). RayClusters ( ns .Name ). Create ( test . Ctx (), rc , metav1. CreateOptions {} )
176
+ err = createRayCluster ( test , ns .Name , noLQ )
191
177
return err
192
178
}).WithTimeout (10 * time .Second ).WithPolling (500 * time .Millisecond ).Should (Succeed ())
193
179
defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
194
180
})
195
181
t .Run ("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
196
- rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), ns .Name ).Queue (lq .Name ).Obj ()
197
- _ , err = test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
182
+ err = createRayCluster (test , ns .Name , withLQ )
198
183
test .Expect (err ).ToNot (HaveOccurred ())
199
184
defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
200
185
})
201
186
})
202
187
t .Run ("AppWrapper Tests" , func (t * testing.T ) {
203
188
t .Run ("AppWrapper should be admitted with the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
204
- awName := uniqueSuffix (awWithLQName )
205
- rcName := uniqueSuffix (rcNoLQName )
206
-
207
- aw = newAppWrapperWithRayCluster (awName , rcName , ns .Name )
208
- if aw .Labels == nil {
209
- aw .Labels = make (map [string ]string )
210
- }
211
- aw .Labels ["kueue.x-k8s.io/queue-name" ] = lq .Name
212
-
213
- // Create the AppWrapper with the 'kueue.x-k8s.io/queue-name' label set
214
- awMap , _ := runtime .DefaultUnstructuredConverter .ToUnstructured (aw )
215
- _ , err = test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Create (test .Ctx (), & unstructured.Unstructured {Object : awMap }, metav1.CreateOptions {})
189
+ err = createAppWrapper (test , ns .Name , withLQ )
216
190
test .Expect (err ).ToNot (HaveOccurred ())
217
- defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), awName , metav1.DeleteOptions {})
191
+ defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), aw . Name , metav1.DeleteOptions {})
218
192
})
219
193
t .Run ("AppWrapper should be admitted without the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
220
- awName := uniqueSuffix (awNoLQName )
221
- rcName := uniqueSuffix (rcNoLQName )
222
-
223
- // Create the AppWrapper without the 'kueue.x-k8s.io/queue-name' label set
224
- aw = newAppWrapperWithRayCluster (awName , rcName , ns .Name )
225
- awMap , _ := runtime .DefaultUnstructuredConverter .ToUnstructured (aw )
226
- _ , err = test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Create (test .Ctx (), & unstructured.Unstructured {Object : awMap }, metav1.CreateOptions {})
194
+ err = createAppWrapper (test , ns .Name , noLQ )
227
195
test .Expect (err ).ToNot (HaveOccurred ())
228
- defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), awName , metav1.DeleteOptions {})
196
+ defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), aw . Name , metav1.DeleteOptions {})
229
197
})
230
198
})
231
199
})
@@ -257,88 +225,50 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
257
225
defer revertVAPB (test , vapbCopy )
258
226
t .Run ("RayCluster Tests" , func (t * testing.T ) {
259
227
t .Run ("RayCluster should not be admitted without the 'kueue.x-k8s.io/queue-name' label in a labeled namespace" , func (t * testing.T ) {
260
- rc = testingraycluster .MakeCluster (uniqueSuffix (rcNoLQName ), ns .Name ).Obj ()
261
228
test .Eventually (func () error {
262
- _ , err := test . Client (). Ray (). RayV1 (). RayClusters ( ns .Name ). Create ( test . Ctx (), rc , metav1. CreateOptions {} )
229
+ err = createRayCluster ( test , ns .Name , noLQ )
263
230
return err
264
231
}).WithTimeout (10 * time .Second ).WithPolling (500 * time .Millisecond ).ShouldNot (Succeed ())
265
232
defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
266
233
})
267
234
t .Run ("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label in a labeled namespace" , func (t * testing.T ) {
268
- rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), ns .Name ).Queue (lq .Name ).Obj ()
269
- _ , err = test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
235
+ err = createRayCluster (test , ns .Name , withLQ )
270
236
test .Expect (err ).ToNot (HaveOccurred ())
271
237
defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
272
238
})
273
239
t .Run ("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label in any other namespace" , func (t * testing.T ) {
274
- rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), nsNoLabel .Name ).Queue (lq .Name ).Obj ()
275
- _ , err = test .Client ().Ray ().RayV1 ().RayClusters (nsNoLabel .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
240
+ err = createRayCluster (test , nsNoLabel .Name , withLQ )
276
241
test .Expect (err ).ToNot (HaveOccurred ())
277
242
defer test .Client ().Ray ().RayV1 ().RayClusters (nsNoLabel .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
278
243
})
279
244
t .Run ("RayCluster should be admitted without the 'kueue.x-k8s.io/queue-name' label in any other namespace" , func (t * testing.T ) {
280
- rc = testingraycluster .MakeCluster (uniqueSuffix (rcNoLQName ), nsNoLabel .Name ).Obj ()
281
245
test .Eventually (func () error {
282
- _ , err = test . Client (). Ray (). RayV1 (). RayClusters ( nsNoLabel .Name ). Create ( test . Ctx (), rc , metav1. CreateOptions {} )
246
+ err = createRayCluster ( test , nsNoLabel .Name , noLQ )
283
247
return err
284
248
}).WithTimeout (10 * time .Second ).WithPolling (500 * time .Millisecond ).Should (Succeed ())
285
249
defer test .Client ().Ray ().RayV1 ().RayClusters (nsNoLabel .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
286
250
})
287
251
})
288
252
t .Run ("AppWrapper Tests" , func (t * testing.T ) {
289
253
t .Run ("AppWrapper should be admitted without the 'kueue.x-k8s.io/queue-name' label in a labeled namespace" , func (t * testing.T ) {
290
- awName := uniqueSuffix (awNoLQName )
291
- rcName := uniqueSuffix (rcNoLQName )
292
-
293
- // Create the AppWrapper without the 'kueue.x-k8s.io/queue-name' label set
294
- aw = newAppWrapperWithRayCluster (awName , rcName , ns .Name )
295
- awMap , _ := runtime .DefaultUnstructuredConverter .ToUnstructured (aw )
296
- _ , err = test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Create (test .Ctx (), & unstructured.Unstructured {Object : awMap }, metav1.CreateOptions {})
254
+ err = createAppWrapper (test , ns .Name , noLQ )
297
255
test .Expect (err ).ToNot (HaveOccurred ())
298
- defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), awName , metav1.DeleteOptions {})
256
+ defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), aw . Name , metav1.DeleteOptions {})
299
257
})
300
258
t .Run ("AppWrapper should be admitted with the 'kueue.x-k8s.io/queue-name' label in a labeled namespace" , func (t * testing.T ) {
301
- awName := uniqueSuffix (awWithLQName )
302
- rcName := uniqueSuffix (rcNoLQName )
303
-
304
- aw = newAppWrapperWithRayCluster (awName , rcName , ns .Name )
305
- if aw .Labels == nil {
306
- aw .Labels = make (map [string ]string )
307
- }
308
- aw .Labels ["kueue.x-k8s.io/queue-name" ] = lq .Name
309
-
310
- // Create the AppWrapper with the 'kueue.x-k8s.io/queue-name' label set
311
- awMap , _ := runtime .DefaultUnstructuredConverter .ToUnstructured (aw )
312
- _ , err = test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Create (test .Ctx (), & unstructured.Unstructured {Object : awMap }, metav1.CreateOptions {})
259
+ err = createAppWrapper (test , ns .Name , withLQ )
313
260
test .Expect (err ).ToNot (HaveOccurred ())
314
- defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), awName , metav1.DeleteOptions {})
261
+ defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (ns .Name ).Delete (test .Ctx (), aw . Name , metav1.DeleteOptions {})
315
262
})
316
263
t .Run ("AppWrapper should be admitted with the 'kueue.x-k8s.io/queue-name' label in any other namespace" , func (t * testing.T ) {
317
- awName := uniqueSuffix (awWithLQName )
318
- rcName := uniqueSuffix (rcNoLQName )
319
-
320
- aw = newAppWrapperWithRayCluster (awName , rcName , nsNoLabel .Name )
321
- if aw .Labels == nil {
322
- aw .Labels = make (map [string ]string )
323
- }
324
- aw .Labels ["kueue.x-k8s.io/queue-name" ] = lq .Name
325
-
326
- // Create the AppWrapper with the 'kueue.x-k8s.io/queue-name' label set
327
- awMap , _ := runtime .DefaultUnstructuredConverter .ToUnstructured (aw )
328
- _ , err = test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (nsNoLabel .Name ).Create (test .Ctx (), & unstructured.Unstructured {Object : awMap }, metav1.CreateOptions {})
264
+ err = createAppWrapper (test , nsNoLabel .Name , withLQ )
329
265
test .Expect (err ).ToNot (HaveOccurred ())
330
- defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (nsNoLabel .Name ).Delete (test .Ctx (), awName , metav1.DeleteOptions {})
266
+ defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (nsNoLabel .Name ).Delete (test .Ctx (), aw . Name , metav1.DeleteOptions {})
331
267
})
332
268
t .Run ("AppWrapper should be admitted without the 'kueue.x-k8s.io/queue-name' label in any other namespace" , func (t * testing.T ) {
333
- awName := uniqueSuffix (awNoLQName )
334
- rcName := uniqueSuffix (rcNoLQName )
335
-
336
- // Create the AppWrapper without the 'kueue.x-k8s.io/queue-name' label set
337
- aw = newAppWrapperWithRayCluster (awName , rcName , nsNoLabel .Name )
338
- awMap , _ := runtime .DefaultUnstructuredConverter .ToUnstructured (aw )
339
- _ , err = test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (nsNoLabel .Name ).Create (test .Ctx (), & unstructured.Unstructured {Object : awMap }, metav1.CreateOptions {})
269
+ err = createAppWrapper (test , nsNoLabel .Name , noLQ )
340
270
test .Expect (err ).ToNot (HaveOccurred ())
341
- defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (nsNoLabel .Name ).Delete (test .Ctx (), awName , metav1.DeleteOptions {})
271
+ defer test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (nsNoLabel .Name ).Delete (test .Ctx (), aw . Name , metav1.DeleteOptions {})
342
272
})
343
273
})
344
274
})
@@ -359,3 +289,29 @@ func revertVAPB(test Test, vapbCopy *vapv1.ValidatingAdmissionPolicyBinding) {
359
289
_ , err := test .Client ().Core ().AdmissionregistrationV1 ().ValidatingAdmissionPolicyBindings ().Patch (test .Ctx (), vapbCopy .Name , types .StrategicMergePatchType , patchBytes , metav1.PatchOptions {})
360
290
test .Expect (err ).ToNot (HaveOccurred ())
361
291
}
292
+
293
+ func createRayCluster (test Test , namespaceName string , localQueue bool ) error {
294
+ if localQueue {
295
+ rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), namespaceName ).Queue (lq .Name ).Obj ()
296
+ } else {
297
+ rc = testingraycluster .MakeCluster (uniqueSuffix (rcNoLQName ), namespaceName ).Obj ()
298
+ }
299
+ _ , err := test .Client ().Ray ().RayV1 ().RayClusters (namespaceName ).Create (test .Ctx (), rc , metav1.CreateOptions {})
300
+ return err
301
+ }
302
+
303
+ func createAppWrapper (test Test , namespaceName string , localQueue bool ) error {
304
+ if localQueue {
305
+ aw = newAppWrapperWithRayCluster (uniqueSuffix (awWithLQName ), uniqueSuffix (rcNoLQName ), namespaceName )
306
+ if aw .Labels == nil {
307
+ aw .Labels = make (map [string ]string )
308
+ }
309
+ aw .Labels ["kueue.x-k8s.io/queue-name" ] = lq .Name
310
+ } else {
311
+ // Make an AppWrapper without the 'kueue.x-k8s.io/queue-name' label set
312
+ aw = newAppWrapperWithRayCluster (uniqueSuffix (awNoLQName ), uniqueSuffix (rcNoLQName ), namespaceName )
313
+ }
314
+ awMap , _ := runtime .DefaultUnstructuredConverter .ToUnstructured (aw )
315
+ _ , err := test .Client ().Dynamic ().Resource (awv1beta2 .GroupVersion .WithResource ("appwrappers" )).Namespace (namespaceName ).Create (test .Ctx (), & unstructured.Unstructured {Object : awMap }, metav1.CreateOptions {})
316
+ return err
317
+ }
0 commit comments