Skip to content

Commit

Permalink
[test][integration][ray] Fix cleanup for flavors and priority-class (k…
Browse files Browse the repository at this point in the history
…ubernetes-sigs#3123)

* [test][int][rayjob]Fix flavor cleanup

* [test][int][raycluster]Fix flavor cleanup

* [test][int][raycluster]Fix priority cleanup

* [test][int][rayjob]Fix priority cleanup

* Use std. `defer` since `ginkgo.DeferCleanup` are called after `AfterAll`
  • Loading branch information
trasc authored and kannon92 committed Nov 19, 2024
1 parent 913a2c8 commit f06f00e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/onsi/gomega"
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
corev1 "k8s.io/api/core/v1"
schedulingv1 "k8s.io/api/scheduling/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -88,6 +89,9 @@ var _ = ginkgo.Describe("RayCluster controller", ginkgo.Ordered, ginkgo.Continue
priorityClass := testing.MakePriorityClass(priorityClassName).
PriorityValue(priorityValue).Obj()
gomega.Expect(k8sClient.Create(ctx, priorityClass)).Should(gomega.Succeed())
defer func() {
util.ExpectObjectToBeDeleted(ctx, k8sClient, priorityClass, true)
}()

job := testingraycluster.MakeCluster(jobName, ns.Name).
Suspend(false).
Expand Down Expand Up @@ -156,6 +160,10 @@ var _ = ginkgo.Describe("RayCluster controller", ginkgo.Ordered, ginkgo.Continue
gomega.Expect(k8sClient.Create(ctx, onDemandFlavor)).Should(gomega.Succeed())
spotFlavor := testing.MakeResourceFlavor("spot").NodeLabel(instanceKey, "spot").Obj()
gomega.Expect(k8sClient.Create(ctx, spotFlavor)).Should(gomega.Succeed())
defer func() {
util.ExpectObjectToBeDeleted(ctx, k8sClient, spotFlavor, true)
util.ExpectObjectToBeDeleted(ctx, k8sClient, onDemandFlavor, true)
}()
clusterQueue := testing.MakeClusterQueue("cluster-queue").
ResourceGroup(
*testing.MakeFlavorQuotas("on-demand").Resource(corev1.ResourceCPU, "5").Obj(),
Expand Down Expand Up @@ -646,6 +654,7 @@ var _ = ginkgo.Describe("Job controller with preemption enabled", ginkgo.Ordered
onDemandFlavor *kueue.ResourceFlavor
clusterQueue *kueue.ClusterQueue
localQueue *kueue.LocalQueue
priorityClass *schedulingv1.PriorityClass
)

ginkgo.BeforeEach(func() {
Expand Down Expand Up @@ -674,14 +683,15 @@ var _ = ginkgo.Describe("Job controller with preemption enabled", ginkgo.Ordered
gomega.Expect(k8sClient.Create(ctx, localQueue)).Should(gomega.Succeed())

ginkgo.By("creating priority")
priorityClass := testing.MakePriorityClass(priorityClassName).
priorityClass = testing.MakePriorityClass(priorityClassName).
PriorityValue(priorityValue).Obj()
gomega.Expect(k8sClient.Create(ctx, priorityClass)).Should(gomega.Succeed())
})
ginkgo.AfterEach(func() {
gomega.Expect(util.DeleteNamespace(ctx, k8sClient, ns)).To(gomega.Succeed())
util.ExpectObjectToBeDeleted(ctx, k8sClient, clusterQueue, true)
util.ExpectObjectToBeDeleted(ctx, k8sClient, onDemandFlavor, true)
util.ExpectObjectToBeDeleted(ctx, k8sClient, priorityClass, true)
})

ginkgo.It("Should preempt lower priority RayClusters when resource insufficient", func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/onsi/gomega"
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
corev1 "k8s.io/api/core/v1"
schedulingv1 "k8s.io/api/scheduling/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -97,6 +98,9 @@ var _ = ginkgo.Describe("Job controller", ginkgo.Ordered, ginkgo.ContinueOnFailu
priorityClass := testing.MakePriorityClass(priorityClassName).
PriorityValue(priorityValue).Obj()
gomega.Expect(k8sClient.Create(ctx, priorityClass)).Should(gomega.Succeed())
defer func() {
util.ExpectObjectToBeDeleted(ctx, k8sClient, priorityClass, true)
}()

job := testingrayjob.MakeJob(jobName, ns.Name).
Suspend(false).
Expand Down Expand Up @@ -165,6 +169,10 @@ var _ = ginkgo.Describe("Job controller", ginkgo.Ordered, ginkgo.ContinueOnFailu
gomega.Expect(k8sClient.Create(ctx, onDemandFlavor)).Should(gomega.Succeed())
spotFlavor := testing.MakeResourceFlavor("spot").NodeLabel(instanceKey, "spot").Obj()
gomega.Expect(k8sClient.Create(ctx, spotFlavor)).Should(gomega.Succeed())
defer func() {
util.ExpectObjectToBeDeleted(ctx, k8sClient, spotFlavor, true)
util.ExpectObjectToBeDeleted(ctx, k8sClient, onDemandFlavor, true)
}()
clusterQueue := testing.MakeClusterQueue("cluster-queue").
ResourceGroup(
*testing.MakeFlavorQuotas("on-demand").Resource(corev1.ResourceCPU, "5").Obj(),
Expand Down Expand Up @@ -613,6 +621,7 @@ var _ = ginkgo.Describe("Job controller with preemption enabled", ginkgo.Ordered
onDemandFlavor *kueue.ResourceFlavor
clusterQueue *kueue.ClusterQueue
localQueue *kueue.LocalQueue
priorityClass *schedulingv1.PriorityClass
)

ginkgo.BeforeEach(func() {
Expand Down Expand Up @@ -641,14 +650,15 @@ var _ = ginkgo.Describe("Job controller with preemption enabled", ginkgo.Ordered
gomega.Expect(k8sClient.Create(ctx, localQueue)).Should(gomega.Succeed())

ginkgo.By("creating priority")
priorityClass := testing.MakePriorityClass(priorityClassName).
priorityClass = testing.MakePriorityClass(priorityClassName).
PriorityValue(priorityValue).Obj()
gomega.Expect(k8sClient.Create(ctx, priorityClass)).Should(gomega.Succeed())
})
ginkgo.AfterEach(func() {
gomega.Expect(util.DeleteNamespace(ctx, k8sClient, ns)).To(gomega.Succeed())
util.ExpectObjectToBeDeleted(ctx, k8sClient, clusterQueue, true)
util.ExpectObjectToBeDeleted(ctx, k8sClient, onDemandFlavor, true)
util.ExpectObjectToBeDeleted(ctx, k8sClient, priorityClass, true)
})

ginkgo.It("Should preempt lower priority rayJobs when resource insufficient", func() {
Expand Down

0 comments on commit f06f00e

Please sign in to comment.