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
97634c7f
Commit
97634c7f
authored
Jun 10, 2015
by
Brendan Burns
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix the scheduler to ignore terminated pods.
parent
bdeb4f31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
76 additions
and
1 deletion
+76
-1
predicates.go
plugin/pkg/scheduler/algorithm/predicates/predicates.go
+15
-0
generic_scheduler_test.go
plugin/pkg/scheduler/generic_scheduler_test.go
+61
-1
No files found.
plugin/pkg/scheduler/algorithm/predicates/predicates.go
View file @
97634c7f
...
@@ -360,6 +360,20 @@ func getUsedPorts(pods ...*api.Pod) map[int]bool {
...
@@ -360,6 +360,20 @@ func getUsedPorts(pods ...*api.Pod) map[int]bool {
return
ports
return
ports
}
}
func
filterNonRunningPods
(
pods
[]
*
api
.
Pod
)
[]
*
api
.
Pod
{
if
len
(
pods
)
==
0
{
return
pods
}
result
:=
[]
*
api
.
Pod
{}
for
_
,
pod
:=
range
pods
{
if
pod
.
Status
.
Phase
==
api
.
PodSucceeded
||
pod
.
Status
.
Phase
==
api
.
PodFailed
{
continue
}
result
=
append
(
result
,
pod
)
}
return
result
}
// MapPodsToMachines obtains a list of pods and pivots that list into a map where the keys are host names
// MapPodsToMachines obtains a list of pods and pivots that list into a map where the keys are host names
// and the values are the list of pods running on that host.
// and the values are the list of pods running on that host.
func
MapPodsToMachines
(
lister
algorithm
.
PodLister
)
(
map
[
string
][]
*
api
.
Pod
,
error
)
{
func
MapPodsToMachines
(
lister
algorithm
.
PodLister
)
(
map
[
string
][]
*
api
.
Pod
,
error
)
{
...
@@ -369,6 +383,7 @@ func MapPodsToMachines(lister algorithm.PodLister) (map[string][]*api.Pod, error
...
@@ -369,6 +383,7 @@ func MapPodsToMachines(lister algorithm.PodLister) (map[string][]*api.Pod, error
if
err
!=
nil
{
if
err
!=
nil
{
return
map
[
string
][]
*
api
.
Pod
{},
err
return
map
[
string
][]
*
api
.
Pod
{},
err
}
}
pods
=
filterNonRunningPods
(
pods
)
for
_
,
scheduledPod
:=
range
pods
{
for
_
,
scheduledPod
:=
range
pods
{
host
:=
scheduledPod
.
Spec
.
NodeName
host
:=
scheduledPod
.
Spec
.
NodeName
machineToPods
[
host
]
=
append
(
machineToPods
[
host
],
scheduledPod
)
machineToPods
[
host
]
=
append
(
machineToPods
[
host
],
scheduledPod
)
...
...
plugin/pkg/scheduler/generic_scheduler_test.go
View file @
97634c7f
...
@@ -40,6 +40,10 @@ func matchesPredicate(pod *api.Pod, existingPods []*api.Pod, node string) (bool,
...
@@ -40,6 +40,10 @@ func matchesPredicate(pod *api.Pod, existingPods []*api.Pod, node string) (bool,
return
pod
.
Name
==
node
,
nil
return
pod
.
Name
==
node
,
nil
}
}
func
hasNoPodsPredicate
(
pod
*
api
.
Pod
,
existingPods
[]
*
api
.
Pod
,
node
string
)
(
bool
,
error
)
{
return
len
(
existingPods
)
==
0
,
nil
}
func
numericPriority
(
pod
*
api
.
Pod
,
podLister
algorithm
.
PodLister
,
minionLister
algorithm
.
MinionLister
)
(
algorithm
.
HostPriorityList
,
error
)
{
func
numericPriority
(
pod
*
api
.
Pod
,
podLister
algorithm
.
PodLister
,
minionLister
algorithm
.
MinionLister
)
(
algorithm
.
HostPriorityList
,
error
)
{
nodes
,
err
:=
minionLister
.
List
()
nodes
,
err
:=
minionLister
.
List
()
result
:=
[]
algorithm
.
HostPriority
{}
result
:=
[]
algorithm
.
HostPriority
{}
...
@@ -166,6 +170,7 @@ func TestGenericScheduler(t *testing.T) {
...
@@ -166,6 +170,7 @@ func TestGenericScheduler(t *testing.T) {
prioritizers
[]
algorithm
.
PriorityConfig
prioritizers
[]
algorithm
.
PriorityConfig
nodes
[]
string
nodes
[]
string
pod
*
api
.
Pod
pod
*
api
.
Pod
pods
[]
*
api
.
Pod
expectedHost
string
expectedHost
string
expectsErr
bool
expectsErr
bool
}{
}{
...
@@ -223,11 +228,66 @@ func TestGenericScheduler(t *testing.T) {
...
@@ -223,11 +228,66 @@ func TestGenericScheduler(t *testing.T) {
expectsErr
:
true
,
expectsErr
:
true
,
name
:
"test 7"
,
name
:
"test 7"
,
},
},
{
predicates
:
map
[
string
]
algorithm
.
FitPredicate
{
"nopods"
:
hasNoPodsPredicate
,
"matches"
:
matchesPredicate
,
},
pods
:
[]
*
api
.
Pod
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"2"
},
Spec
:
api
.
PodSpec
{
NodeName
:
"2"
,
},
Status
:
api
.
PodStatus
{
Phase
:
api
.
PodRunning
,
},
},
},
pod
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"2"
}},
prioritizers
:
[]
algorithm
.
PriorityConfig
{{
Function
:
numericPriority
,
Weight
:
1
}},
nodes
:
[]
string
{
"1"
,
"2"
},
expectsErr
:
true
,
name
:
"test 8"
,
},
{
predicates
:
map
[
string
]
algorithm
.
FitPredicate
{
"nopods"
:
hasNoPodsPredicate
,
"matches"
:
matchesPredicate
,
},
pods
:
[]
*
api
.
Pod
{
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"2"
},
Spec
:
api
.
PodSpec
{
NodeName
:
"2"
,
},
Status
:
api
.
PodStatus
{
Phase
:
api
.
PodFailed
,
},
},
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"3"
},
Spec
:
api
.
PodSpec
{
NodeName
:
"2"
,
},
Status
:
api
.
PodStatus
{
Phase
:
api
.
PodSucceeded
,
},
},
},
pod
:
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
"2"
}},
prioritizers
:
[]
algorithm
.
PriorityConfig
{{
Function
:
numericPriority
,
Weight
:
1
}},
nodes
:
[]
string
{
"1"
,
"2"
},
expectedHost
:
"2"
,
name
:
"test 9"
,
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
random
:=
rand
.
New
(
rand
.
NewSource
(
0
))
random
:=
rand
.
New
(
rand
.
NewSource
(
0
))
scheduler
:=
NewGenericScheduler
(
test
.
predicates
,
test
.
prioritizers
,
algorithm
.
FakePodLister
(
[]
*
api
.
Pod
{}
),
random
)
scheduler
:=
NewGenericScheduler
(
test
.
predicates
,
test
.
prioritizers
,
algorithm
.
FakePodLister
(
test
.
pods
),
random
)
machine
,
err
:=
scheduler
.
Schedule
(
test
.
pod
,
algorithm
.
FakeMinionLister
(
makeNodeList
(
test
.
nodes
)))
machine
,
err
:=
scheduler
.
Schedule
(
test
.
pod
,
algorithm
.
FakeMinionLister
(
makeNodeList
(
test
.
nodes
)))
if
test
.
expectsErr
{
if
test
.
expectsErr
{
if
err
==
nil
{
if
err
==
nil
{
...
...
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