Skip to content

Commit

Permalink
Lint check update
Browse files Browse the repository at this point in the history
Signed-off-by: aavarghese <avarghese@us.ibm.com>
  • Loading branch information
aavarghese committed Oct 27, 2021
1 parent 02ede23 commit 31a3c56
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/scheduler/statefulset/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ package statefulset

import (
"context"
"crypto/rand"
"fmt"
"math/rand"
"math/big"
"sort"
"sync"
"time"
Expand Down Expand Up @@ -485,15 +486,19 @@ func (s *StatefulSetScheduler) selectPod(podScoreList st.PodScoreList) (int32, e

maxScore := podScoreList[0].Score
selected := podScoreList[0].ID
cntOfMaxScore := 1
cntOfMaxScore := int64(1)
for _, ps := range podScoreList[1:] {
if ps.Score > maxScore {
maxScore = ps.Score
selected = ps.ID
cntOfMaxScore = 1
} else if ps.Score == maxScore { //if equal scores, randomly picks one
cntOfMaxScore++
if rand.Intn(cntOfMaxScore) == 0 {
randNum, err := rand.Int(rand.Reader, big.NewInt(cntOfMaxScore))
if err != nil {
return -1, fmt.Errorf("failed to generate random number")
}
if randNum.Int64() == int64(0) {
selected = ps.ID
}
}
Expand Down

0 comments on commit 31a3c56

Please sign in to comment.