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
a45c9829
Commit
a45c9829
authored
Nov 16, 2015
by
David Oppenheimer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Avoid full sort when selecting host with highest priority."
This reverts commit
c64048d7
. Address #17332.
parent
70d89a35
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
19 deletions
+20
-19
generic_scheduler.go
plugin/pkg/scheduler/generic_scheduler.go
+20
-19
No files found.
plugin/pkg/scheduler/generic_scheduler.go
View file @
a45c9829
...
...
@@ -19,6 +19,7 @@ package scheduler
import
(
"fmt"
"math/rand"
"sort"
"strings"
"sync"
...
...
@@ -87,32 +88,20 @@ func (g *genericScheduler) Schedule(pod *api.Pod, nodeLister algorithm.NodeListe
return
g
.
selectHost
(
priorityList
)
}
// This method takes a prioritized list of nodes
, shuffles those with the highest scores to the
//
front of the list, and then picks one randomly from the nodes that had the highest score.
// This method takes a prioritized list of nodes
and sorts them in reverse order based on scores
//
and then picks one randomly from the nodes that had the highest score
func
(
g
*
genericScheduler
)
selectHost
(
priorityList
algorithm
.
HostPriorityList
)
(
string
,
error
)
{
if
len
(
priorityList
)
==
0
{
return
""
,
fmt
.
Errorf
(
"empty priorityList"
)
}
max
:=
priorityList
[
0
]
.
Score
n
:=
0
for
i
,
hostEntry
:=
range
priorityList
{
if
hostEntry
.
Score
<
max
{
continue
}
if
hostEntry
.
Score
>
max
{
max
=
hostEntry
.
Score
n
=
0
}
priorityList
[
i
],
priorityList
[
n
]
=
priorityList
[
n
],
priorityList
[
i
]
n
++
}
if
n
==
1
{
return
priorityList
[
0
]
.
Host
,
nil
}
sort
.
Sort
(
sort
.
Reverse
(
priorityList
))
hosts
:=
getBestHosts
(
priorityList
)
g
.
randomLock
.
Lock
()
defer
g
.
randomLock
.
Unlock
()
return
priorityList
[
g
.
random
.
Intn
(
n
)]
.
Host
,
nil
ix
:=
g
.
random
.
Int
()
%
len
(
hosts
)
return
hosts
[
ix
],
nil
}
// Filters the nodes to find the ones that fit based on the given predicate functions
...
...
@@ -190,6 +179,18 @@ func PrioritizeNodes(pod *api.Pod, podLister algorithm.PodLister, priorityConfig
return
result
,
nil
}
func
getBestHosts
(
list
algorithm
.
HostPriorityList
)
[]
string
{
result
:=
[]
string
{}
for
_
,
hostEntry
:=
range
list
{
if
hostEntry
.
Score
==
list
[
0
]
.
Score
{
result
=
append
(
result
,
hostEntry
.
Host
)
}
else
{
break
}
}
return
result
}
// EqualPriority is a prioritizer function that gives an equal weight of one to all nodes
func
EqualPriority
(
_
*
api
.
Pod
,
podLister
algorithm
.
PodLister
,
nodeLister
algorithm
.
NodeLister
)
(
algorithm
.
HostPriorityList
,
error
)
{
nodes
,
err
:=
nodeLister
.
List
()
...
...
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