Skip to content

Commit

Permalink
Define priority by value in testing wrappers
Browse files Browse the repository at this point in the history
Change-Id: Ifa67274f60077c300d7b822bfde74974beea964a
  • Loading branch information
alculquicondor committed Jan 10, 2023
1 parent 74d5969 commit 7a443c7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
3 changes: 1 addition & 2 deletions apis/kueue/webhooks/workload_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/util/validation/field"

kueue "sigs.k8s.io/kueue/apis/kueue/v1alpha2"
"sigs.k8s.io/kueue/pkg/util/pointer"
testingutil "sigs.k8s.io/kueue/pkg/util/testing"
)

Expand Down Expand Up @@ -220,7 +219,7 @@ func TestValidateWorkload(t *testing.T) {
"should have valid priorityClassName": {
workload: testingutil.MakeWorkload(testWorkloadName, testWorkloadNamespace).
PriorityClass("invalid_class").
Priority(pointer.Int32(0)).
Priority(0).
Obj(),
wantErr: field.ErrorList{
field.Invalid(specField.Child("priorityClassName"), nil, ""),
Expand Down
3 changes: 1 addition & 2 deletions pkg/util/priority/priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

kueue "sigs.k8s.io/kueue/apis/kueue/v1alpha2"
"sigs.k8s.io/kueue/pkg/constants"
"sigs.k8s.io/kueue/pkg/util/pointer"
utiltesting "sigs.k8s.io/kueue/pkg/util/testing"
)

Expand All @@ -38,7 +37,7 @@ func TestPriority(t *testing.T) {
want int32
}{
"priority is specified": {
workload: utiltesting.MakeWorkload("name", "ns").Priority(pointer.Int32(100)).Obj(),
workload: utiltesting.MakeWorkload("name", "ns").Priority(100).Obj(),
want: 100,
},
"priority is empty": {
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/testing/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ func (w *WorkloadWrapper) RuntimeClass(name string) *WorkloadWrapper {
return w
}

func (w *WorkloadWrapper) Priority(priority *int32) *WorkloadWrapper {
w.Spec.Priority = priority
func (w *WorkloadWrapper) Priority(priority int32) *WorkloadWrapper {
w.Spec.Priority = &priority
return w
}

Expand Down
17 changes: 8 additions & 9 deletions test/integration/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

kueue "sigs.k8s.io/kueue/apis/kueue/v1alpha2"
"sigs.k8s.io/kueue/pkg/metrics"
"sigs.k8s.io/kueue/pkg/util/pointer"
"sigs.k8s.io/kueue/pkg/util/testing"
"sigs.k8s.io/kueue/test/util"
)
Expand Down Expand Up @@ -157,9 +156,9 @@ var _ = ginkgo.Describe("Scheduler", func() {

lowPriorityVal, highPriorityVal := int32(10), int32(100)

wlLowPriority := testing.MakeWorkload("wl-low-priority", ns.Name).Queue(queue.Name).Request(corev1.ResourceCPU, "5").Priority(&lowPriorityVal).Obj()
wlLowPriority := testing.MakeWorkload("wl-low-priority", ns.Name).Queue(queue.Name).Request(corev1.ResourceCPU, "5").Priority(lowPriorityVal).Obj()
gomega.Expect(k8sClient.Create(ctx, wlLowPriority)).Should(gomega.Succeed())
wlHighPriority := testing.MakeWorkload("wl-high-priority", ns.Name).Queue(queue.Name).Request(corev1.ResourceCPU, "5").Priority(&highPriorityVal).Obj()
wlHighPriority := testing.MakeWorkload("wl-high-priority", ns.Name).Queue(queue.Name).Request(corev1.ResourceCPU, "5").Priority(highPriorityVal).Obj()
gomega.Expect(k8sClient.Create(ctx, wlHighPriority)).Should(gomega.Succeed())

util.ExpectPendingWorkloadsMetric(prodClusterQ, 0, 0)
Expand Down Expand Up @@ -873,14 +872,14 @@ var _ = ginkgo.Describe("Scheduler", func() {

ginkgo.By("Creating workloads")
wl1 := testing.MakeWorkload("wl1", matchingNS.Name).Queue(strictFIFOQueue.
Name).Request(corev1.ResourceCPU, "2").Priority(pointer.Int32(100)).Obj()
Name).Request(corev1.ResourceCPU, "2").Priority(100).Obj()
gomega.Expect(k8sClient.Create(ctx, wl1)).Should(gomega.Succeed())
wl2 := testing.MakeWorkload("wl2", matchingNS.Name).Queue(strictFIFOQueue.
Name).Request(corev1.ResourceCPU, "5").Priority(pointer.Int32(10)).Obj()
Name).Request(corev1.ResourceCPU, "5").Priority(10).Obj()
gomega.Expect(k8sClient.Create(ctx, wl2)).Should(gomega.Succeed())
// wl3 can't be scheduled before wl2 even though there is enough quota.
wl3 := testing.MakeWorkload("wl3", matchingNS.Name).Queue(strictFIFOQueue.
Name).Request(corev1.ResourceCPU, "1").Priority(pointer.Int32(1)).Obj()
Name).Request(corev1.ResourceCPU, "1").Priority(1).Obj()
gomega.Expect(k8sClient.Create(ctx, wl3)).Should(gomega.Succeed())

gomega.Expect(k8sClient.Create(ctx, strictFIFOQueue)).Should(gomega.Succeed())
Expand All @@ -907,14 +906,14 @@ var _ = ginkgo.Describe("Scheduler", func() {

ginkgo.By("Creating workloads")
wl1 := testing.MakeWorkload("wl1", matchingNS.Name).Queue(matchingQueue.
Name).Request(corev1.ResourceCPU, "2").Priority(pointer.Int32(100)).Obj()
Name).Request(corev1.ResourceCPU, "2").Priority(100).Obj()
gomega.Expect(k8sClient.Create(ctx, wl1)).Should(gomega.Succeed())
wl2 := testing.MakeWorkload("wl2", ns.Name).Queue(notMatchingQueue.
Name).Request(corev1.ResourceCPU, "5").Priority(pointer.Int32(10)).Obj()
Name).Request(corev1.ResourceCPU, "5").Priority(10).Obj()
gomega.Expect(k8sClient.Create(ctx, wl2)).Should(gomega.Succeed())
// wl2 can't block wl3 from getting scheduled.
wl3 := testing.MakeWorkload("wl3", matchingNS.Name).Queue(matchingQueue.
Name).Request(corev1.ResourceCPU, "1").Priority(pointer.Int32(1)).Obj()
Name).Request(corev1.ResourceCPU, "1").Priority(1).Obj()
gomega.Expect(k8sClient.Create(ctx, wl3)).Should(gomega.Succeed())

util.ExpectWorkloadsToBeAdmitted(ctx, k8sClient, strictFIFOClusterQ.Name, wl1, wl3)
Expand Down

0 comments on commit 7a443c7

Please sign in to comment.