@@ -168,17 +168,19 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
168168 vapb .Spec .PolicyName = "none"
169169 _ , err = test .Client ().Core ().AdmissionregistrationV1 ().ValidatingAdmissionPolicyBindings ().Update (test .Ctx (), vapb , metav1.UpdateOptions {})
170170 test .Expect (err ).ToNot (HaveOccurred ())
171- time .Sleep (2 * time .Second ) // Wait for the ValidatingAdmissionPolicyBinding to be updated
172171 defer revertVAPB (test , vapbCopy )
173172
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- })
180173 t .Run ("RayCluster should be admitted without the 'kueue.x-k8s.io/queue-name' label set" , func (t * testing.T ) {
181174 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 ()
182184 _ , err = test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
183185 test .Expect (err ).ToNot (HaveOccurred ())
184186 defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
@@ -212,30 +214,35 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
212214 }
213215 ns .Labels ["kueue-managed" ] = "true"
214216 _ , 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 ())
215221 test .Expect (err ).ToNot (HaveOccurred ())
216222
217223 // 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 {})
219225 test .Expect (err ).ToNot (HaveOccurred ())
220226
221227 vapb .Spec .MatchResources .NamespaceSelector .MatchLabels = map [string ]string {"kueue-managed" : "true" }
222228 _ , err = test .Client ().Core ().AdmissionregistrationV1 ().ValidatingAdmissionPolicyBindings ().Update (test .Ctx (), vapb , metav1.UpdateOptions {})
223229 test .Expect (err ).ToNot (HaveOccurred ())
224- time .Sleep (2 * time .Second ) // Wait for the ValidatingAdmissionPolicyBinding to be updated
225230 defer revertVAPB (test , vapbCopy )
226231
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+ })
227240 t .Run ("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label in a labeled namespace" , func (t * testing.T ) {
228241 rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), ns .Name ).Queue (lq .Name ).Obj ()
229242 _ , err = test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Create (test .Ctx (), rc , metav1.CreateOptions {})
230243 test .Expect (err ).ToNot (HaveOccurred ())
231244 defer test .Client ().Ray ().RayV1 ().RayClusters (ns .Name ).Delete (test .Ctx (), rc .Name , metav1.DeleteOptions {})
232245 })
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- })
239246 t .Run ("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label in any other namespace" , func (t * testing.T ) {
240247 rc = testingraycluster .MakeCluster (uniqueSuffix (rcWithLQName ), "default" ).Queue (lq .Name ).Obj ()
241248 _ , err = test .Client ().Ray ().RayV1 ().RayClusters ("default" ).Create (test .Ctx (), rc , metav1.CreateOptions {})
0 commit comments