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()