Skip to content

Commit

Permalink
add integration test for workload priority
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Wang <wangqingcan1990@gmail.com>
  • Loading branch information
denkensk committed Mar 17, 2022
1 parent 561fe4f commit 43a56b3
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 12 deletions.
27 changes: 18 additions & 9 deletions test/integration/controller/job/job_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,26 @@ import (
)

const (
parallelism = 4
jobName = "test-job"
jobNamespace = "default"
jobKey = jobNamespace + "/" + jobName
labelKey = "cloud.provider.com/instance"
flavorOnDemand = "on-demand"
flavorSpot = "spot"
parallelism = 4
jobName = "test-job"
jobNamespace = "default"
jobKey = jobNamespace + "/" + jobName
labelKey = "cloud.provider.com/instance"
flavorOnDemand = "on-demand"
flavorSpot = "spot"
priorityClassName = "test-priority-class"
priorityValue = 10
)

// +kubebuilder:docs-gen:collapse=Imports

var _ = ginkgo.Describe("Job controller", func() {
ginkgo.It("Should reconcile workload and job", func() {
ginkgo.By("checking the job gets suspended when created unsuspended")
job := testing.MakeJob(jobName, jobNamespace).Obj()
priorityClass := testing.MakePriorityClass(priorityClassName).
PriorityValue(int32(priorityValue)).Obj()
gomega.Expect(k8sClient.Create(ctx, priorityClass)).Should(gomega.Succeed())
job := testing.MakeJob(jobName, jobNamespace).PriorityClass(priorityClassName).Obj()
gomega.Expect(k8sClient.Create(ctx, job)).Should(gomega.Succeed())
lookupKey := types.NamespacedName{Name: jobName, Namespace: jobNamespace}
createdJob := &batchv1.Job{}
Expand All @@ -70,6 +75,10 @@ var _ = ginkgo.Describe("Job controller", func() {
}, framework.Timeout, framework.Interval).Should(gomega.BeTrue())
gomega.Expect(createdWorkload.Spec.QueueName).Should(gomega.Equal(""))

ginkgo.By("checking the workload is created with priority and priorityName")
gomega.Expect(createdWorkload.Spec.PriorityClassName).Should(gomega.Equal(priorityClassName))
gomega.Expect(*createdWorkload.Spec.Priority).Should(gomega.Equal(int32(priorityValue)))

ginkgo.By("checking the workload is updated with queue name when the job does")
jobQueueName := "test-queue"
createdJob.Annotations = map[string]string{constants.QueueAnnotation: jobQueueName}
Expand All @@ -82,7 +91,7 @@ var _ = ginkgo.Describe("Job controller", func() {
}, framework.Timeout, framework.Interval).Should(gomega.BeTrue())

ginkgo.By("checking a second non-matching workload is deleted")
secondWl, _ := workloadjob.ConstructWorkloadFor(createdJob, scheme.Scheme)
secondWl, _ := workloadjob.ConstructWorkloadFor(ctx, k8sClient, createdJob, scheme.Scheme)
secondWl.Name = "second-workload"
secondWl.Spec.PodSets[0].Count = parallelism + 1
gomega.Expect(k8sClient.Create(ctx, secondWl)).Should(gomega.Succeed())
Expand Down
76 changes: 73 additions & 3 deletions test/integration/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ import (

var _ = ginkgo.Describe("Scheduler", func() {
const (
instanceKey = "cloud.provider.com/instance"
onDemandFlavor = "on-demand"
spotFlavor = "spot"
instanceKey = "cloud.provider.com/instance"
onDemandFlavor = "on-demand"
spotFlavor = "spot"
highPriorityClassName = "high-priority"
highPriority = 100
lowPriorityClassName = "low-priority"
lowPriority = 10
)

var (
Expand Down Expand Up @@ -269,4 +273,70 @@ var _ = ginkgo.Describe("Scheduler", func() {
return createdJob.Spec.Suspend
}, framework.Timeout, framework.Interval).Should(gomega.Equal(pointer.Bool(false)))
})

ginkgo.It("Should schedule jobs according to the priority", func() {
// Initialize clusterQueue first but do not create
clusterQ := testing.MakeClusterQueue("cluster-queue").Resource(testing.MakeResource(corev1.ResourceCPU).
Flavor(testing.MakeFlavor(onDemandFlavor, "1").Obj()).Obj()).Obj()

queue := testing.MakeQueue("queue", ns.Name).ClusterQueue(clusterQ.Name).Obj()
gomega.Expect(k8sClient.Create(ctx, queue)).Should(gomega.Succeed())

highPriorityClass := testing.MakePriorityClass(highPriorityClassName).
PriorityValue(int32(highPriority)).Obj()
gomega.Expect(k8sClient.Create(ctx, highPriorityClass)).Should(gomega.Succeed())

lowPriorityClass := testing.MakePriorityClass(lowPriorityClassName).
PriorityValue(int32(lowPriority)).Obj()
gomega.Expect(k8sClient.Create(ctx, lowPriorityClass)).Should(gomega.Succeed())

job1 := testing.MakeJob("job1", ns.Name).Queue(queue.Name).Request(
corev1.ResourceCPU, "1").PriorityClass(lowPriorityClassName).Obj()
gomega.Expect(k8sClient.Create(ctx, job1)).Should(gomega.Succeed())
job2 := testing.MakeJob("job2", ns.Name).Queue(queue.Name).Request(
corev1.ResourceCPU, "1").PriorityClass(highPriorityClassName).Obj()
gomega.Expect(k8sClient.Create(ctx, job2)).Should(gomega.Succeed())

ginkgo.By("checking the workload1 is created with priority and priorityName")
createdWorkload1 := &kueue.QueuedWorkload{}
lookupKey1 := types.NamespacedName{Name: "job1", Namespace: ns.Name}
gomega.Eventually(func() bool {
err := k8sClient.Get(ctx, lookupKey1, createdWorkload1)
return err == nil
}, framework.Timeout, framework.Interval).Should(gomega.BeTrue())
gomega.Expect(createdWorkload1.Spec.PriorityClassName).Should(gomega.Equal(lowPriorityClassName))
gomega.Expect(*createdWorkload1.Spec.Priority).Should(gomega.Equal(int32(lowPriority)))

ginkgo.By("checking the workload2 is created with priority and priorityName")
createdWorkload2 := &kueue.QueuedWorkload{}
lookupKey2 := types.NamespacedName{Name: "job2", Namespace: ns.Name}
gomega.Eventually(func() bool {
err := k8sClient.Get(ctx, lookupKey2, createdWorkload2)
return err == nil
}, framework.Timeout, framework.Interval).Should(gomega.BeTrue())
gomega.Expect(createdWorkload2.Spec.PriorityClassName).Should(gomega.Equal(highPriorityClassName))
gomega.Expect(*createdWorkload2.Spec.Priority).Should(gomega.Equal(int32(highPriority)))

// Create clusterQueue
gomega.Expect(k8sClient.Create(ctx, clusterQ)).Should(gomega.Succeed())
defer func() {
gomega.Expect(framework.DeleteClusterQueue(ctx, k8sClient, clusterQ)).ToNot(gomega.HaveOccurred())
}()

ginkgo.By("checking the job with low priority suspends")
createdJob1 := &batchv1.Job{}
gomega.Eventually(func() *bool {
gomega.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: "job1",
Namespace: ns.Name}, createdJob1)).Should(gomega.Succeed())
return createdJob1.Spec.Suspend
}, framework.Timeout, framework.Interval).Should(gomega.Equal(pointer.Bool(true)))

ginkgo.By("checking the job with high priority starts")
createdJob2 := &batchv1.Job{}
gomega.Eventually(func() *bool {
gomega.Expect(k8sClient.Get(ctx, types.NamespacedName{Name: "job2",
Namespace: ns.Name}, createdJob2)).Should(gomega.Succeed())
return createdJob2.Spec.Suspend
}, framework.Timeout, framework.Interval).Should(gomega.Equal(pointer.Bool(false)))
})
})

0 comments on commit 43a56b3

Please sign in to comment.