Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scheduler: pick vf by random #1953

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pkg/scheduler/plugins/deviceshare/device_allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package deviceshare

import (
"fmt"
"math/rand"
"sort"

corev1 "k8s.io/api/core/v1"
Expand All @@ -33,6 +34,10 @@ 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{}

Expand Down Expand Up @@ -476,10 +481,11 @@ 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[0]
vf := &remainingVFs[randIntnFn(len(remainingVFs))]
return vf
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/scheduler/plugins/deviceshare/device_allocator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,9 @@ 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()
Expand Down Expand Up @@ -1703,6 +1706,9 @@ 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()
Expand Down
Loading