Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a6aaf818
Commit
a6aaf818
authored
Mar 08, 2016
by
k8s-merge-robot
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #22430 from gmarek/round-robin
Auto commit by PR queue bot
parents
7e9256b3
2c52e626
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
20 deletions
+21
-20
generic_scheduler.go
plugin/pkg/scheduler/generic_scheduler.go
+21
-20
No files found.
plugin/pkg/scheduler/generic_scheduler.go
View file @
a6aaf818
...
...
@@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"math/rand"
"sort"
"strings"
"sync"
...
...
@@ -55,12 +56,13 @@ func (f *FitError) Error() string {
}
type
genericScheduler
struct
{
predicates
map
[
string
]
algorithm
.
FitPredicate
prioritizers
[]
algorithm
.
PriorityConfig
extenders
[]
algorithm
.
SchedulerExtender
pods
algorithm
.
PodLister
random
*
rand
.
Rand
randomLock
sync
.
Mutex
predicates
map
[
string
]
algorithm
.
FitPredicate
prioritizers
[]
algorithm
.
PriorityConfig
extenders
[]
algorithm
.
SchedulerExtender
pods
algorithm
.
PodLister
random
*
rand
.
Rand
randomLock
sync
.
Mutex
lastNodeIndex
uint64
}
// Schedule tries to schedule the given pod to one of node in the node list.
...
...
@@ -109,24 +111,16 @@ func (g *genericScheduler) selectHost(priorityList schedulerapi.HostPriorityList
return
""
,
fmt
.
Errorf
(
"empty priorityList"
)
}
sort
.
Sort
(
sort
.
Reverse
(
priorityList
))
maxScore
:=
priorityList
[
0
]
.
Score
// idx contains indices of elements with score == maxScore.
idx
:=
[]
int
{}
for
i
,
entry
:=
range
priorityList
{
if
entry
.
Score
>
maxScore
{
maxScore
=
entry
.
Score
idx
=
[]
int
{
i
}
}
else
if
entry
.
Score
==
maxScore
{
idx
=
append
(
idx
,
i
)
}
}
firstAfterMaxScore
:=
sort
.
Search
(
len
(
priorityList
),
func
(
i
int
)
bool
{
return
priorityList
[
i
]
.
Score
<
maxScore
})
g
.
randomLock
.
Lock
()
ix
:=
g
.
random
.
Int
()
%
len
(
idx
)
ix
:=
int
(
g
.
lastNodeIndex
%
uint64
(
firstAfterMaxScore
))
g
.
lastNodeIndex
++
g
.
randomLock
.
Unlock
()
return
priorityList
[
i
dx
[
ix
]
]
.
Host
,
nil
return
priorityList
[
i
x
]
.
Host
,
nil
}
// Filters the nodes to find the ones that fit based on the given predicate functions
...
...
@@ -188,7 +182,14 @@ func findNodesThatFit(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.No
// Each priority function can also have its own weight
// The node scores returned by the priority function are multiplied by the weights to get weighted scores
// All scores are finally combined (added) to get the total weighted scores of all nodes
func
PrioritizeNodes
(
pod
*
api
.
Pod
,
nodeNameToInfo
map
[
string
]
*
schedulercache
.
NodeInfo
,
podLister
algorithm
.
PodLister
,
priorityConfigs
[]
algorithm
.
PriorityConfig
,
nodeLister
algorithm
.
NodeLister
,
extenders
[]
algorithm
.
SchedulerExtender
)
(
schedulerapi
.
HostPriorityList
,
error
)
{
func
PrioritizeNodes
(
pod
*
api
.
Pod
,
nodeNameToInfo
map
[
string
]
*
schedulercache
.
NodeInfo
,
podLister
algorithm
.
PodLister
,
priorityConfigs
[]
algorithm
.
PriorityConfig
,
nodeLister
algorithm
.
NodeLister
,
extenders
[]
algorithm
.
SchedulerExtender
,
)
(
schedulerapi
.
HostPriorityList
,
error
)
{
result
:=
schedulerapi
.
HostPriorityList
{}
// If no priority configs are provided, then the EqualPriority function is applied
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment