From fbdc1e065fddca2b1e0242d64076455a64a592e8 Mon Sep 17 00:00:00 2001 From: wangjianyu Date: Tue, 9 Apr 2024 11:52:32 +0800 Subject: [PATCH] Revert "scheduler: pick vf by random (#1953)" (#1986) Signed-off-by: wangjianyu.wjy Co-authored-by: wangjianyu.wjy Signed-off-by: george --- pkg/scheduler/plugins/deviceshare/device_allocator.go | 8 +------- .../plugins/deviceshare/device_allocator_test.go | 6 ------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/pkg/scheduler/plugins/deviceshare/device_allocator.go b/pkg/scheduler/plugins/deviceshare/device_allocator.go index 0bf5d9304..99c791fbd 100644 --- a/pkg/scheduler/plugins/deviceshare/device_allocator.go +++ b/pkg/scheduler/plugins/deviceshare/device_allocator.go @@ -18,7 +18,6 @@ package deviceshare import ( "fmt" - "math/rand" "sort" corev1 "k8s.io/api/core/v1" @@ -34,10 +33,6 @@ import ( "github.com/koordinator-sh/koordinator/pkg/util/bitmask" ) -var ( - randIntnFn = rand.Intn -) - var deviceHandlers = map[schedulingv1alpha1.DeviceType]DeviceHandler{} var deviceAllocators = map[schedulingv1alpha1.DeviceType]DeviceAllocator{} @@ -489,11 +484,10 @@ func allocateVF(vfAllocation *VFAllocation, deviceInfos map[int]*schedulingv1alp if len(remainingVFs) == 0 { return nil } - // Here we sort the remaining vf just for test deterministic. In fact, we pick the vf by random to alleviating some unexpected vf duplicate allocation problem due to uncoordinated scheduling and node-side vf allocation components sort.Slice(remainingVFs, func(i, j int) bool { return remainingVFs[i].BusID < remainingVFs[j].BusID }) - vf := &remainingVFs[randIntnFn(len(remainingVFs))] + vf := &remainingVFs[0] return vf } diff --git a/pkg/scheduler/plugins/deviceshare/device_allocator_test.go b/pkg/scheduler/plugins/deviceshare/device_allocator_test.go index ea0198ef9..629fea82a 100644 --- a/pkg/scheduler/plugins/deviceshare/device_allocator_test.go +++ b/pkg/scheduler/plugins/deviceshare/device_allocator_test.go @@ -866,9 +866,6 @@ func TestAutopilotAllocator(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - randIntnFn = func(n int) int { - return 0 - } deviceCR := tt.deviceCR.DeepCopy() deviceCR.ResourceVersion = "1" koordFakeClient := koordfake.NewSimpleClientset() @@ -1706,9 +1703,6 @@ func TestAutopilotAllocatorWithExclusivePolicyAndRequiredScope(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - randIntnFn = func(n int) int { - return 0 - } deviceCR := tt.deviceCR.DeepCopy() deviceCR.ResourceVersion = "1" koordFakeClient := koordfake.NewSimpleClientset()