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
ea943d82
Commit
ea943d82
authored
Sep 09, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate a bunch of priority functions to map-reduce framework
parent
6ffd30c2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
17 deletions
+14
-17
priorities.go
plugin/pkg/scheduler/algorithm/priorities/priorities.go
+0
-0
priorities_test.go
plugin/pkg/scheduler/algorithm/priorities/priorities_test.go
+8
-11
defaults.go
plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
+4
-4
plugins.go
plugin/pkg/scheduler/factory/plugins.go
+1
-1
generic_scheduler_test.go
plugin/pkg/scheduler/generic_scheduler_test.go
+1
-1
No files found.
plugin/pkg/scheduler/algorithm/priorities/priorities.go
View file @
ea943d82
This diff is collapsed.
Click to expand it.
plugin/pkg/scheduler/algorithm/priorities/priorities_test.go
View file @
ea943d82
...
@@ -295,8 +295,7 @@ func TestLeastRequested(t *testing.T) {
...
@@ -295,8 +295,7 @@ func TestLeastRequested(t *testing.T) {
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
nodeNameToInfo
:=
schedulercache
.
CreateNodeNameToInfoMap
(
test
.
pods
,
test
.
nodes
)
nodeNameToInfo
:=
schedulercache
.
CreateNodeNameToInfoMap
(
test
.
pods
,
test
.
nodes
)
lrp
:=
priorityFunction
(
LeastRequestedPriorityMap
,
nil
)
list
,
err
:=
priorityFunction
(
LeastRequestedPriorityMap
,
nil
)(
test
.
pod
,
nodeNameToInfo
,
test
.
nodes
)
list
,
err
:=
lrp
(
test
.
pod
,
nodeNameToInfo
,
test
.
nodes
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -451,7 +450,7 @@ func TestMostRequested(t *testing.T) {
...
@@ -451,7 +450,7 @@ func TestMostRequested(t *testing.T) {
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
nodeNameToInfo
:=
schedulercache
.
CreateNodeNameToInfoMap
(
test
.
pods
,
test
.
nodes
)
nodeNameToInfo
:=
schedulercache
.
CreateNodeNameToInfoMap
(
test
.
pods
,
test
.
nodes
)
list
,
err
:=
MostRequestedPriority
(
test
.
pod
,
nodeNameToInfo
,
test
.
nodes
)
list
,
err
:=
priorityFunction
(
MostRequestedPriorityMap
,
nil
)
(
test
.
pod
,
nodeNameToInfo
,
test
.
nodes
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -541,11 +540,8 @@ func TestNewNodeLabelPriority(t *testing.T) {
...
@@ -541,11 +540,8 @@ func TestNewNodeLabelPriority(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
prioritizer
:=
NodeLabelPrioritizer
{
nodeNameToInfo
:=
schedulercache
.
CreateNodeNameToInfoMap
(
nil
,
test
.
nodes
)
label
:
test
.
label
,
list
,
err
:=
priorityFunction
(
NewNodeLabelPriority
(
test
.
label
,
test
.
presence
))(
nil
,
nodeNameToInfo
,
test
.
nodes
)
presence
:
test
.
presence
,
}
list
,
err
:=
prioritizer
.
CalculateNodeLabelPriority
(
nil
,
map
[
string
]
*
schedulercache
.
NodeInfo
{},
test
.
nodes
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -784,7 +780,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
...
@@ -784,7 +780,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
nodeNameToInfo
:=
schedulercache
.
CreateNodeNameToInfoMap
(
test
.
pods
,
test
.
nodes
)
nodeNameToInfo
:=
schedulercache
.
CreateNodeNameToInfoMap
(
test
.
pods
,
test
.
nodes
)
list
,
err
:=
BalancedResourceAllocation
(
test
.
pod
,
nodeNameToInfo
,
test
.
nodes
)
list
,
err
:=
priorityFunction
(
BalancedResourceAllocationMap
,
nil
)
(
test
.
pod
,
nodeNameToInfo
,
test
.
nodes
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -928,7 +924,7 @@ func TestImageLocalityPriority(t *testing.T) {
...
@@ -928,7 +924,7 @@ func TestImageLocalityPriority(t *testing.T) {
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
nodeNameToInfo
:=
schedulercache
.
CreateNodeNameToInfoMap
(
test
.
pods
,
test
.
nodes
)
nodeNameToInfo
:=
schedulercache
.
CreateNodeNameToInfoMap
(
test
.
pods
,
test
.
nodes
)
list
,
err
:=
ImageLocalityPriority
(
test
.
pod
,
nodeNameToInfo
,
test
.
nodes
)
list
,
err
:=
priorityFunction
(
ImageLocalityPriorityMap
,
nil
)
(
test
.
pod
,
nodeNameToInfo
,
test
.
nodes
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
...
@@ -1152,7 +1148,8 @@ func TestNodePreferAvoidPriority(t *testing.T) {
...
@@ -1152,7 +1148,8 @@ func TestNodePreferAvoidPriority(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
list
,
err
:=
CalculateNodePreferAvoidPodsPriority
(
test
.
pod
,
map
[
string
]
*
schedulercache
.
NodeInfo
{},
test
.
nodes
)
nodeNameToInfo
:=
schedulercache
.
CreateNodeNameToInfoMap
(
nil
,
test
.
nodes
)
list
,
err
:=
priorityFunction
(
CalculateNodePreferAvoidPodsPriorityMap
,
nil
)(
test
.
pod
,
nodeNameToInfo
,
test
.
nodes
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
...
...
plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
View file @
ea943d82
...
@@ -82,7 +82,7 @@ func init() {
...
@@ -82,7 +82,7 @@ func init() {
// ImageLocalityPriority prioritizes nodes based on locality of images requested by a pod. Nodes with larger size
// ImageLocalityPriority prioritizes nodes based on locality of images requested by a pod. Nodes with larger size
// of already-installed packages required by the pod will be preferred over nodes with no already-installed
// of already-installed packages required by the pod will be preferred over nodes with no already-installed
// packages required by the pod or a small total size of already-installed packages required by the pod.
// packages required by the pod or a small total size of already-installed packages required by the pod.
factory
.
RegisterPriorityFunction
(
"ImageLocalityPriority"
,
priorities
.
ImageLocalityPriority
,
1
)
factory
.
RegisterPriorityFunction
2
(
"ImageLocalityPriority"
,
priorities
.
ImageLocalityPriorityMap
,
nil
,
1
)
// Fit is defined based on the absence of port conflicts.
// Fit is defined based on the absence of port conflicts.
// This predicate is actually a default predicate, because it is invoked from
// This predicate is actually a default predicate, because it is invoked from
// predicates.GeneralPredicates()
// predicates.GeneralPredicates()
...
@@ -98,7 +98,7 @@ func init() {
...
@@ -98,7 +98,7 @@ func init() {
// Fit is determined by node selector query.
// Fit is determined by node selector query.
factory
.
RegisterFitPredicate
(
"MatchNodeSelector"
,
predicates
.
PodSelectorMatches
)
factory
.
RegisterFitPredicate
(
"MatchNodeSelector"
,
predicates
.
PodSelectorMatches
)
// Optional, cluster-autoscaler friendly priority function - give used nodes higher priority.
// Optional, cluster-autoscaler friendly priority function - give used nodes higher priority.
factory
.
RegisterPriorityFunction
(
"MostRequestedPriority"
,
priorities
.
MostRequestedPriority
,
1
)
factory
.
RegisterPriorityFunction
2
(
"MostRequestedPriority"
,
priorities
.
MostRequestedPriorityMap
,
nil
,
1
)
}
}
func
replace
(
set
sets
.
String
,
replaceWhat
,
replaceWith
string
)
sets
.
String
{
func
replace
(
set
sets
.
String
,
replaceWhat
,
replaceWith
string
)
sets
.
String
{
...
@@ -167,7 +167,7 @@ func defaultPriorities() sets.String {
...
@@ -167,7 +167,7 @@ func defaultPriorities() sets.String {
// Prioritize nodes by least requested utilization.
// Prioritize nodes by least requested utilization.
factory
.
RegisterPriorityFunction2
(
"LeastRequestedPriority"
,
priorities
.
LeastRequestedPriorityMap
,
nil
,
1
),
factory
.
RegisterPriorityFunction2
(
"LeastRequestedPriority"
,
priorities
.
LeastRequestedPriorityMap
,
nil
,
1
),
// Prioritizes nodes to help achieve balanced resource usage
// Prioritizes nodes to help achieve balanced resource usage
factory
.
RegisterPriorityFunction
(
"BalancedResourceAllocation"
,
priorities
.
BalancedResourceAllocation
,
1
),
factory
.
RegisterPriorityFunction
2
(
"BalancedResourceAllocation"
,
priorities
.
BalancedResourceAllocationMap
,
nil
,
1
),
// spreads pods by minimizing the number of pods (belonging to the same service or replication controller) on the same node.
// spreads pods by minimizing the number of pods (belonging to the same service or replication controller) on the same node.
factory
.
RegisterPriorityConfigFactory
(
factory
.
RegisterPriorityConfigFactory
(
"SelectorSpreadPriority"
,
"SelectorSpreadPriority"
,
...
@@ -180,7 +180,7 @@ func defaultPriorities() sets.String {
...
@@ -180,7 +180,7 @@ func defaultPriorities() sets.String {
),
),
// Set this weight large enough to override all other priority functions.
// Set this weight large enough to override all other priority functions.
// TODO: Figure out a better way to do this, maybe at same time as fixing #24720.
// TODO: Figure out a better way to do this, maybe at same time as fixing #24720.
factory
.
RegisterPriorityFunction
(
"NodePreferAvoidPodsPriority"
,
priorities
.
CalculateNodePreferAvoidPodsPriority
,
10000
),
factory
.
RegisterPriorityFunction
2
(
"NodePreferAvoidPodsPriority"
,
priorities
.
CalculateNodePreferAvoidPodsPriorityMap
,
nil
,
10000
),
factory
.
RegisterPriorityFunction
(
"NodeAffinityPriority"
,
priorities
.
CalculateNodeAffinityPriority
,
1
),
factory
.
RegisterPriorityFunction
(
"NodeAffinityPriority"
,
priorities
.
CalculateNodeAffinityPriority
,
1
),
factory
.
RegisterPriorityFunction
(
"TaintTolerationPriority"
,
priorities
.
ComputeTaintTolerationPriority
,
1
),
factory
.
RegisterPriorityFunction
(
"TaintTolerationPriority"
,
priorities
.
ComputeTaintTolerationPriority
,
1
),
// pods should be placed in the same topological domain (e.g. same node, same rack, same zone, same power domain, etc.)
// pods should be placed in the same topological domain (e.g. same node, same rack, same zone, same power domain, etc.)
...
...
plugin/pkg/scheduler/factory/plugins.go
View file @
ea943d82
...
@@ -206,7 +206,7 @@ func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string {
...
@@ -206,7 +206,7 @@ func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string {
}
}
}
else
if
policy
.
Argument
.
LabelPreference
!=
nil
{
}
else
if
policy
.
Argument
.
LabelPreference
!=
nil
{
pcf
=
&
PriorityConfigFactory
{
pcf
=
&
PriorityConfigFactory
{
Function
:
func
(
args
PluginFactoryArgs
)
algorithm
.
PriorityFunction
{
MapReduceFunction
:
func
(
args
PluginFactoryArgs
)
(
algorithm
.
PriorityMapFunction
,
algorithm
.
PriorityReduceFunction
)
{
return
priorities
.
NewNodeLabelPriority
(
return
priorities
.
NewNodeLabelPriority
(
policy
.
Argument
.
LabelPreference
.
Label
,
policy
.
Argument
.
LabelPreference
.
Label
,
policy
.
Argument
.
LabelPreference
.
Presence
,
policy
.
Argument
.
LabelPreference
.
Presence
,
...
...
plugin/pkg/scheduler/generic_scheduler_test.go
View file @
ea943d82
...
@@ -489,7 +489,7 @@ func TestZeroRequest(t *testing.T) {
...
@@ -489,7 +489,7 @@ func TestZeroRequest(t *testing.T) {
// to test what's actually in production.
// to test what's actually in production.
priorityConfigs
:=
[]
algorithm
.
PriorityConfig
{
priorityConfigs
:=
[]
algorithm
.
PriorityConfig
{
{
Map
:
algorithmpriorities
.
LeastRequestedPriorityMap
,
Weight
:
1
},
{
Map
:
algorithmpriorities
.
LeastRequestedPriorityMap
,
Weight
:
1
},
{
Function
:
algorithmpriorities
.
BalancedResourceAllocation
,
Weight
:
1
},
{
Map
:
algorithmpriorities
.
BalancedResourceAllocationMap
,
Weight
:
1
},
{
{
Function
:
algorithmpriorities
.
NewSelectorSpreadPriority
(
Function
:
algorithmpriorities
.
NewSelectorSpreadPriority
(
algorithm
.
FakePodLister
(
test
.
pods
),
algorithm
.
FakePodLister
(
test
.
pods
),
...
...
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