Skip to content

Commit 47ce634

Browse files
committed
fix: scale test flaky queue update
Signed-off-by: Erez Freiberger <enoodle@gmail.com>
1 parent c048f65 commit 47ce634

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

test/e2e/scale/kwok_test.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package scale
55

66
import (
77
"context"
8+
"encoding/json"
89
"errors"
910
"fmt"
1011
"os"
@@ -18,6 +19,7 @@ import (
1819
v1 "k8s.io/api/core/v1"
1920
"k8s.io/apimachinery/pkg/api/resource"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/apimachinery/pkg/types"
2123
runtimeClient "sigs.k8s.io/controller-runtime/pkg/client"
2224
"sigs.k8s.io/yaml"
2325

@@ -370,12 +372,11 @@ var _ = Describe("Kwok scale test", Ordered, Label(labels.Scale), func() {
370372

371373
Context("Reclaim", func() {
372374
BeforeAll(func(ctx context.Context) {
373-
sanityTestQueue.Spec.Resources.GPU = v2.QueueResource{
375+
Expect(patchQueueGPU(ctx, testCtx, sanityTestQueue, v2.QueueResource{
374376
Quota: 0,
375377
OverQuotaWeight: 0,
376378
Limit: -1,
377-
}
378-
Expect(testCtx.ControllerClient.Patch(ctx, sanityTestQueue, runtimeClient.MergeFrom(&v2.Queue{}))).To(Succeed())
379+
})).To(Succeed())
379380

380381
reclaimSingleGPUJobsQueue = queue.CreateQueueObject("reclaim-single-"+utils.GenerateRandomK8sName(10), parentQueue.Name)
381382
testCtx.AddQueues(ctx, []*v2.Queue{reclaimSingleGPUJobsQueue})
@@ -388,18 +389,22 @@ var _ = Describe("Kwok scale test", Ordered, Label(labels.Scale), func() {
388389

389390
Context("measure reclaim failure time", func() {
390391
BeforeAll(func(ctx context.Context) {
391-
Expect(testCtx.ControllerClient.Get(ctx, runtimeClient.ObjectKeyFromObject(sanityTestQueue), sanityTestQueue)).To(Succeed())
392-
sanityTestQueue.Spec.Resources.GPU.Quota = float64((numberOfNodes * gpusPerNode) - (defaultPodsPerDistributedJob * gpusPerNode) + 1)
393-
Expect(testCtx.ControllerClient.Update(ctx, sanityTestQueue)).To(Succeed())
392+
Expect(patchQueueGPU(ctx, testCtx, sanityTestQueue, v2.QueueResource{
393+
Quota: float64((numberOfNodes * gpusPerNode) - (defaultPodsPerDistributedJob * gpusPerNode) + 1),
394+
OverQuotaWeight: 0,
395+
Limit: -1,
396+
})).To(Succeed())
394397
})
395398

396399
AfterAll(func(ctx context.Context) {
397400
if CurrentSpecReport().Failed() {
398401
return
399402
}
400-
Expect(testCtx.ControllerClient.Get(ctx, runtimeClient.ObjectKeyFromObject(sanityTestQueue), sanityTestQueue)).To(Succeed())
401-
sanityTestQueue.Spec.Resources.GPU.Quota = 0
402-
Expect(testCtx.ControllerClient.Update(ctx, sanityTestQueue)).To(Succeed())
403+
Expect(patchQueueGPU(ctx, testCtx, sanityTestQueue, v2.QueueResource{
404+
Quota: 0,
405+
OverQuotaWeight: 0,
406+
Limit: -1,
407+
})).To(Succeed())
403408
})
404409

405410
It("measure time for reclaim to fail on distributed job last pod", func(ctx context.Context) {
@@ -554,6 +559,20 @@ var _ = Describe("Kwok scale test", Ordered, Label(labels.Scale), func() {
554559
})
555560
})
556561

562+
func patchQueueGPU(ctx context.Context, testCtx *testcontext.TestContext, queue *v2.Queue, gpu v2.QueueResource) error {
563+
patch, err := json.Marshal(map[string]interface{}{
564+
"spec": map[string]interface{}{
565+
"resources": map[string]interface{}{
566+
"gpu": gpu,
567+
},
568+
},
569+
})
570+
if err != nil {
571+
return err
572+
}
573+
return testCtx.ControllerClient.Patch(ctx, queue, runtimeClient.RawPatch(types.MergePatchType, patch))
574+
}
575+
557576
func updateFakeGPUOperatorGPUsPerNode(ctx context.Context, testCtx *testcontext.TestContext) {
558577
topologyConfig := &v1.ConfigMap{}
559578

0 commit comments

Comments
 (0)