Skip to content

Commit

Permalink
fix: flaky vap test
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobbins228 committed Jan 23, 2025
1 parent a0c05e1 commit acc3756
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tests/odh/validating_admission_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestValidatingAdmissionPolicy(t *testing.T) {

var (
ns *corev1.Namespace
nsNoLabel *corev1.Namespace
rf *kueuev1beta1.ResourceFlavor
cq *kueuev1beta1.ClusterQueue
lq *kueuev1beta1.LocalQueue
Expand All @@ -70,6 +71,10 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
ns = CreateTestNamespaceWithName(test, uniqueSuffix("vap"))
defer test.Client().Core().CoreV1().Namespaces().Delete(test.Ctx(), ns.Name, metav1.DeleteOptions{})

// Create a namespace that will not receive the `kueue.x-k8s.io/queue-name` label
nsNoLabel = CreateTestNamespaceWithName(test, uniqueSuffix("vap-nl"))
defer test.Client().Core().CoreV1().Namespaces().Delete(test.Ctx(), nsNoLabel.Name, metav1.DeleteOptions{})

// Create a resource flavor
rf = CreateKueueResourceFlavor(test, kueuev1beta1.ResourceFlavorSpec{})
defer test.Client().Kueue().KueueV1beta1().ResourceFlavors().Delete(test.Ctx(), rf.Name, metav1.DeleteOptions{})
Expand Down Expand Up @@ -176,7 +181,7 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
test.Eventually(func() error {
_, err := test.Client().Ray().RayV1().RayClusters(ns.Name).Create(test.Ctx(), rc, metav1.CreateOptions{})
return err
}).WithTimeout(5 * time.Second).WithPolling(500 * time.Millisecond).Should(Succeed())
}).WithTimeout(10 * time.Second).WithPolling(500 * time.Millisecond).Should(Succeed())
defer test.Client().Ray().RayV1().RayClusters(ns.Name).Delete(test.Ctx(), rc.Name, metav1.DeleteOptions{})
})
t.Run("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label set", func(t *testing.T) {
Expand Down Expand Up @@ -217,7 +222,7 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
test.Eventually(func() bool {
ns, _ = test.Client().Core().CoreV1().Namespaces().Get(test.Ctx(), ns.Name, metav1.GetOptions{})
return ns.Labels["kueue-managed"] == "true"
}).WithTimeout(5 * time.Second).WithPolling(500 * time.Millisecond).Should(BeTrue())
}).WithTimeout(10 * time.Second).WithPolling(500 * time.Millisecond).Should(BeTrue())
test.Expect(err).ToNot(HaveOccurred())

// Apply the ValidatingAdmissionPolicyBinding targetting namespaces with the label 'kueue-managed'
Expand All @@ -234,7 +239,7 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
test.Eventually(func() error {
_, err := test.Client().Ray().RayV1().RayClusters(ns.Name).Create(test.Ctx(), rc, metav1.CreateOptions{})
return err
}).WithTimeout(5 * time.Second).WithPolling(500 * time.Millisecond).ShouldNot(Succeed())
}).WithTimeout(10 * time.Second).WithPolling(500 * time.Millisecond).ShouldNot(Succeed())
defer test.Client().Ray().RayV1().RayClusters(ns.Name).Delete(test.Ctx(), rc.Name, metav1.DeleteOptions{})
})
t.Run("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label in a labeled namespace", func(t *testing.T) {
Expand All @@ -244,16 +249,18 @@ func TestValidatingAdmissionPolicy(t *testing.T) {
defer test.Client().Ray().RayV1().RayClusters(ns.Name).Delete(test.Ctx(), rc.Name, metav1.DeleteOptions{})
})
t.Run("RayCluster should be admitted with the 'kueue.x-k8s.io/queue-name' label in any other namespace", func(t *testing.T) {
rc = testingraycluster.MakeCluster(uniqueSuffix(rcWithLQName), "default").Queue(lq.Name).Obj()
_, err = test.Client().Ray().RayV1().RayClusters("default").Create(test.Ctx(), rc, metav1.CreateOptions{})
rc = testingraycluster.MakeCluster(uniqueSuffix(rcWithLQName), nsNoLabel.Name).Queue(lq.Name).Obj()
_, err = test.Client().Ray().RayV1().RayClusters(nsNoLabel.Name).Create(test.Ctx(), rc, metav1.CreateOptions{})
test.Expect(err).ToNot(HaveOccurred())
defer test.Client().Ray().RayV1().RayClusters("default").Delete(test.Ctx(), rc.Name, metav1.DeleteOptions{})
defer test.Client().Ray().RayV1().RayClusters(nsNoLabel.Name).Delete(test.Ctx(), rc.Name, metav1.DeleteOptions{})
})
t.Run("RayCluster should be admitted without the 'kueue.x-k8s.io/queue-name' label in any other namespace", func(t *testing.T) {
rc = testingraycluster.MakeCluster(uniqueSuffix(rcNoLQName), "default").Obj()
_, err = test.Client().Ray().RayV1().RayClusters("default").Create(test.Ctx(), rc, metav1.CreateOptions{})
test.Expect(err).ToNot(HaveOccurred())
defer test.Client().Ray().RayV1().RayClusters("default").Delete(test.Ctx(), rc.Name, metav1.DeleteOptions{})
rc = testingraycluster.MakeCluster(uniqueSuffix(rcNoLQName), nsNoLabel.Name).Obj()
test.Eventually(func() error {
_, err = test.Client().Ray().RayV1().RayClusters(nsNoLabel.Name).Create(test.Ctx(), rc, metav1.CreateOptions{})
return err
}).WithTimeout(10 * time.Second).WithPolling(500 * time.Millisecond).Should(Succeed())
defer test.Client().Ray().RayV1().RayClusters(nsNoLabel.Name).Delete(test.Ctx(), rc.Name, metav1.DeleteOptions{})
})
})
}
Expand Down

0 comments on commit acc3756

Please sign in to comment.