@@ -168,17 +168,19 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
168
168
vapb .Spec .PolicyName = "none"
169
169
_ , err = test .Client ().Core ().AdmissionregistrationV1 ().ValidatingAdmissionPolicyBindings ().Update (test .Ctx (), vapb , metav1.UpdateOptions {})
170
170
test .Expect (err ).ToNot (HaveOccurred ())
171
- time .Sleep (2 * time .Second ) // Wait for the ValidatingAdmissionPolicyBinding to be updated
172
171
defer revertVAPB (test , vapbCopy )
173
172
174
- t .Run ("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
175
- rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), ns .Name ).Queue (lq .Name ).Obj ()
176
- _ , err = test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
177
- test .Expect (err ).ToNot (HaveOccurred ())
178
- defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
179
- })
180
173
t .Run ("RayCluster should be admitted without the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
181
174
rc = testingraycluster .MakeCluster (uniqueSuffix (rcNoLQName ), ns .Name ).Obj ()
175
+ // Eventually is used here to allow time for the ValidatingAdmissionPolicyBinding updates to be propagated.
176
+ test .Eventually (func () error {
177
+ _ , err := test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
178
+ return err
179
+ }).WithTimeout (5 * time .Second ).WithPolling (500 * time .Millisecond ).Should (Succeed ())
180
+ defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
181
+ })
182
+ t .Run ("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
183
+ rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), ns .Name ).Queue (lq .Name ).Obj ()
182
184
_ , err = test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
183
185
test .Expect (err ).ToNot (HaveOccurred ())
184
186
defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
@@ -212,30 +214,35 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
212
214
}
213
215
ns .Labels ["kueue-managed" ] = "true"
214
216
_ , err = test .Client ().Core ().CoreV1 ().Namespaces ().Update (test .Ctx (), ns , metav1.UpdateOptions {})
217
+ test .Eventually (func () bool {
218
+ ns , _ = test .Client ().Core ().CoreV1 ().Namespaces ().Get (test .Ctx (), ns .Name , metav1.GetOptions {})
219
+ return ns .Labels ["kueue-managed" ] == "true"
220
+ }).WithTimeout (5 * time .Second ).WithPolling (500 * time .Millisecond ).Should (BeTrue ())
215
221
test .Expect (err ).ToNot (HaveOccurred ())
216
222
217
223
// Apply the ValidatingAdmissionPolicyBinding targetting namespaces with the label 'kueue-managed'
218
- vapb , err : = test .Client ().Core ().AdmissionregistrationV1 ().ValidatingAdmissionPolicyBindings ().Get (test .Ctx (), vapb .Name , metav1.GetOptions {})
224
+ vapb , err = test .Client ().Core ().AdmissionregistrationV1 ().ValidatingAdmissionPolicyBindings ().Get (test .Ctx (), vapb .Name , metav1.GetOptions {})
219
225
test .Expect (err ).ToNot (HaveOccurred ())
220
226
221
227
vapb .Spec .MatchResources .NamespaceSelector .MatchLabels = map [string ]string {"kueue-managed" : "true" }
222
228
_ , err = test .Client ().Core ().AdmissionregistrationV1 ().ValidatingAdmissionPolicyBindings ().Update (test .Ctx (), vapb , metav1.UpdateOptions {})
223
229
test .Expect (err ).ToNot (HaveOccurred ())
224
- time .Sleep (2 * time .Second ) // Wait for the ValidatingAdmissionPolicyBinding to be updated
225
230
defer revertVAPB (test , vapbCopy )
226
231
232
+ t .Run ("RayCluster should not be admitted without the 'kueue.x-k8s.io/queue-name' label in a labeled namespace" , func (t * testing.T ) {
233
+ rc = testingraycluster .MakeCluster (uniqueSuffix (rcNoLQName ), ns .Name ).Obj ()
234
+ test .Eventually (func () error {
235
+ _ , err := test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
236
+ return err
237
+ }).WithTimeout (5 * time .Second ).WithPolling (500 * time .Millisecond ).ShouldNot (Succeed ())
238
+ defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
239
+ })
227
240
t .Run ("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label in a labeled namespace" , func (t * testing.T ) {
228
241
rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), ns .Name ).Queue (lq .Name ).Obj ()
229
242
_ , err = test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
230
243
test .Expect (err ).ToNot (HaveOccurred ())
231
244
defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
232
245
})
233
- t .Run ("RayCluster should not be admitted without the 'kueue.x-k8s.io/queue-name' label in a labeled namespace" , func (t * testing.T ) {
234
- rc = testingraycluster .MakeCluster (uniqueSuffix (rcNoLQName ), ns .Name ).Obj ()
235
- _ , err = test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
236
- test .Expect (err ).ToNot (BeNil ())
237
- defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
238
- })
239
246
t .Run ("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label in any other namespace" , func (t * testing.T ) {
240
247
rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), "default" ).Queue (lq .Name ).Obj ()
241
248
_ , err = test .Client ().Ray ().RayV1 ().RayClusters ("default" ).Create (test .Ctx (), rc , metav1.CreateOptions {})
0 commit comments