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
8fa59aa9
Commit
8fa59aa9
authored
Nov 19, 2017
by
Gavin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
address review comments
parent
bed435de
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
22 deletions
+18
-22
selector_spreading.go
.../pkg/scheduler/algorithm/priorities/selector_spreading.go
+18
-20
selector_spreading_test.go
...scheduler/algorithm/priorities/selector_spreading_test.go
+0
-1
defaults.go
plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
+0
-1
No files found.
plugin/pkg/scheduler/algorithm/priorities/selector_spreading.go
View file @
8fa59aa9
...
@@ -54,11 +54,13 @@ func NewSelectorSpreadPriority(
...
@@ -54,11 +54,13 @@ func NewSelectorSpreadPriority(
return
selectorSpread
.
CalculateSpreadPriorityMap
,
selectorSpread
.
CalculateSpreadPriorityReduce
return
selectorSpread
.
CalculateSpreadPriorityMap
,
selectorSpread
.
CalculateSpreadPriorityReduce
}
}
// CalculateSpreadPriorityMap spreads pods across hosts, considering pods belonging to the same service or replication controller.
// CalculateSpreadPriorityMap spreads pods across hosts, considering pods
// When a pod is scheduled, it looks for services, RCs or RSs that match the pod, then finds existing pods that match those selectors.
// belonging to the same service,RC,RS or StatefulSet.
// When a pod is scheduled, it looks for services, RCs,RSs and StatefulSets that match the pod,
// then finds existing pods that match those selectors.
// It favors nodes that have fewer existing matching pods.
// It favors nodes that have fewer existing matching pods.
// i.e. it pushes the scheduler towards a node where there's the smallest number of
// i.e. it pushes the scheduler towards a node where there's the smallest number of
// pods which match the same service, RC
or RS
selectors as the pod being scheduled.
// pods which match the same service, RC
,RSs or StatefulSets
selectors as the pod being scheduled.
func
(
s
*
SelectorSpread
)
CalculateSpreadPriorityMap
(
pod
*
v1
.
Pod
,
meta
interface
{},
nodeInfo
*
schedulercache
.
NodeInfo
)
(
schedulerapi
.
HostPriority
,
error
)
{
func
(
s
*
SelectorSpread
)
CalculateSpreadPriorityMap
(
pod
*
v1
.
Pod
,
meta
interface
{},
nodeInfo
*
schedulercache
.
NodeInfo
)
(
schedulerapi
.
HostPriority
,
error
)
{
var
selectors
[]
labels
.
Selector
var
selectors
[]
labels
.
Selector
node
:=
nodeInfo
.
Node
()
node
:=
nodeInfo
.
Node
()
...
@@ -80,7 +82,7 @@ func (s *SelectorSpread) CalculateSpreadPriorityMap(pod *v1.Pod, meta interface{
...
@@ -80,7 +82,7 @@ func (s *SelectorSpread) CalculateSpreadPriorityMap(pod *v1.Pod, meta interface{
},
nil
},
nil
}
}
count
:=
float64
(
0
)
count
:=
int
(
0
)
for
_
,
nodePod
:=
range
nodeInfo
.
Pods
()
{
for
_
,
nodePod
:=
range
nodeInfo
.
Pods
()
{
if
pod
.
Namespace
!=
nodePod
.
Namespace
{
if
pod
.
Namespace
!=
nodePod
.
Namespace
{
continue
continue
...
@@ -110,22 +112,15 @@ func (s *SelectorSpread) CalculateSpreadPriorityMap(pod *v1.Pod, meta interface{
...
@@ -110,22 +112,15 @@ func (s *SelectorSpread) CalculateSpreadPriorityMap(pod *v1.Pod, meta interface{
},
nil
},
nil
}
}
// CalculateSpreadPriorityReduce calculates the source of each node based on the number of existing matching pods on the node
// CalculateSpreadPriorityReduce calculates the source of each node
// where zone information is included on the nodes, it favors nodes in zones with fewer existing matching pods.
// based on the number of existing matching pods on the node
// where zone information is included on the nodes, it favors nodes
// in zones with fewer existing matching pods.
func
(
s
*
SelectorSpread
)
CalculateSpreadPriorityReduce
(
pod
*
v1
.
Pod
,
meta
interface
{},
nodeNameToInfo
map
[
string
]
*
schedulercache
.
NodeInfo
,
result
schedulerapi
.
HostPriorityList
)
error
{
func
(
s
*
SelectorSpread
)
CalculateSpreadPriorityReduce
(
pod
*
v1
.
Pod
,
meta
interface
{},
nodeNameToInfo
map
[
string
]
*
schedulercache
.
NodeInfo
,
result
schedulerapi
.
HostPriorityList
)
error
{
var
selectors
[]
labels
.
Selector
countsByZone
:=
make
(
map
[
string
]
int
,
10
)
countsByZone
:=
make
(
map
[
string
]
int
,
10
)
maxCountByZone
:=
int
(
0
)
maxCountByZone
:=
int
(
0
)
maxCountByNodeName
:=
int
(
0
)
maxCountByNodeName
:=
int
(
0
)
priorityMeta
,
ok
:=
meta
.
(
*
priorityMetadata
)
if
ok
{
selectors
=
priorityMeta
.
podSelectors
}
else
{
selectors
=
getSelectors
(
pod
,
s
.
serviceLister
,
s
.
controllerLister
,
s
.
replicaSetLister
,
s
.
statefulSetLister
)
}
if
len
(
selectors
)
>
0
{
for
i
:=
range
result
{
for
i
:=
range
result
{
if
result
[
i
]
.
Score
>
maxCountByNodeName
{
if
result
[
i
]
.
Score
>
maxCountByNodeName
{
maxCountByNodeName
=
result
[
i
]
.
Score
maxCountByNodeName
=
result
[
i
]
.
Score
...
@@ -136,7 +131,6 @@ func (s *SelectorSpread) CalculateSpreadPriorityReduce(pod *v1.Pod, meta interfa
...
@@ -136,7 +131,6 @@ func (s *SelectorSpread) CalculateSpreadPriorityReduce(pod *v1.Pod, meta interfa
}
}
countsByZone
[
zoneId
]
+=
result
[
i
]
.
Score
countsByZone
[
zoneId
]
+=
result
[
i
]
.
Score
}
}
}
for
zoneId
:=
range
countsByZone
{
for
zoneId
:=
range
countsByZone
{
if
countsByZone
[
zoneId
]
>
maxCountByZone
{
if
countsByZone
[
zoneId
]
>
maxCountByZone
{
...
@@ -146,19 +140,23 @@ func (s *SelectorSpread) CalculateSpreadPriorityReduce(pod *v1.Pod, meta interfa
...
@@ -146,19 +140,23 @@ func (s *SelectorSpread) CalculateSpreadPriorityReduce(pod *v1.Pod, meta interfa
haveZones
:=
len
(
countsByZone
)
!=
0
haveZones
:=
len
(
countsByZone
)
!=
0
maxCountByNodeNameFloat64
:=
float64
(
maxCountByNodeName
)
maxCountByZoneFloat64
:=
float64
(
maxCountByZone
)
MaxPriorityFloat64
:=
float64
(
schedulerapi
.
MaxPriority
)
for
i
:=
range
result
{
for
i
:=
range
result
{
// initializing to the default/max node score of maxPriority
// initializing to the default/max node score of maxPriority
fScore
:=
float64
(
schedulerapi
.
MaxPriority
)
fScore
:=
MaxPriorityFloat64
if
maxCountByNodeName
>
0
{
if
maxCountByNodeName
>
0
{
fScore
=
float64
(
schedulerapi
.
MaxPriority
)
*
(
float64
(
maxCountByNodeName
-
result
[
i
]
.
Score
)
/
float64
(
maxCountByNodeName
)
)
fScore
=
MaxPriorityFloat64
*
(
float64
(
maxCountByNodeName
-
result
[
i
]
.
Score
)
/
maxCountByNodeNameFloat64
)
}
}
// If there is zone information present, incorporate it
// If there is zone information present, incorporate it
if
haveZones
{
if
haveZones
{
zoneId
:=
utilnode
.
GetZoneKey
(
nodeNameToInfo
[
result
[
i
]
.
Host
]
.
Node
())
zoneId
:=
utilnode
.
GetZoneKey
(
nodeNameToInfo
[
result
[
i
]
.
Host
]
.
Node
())
if
zoneId
!=
""
{
if
zoneId
!=
""
{
zoneScore
:=
float64
(
schedulerapi
.
MaxPriority
)
zoneScore
:=
MaxPriorityFloat64
if
maxCountByZone
>
0
{
if
maxCountByZone
>
0
{
zoneScore
=
float64
(
schedulerapi
.
MaxPriority
)
*
(
float64
(
maxCountByZone
-
countsByZone
[
zoneId
])
/
float64
(
maxCountByZone
)
)
zoneScore
=
MaxPriorityFloat64
*
(
float64
(
maxCountByZone
-
countsByZone
[
zoneId
])
/
maxCountByZoneFloat64
)
}
}
fScore
=
(
fScore
*
(
1.0
-
zoneWeighting
))
+
(
zoneWeighting
*
zoneScore
)
fScore
=
(
fScore
*
(
1.0
-
zoneWeighting
))
+
(
zoneWeighting
*
zoneScore
)
}
}
...
...
plugin/pkg/scheduler/algorithm/priorities/selector_spreading_test.go
View file @
8fa59aa9
...
@@ -553,7 +553,6 @@ func TestZoneSelectorSpreadPriority(t *testing.T) {
...
@@ -553,7 +553,6 @@ func TestZoneSelectorSpreadPriority(t *testing.T) {
buildPod
(
nodeMachine1Zone2
,
labels1
,
controllerRef
(
"ReplicationController"
,
"name"
,
"abc123"
)),
buildPod
(
nodeMachine1Zone2
,
labels1
,
controllerRef
(
"ReplicationController"
,
"name"
,
"abc123"
)),
buildPod
(
nodeMachine1Zone3
,
labels1
,
controllerRef
(
"ReplicationController"
,
"name"
,
"abc123"
)),
buildPod
(
nodeMachine1Zone3
,
labels1
,
controllerRef
(
"ReplicationController"
,
"name"
,
"abc123"
)),
},
},
//nodes: []string{nodeMachine1Zone3, nodeMachine1Zone2, nodeMachine1Zone3},
rcs
:
[]
*
v1
.
ReplicationController
{{
Spec
:
v1
.
ReplicationControllerSpec
{
Selector
:
labels1
}}},
rcs
:
[]
*
v1
.
ReplicationController
{{
Spec
:
v1
.
ReplicationControllerSpec
{
Selector
:
labels1
}}},
expectedList
:
[]
schedulerapi
.
HostPriority
{
expectedList
:
[]
schedulerapi
.
HostPriority
{
// Note that because we put two pods on the same node (nodeMachine1Zone3),
// Note that because we put two pods on the same node (nodeMachine1Zone3),
...
...
plugin/pkg/scheduler/algorithmprovider/defaults/defaults.go
View file @
8fa59aa9
...
@@ -218,7 +218,6 @@ func defaultPriorities() sets.String {
...
@@ -218,7 +218,6 @@ func defaultPriorities() sets.String {
Weight
:
1
,
Weight
:
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.)
// as some other pods, or, conversely, should not be placed in the same topological domain as some other pods.
// as some other pods, or, conversely, should not be placed in the same topological domain as some other pods.
factory
.
RegisterPriorityConfigFactory
(
factory
.
RegisterPriorityConfigFactory
(
...
...
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