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
97458787
Commit
97458787
authored
Jul 13, 2016
by
Wojciech Tyczynski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ForgetPod to SchedulerCache
parent
89be0393
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
10 deletions
+51
-10
scheduler.go
plugin/pkg/scheduler/scheduler.go
+3
-0
cache.go
plugin/pkg/scheduler/schedulercache/cache.go
+24
-0
cache_test.go
plugin/pkg/scheduler/schedulercache/cache_test.go
+9
-0
interface.go
plugin/pkg/scheduler/schedulercache/interface.go
+10
-7
fake_cache.go
plugin/pkg/scheduler/testing/fake_cache.go
+2
-0
pods_to_cache.go
plugin/pkg/scheduler/testing/pods_to_cache.go
+3
-3
No files found.
plugin/pkg/scheduler/scheduler.go
View file @
97458787
...
...
@@ -140,6 +140,9 @@ func (s *Scheduler) scheduleOne() {
err
:=
s
.
config
.
Binder
.
Bind
(
b
)
if
err
!=
nil
{
glog
.
V
(
1
)
.
Infof
(
"Failed to bind pod: %v/%v"
,
pod
.
Namespace
,
pod
.
Name
)
if
err
:=
s
.
config
.
SchedulerCache
.
ForgetPod
(
&
assumed
);
err
!=
nil
{
glog
.
Errorf
(
"scheduler cache ForgetPod failed: %v"
,
err
)
}
s
.
config
.
Error
(
pod
,
err
)
s
.
config
.
Recorder
.
Eventf
(
pod
,
api
.
EventTypeNormal
,
"FailedScheduling"
,
"Binding rejected: %v"
,
err
)
s
.
config
.
PodConditionUpdater
.
Update
(
pod
,
&
api
.
PodCondition
{
...
...
plugin/pkg/scheduler/schedulercache/cache.go
View file @
97458787
...
...
@@ -132,6 +132,30 @@ func (cache *schedulerCache) assumePod(pod *api.Pod, now time.Time) error {
return
nil
}
func
(
cache
*
schedulerCache
)
ForgetPod
(
pod
*
api
.
Pod
)
error
{
key
,
err
:=
getPodKey
(
pod
)
if
err
!=
nil
{
return
err
}
cache
.
mu
.
Lock
()
defer
cache
.
mu
.
Unlock
()
_
,
ok
:=
cache
.
podStates
[
key
]
switch
{
// Only assumed pod can be forgotten.
case
ok
&&
cache
.
assumedPods
[
key
]
:
err
:=
cache
.
removePod
(
pod
)
if
err
!=
nil
{
return
err
}
delete
(
cache
.
podStates
,
key
)
default
:
return
fmt
.
Errorf
(
"pod state wasn't assumed but get forgotten. Pod key: %v"
,
key
)
}
return
nil
}
func
(
cache
*
schedulerCache
)
AddPod
(
pod
*
api
.
Pod
)
error
{
key
,
err
:=
getPodKey
(
pod
)
if
err
!=
nil
{
...
...
plugin/pkg/scheduler/schedulercache/cache_test.go
View file @
97458787
...
...
@@ -103,6 +103,15 @@ func TestAssumePodScheduled(t *testing.T) {
}
n
:=
cache
.
nodes
[
nodeName
]
deepEqualWithoutGeneration
(
t
,
i
,
n
,
tt
.
wNodeInfo
)
for
_
,
pod
:=
range
tt
.
pods
{
if
err
:=
cache
.
ForgetPod
(
pod
);
err
!=
nil
{
t
.
Fatalf
(
"ForgetPod failed: %v"
,
err
)
}
}
if
cache
.
nodes
[
nodeName
]
!=
nil
{
t
.
Errorf
(
"NodeInfo should be cleaned for %s"
,
nodeName
)
}
}
}
...
...
plugin/pkg/scheduler/schedulercache/interface.go
View file @
97458787
...
...
@@ -36,13 +36,13 @@ import (
// | | | | Update
// + Assume Add v v |
//Initial +--------> Assumed +------------+---> Added <--+
//
+
| +
//
|
| |
//
|
Add | | Remove
//
|
| |
//
|
+ |
//
+--
-----------> Expired +----> Deleted
//
Expire
//
^ + +
| +
//
| | |
| |
//
| | |
Add | | Remove
//
| | |
| |
//
| | |
+ |
//
+----------------+ +
-----------> Expired +----> Deleted
//
Forget
Expire
//
//
// Note that an assumed pod can expire, because if we haven't received Add event notifying us
...
...
@@ -61,6 +61,9 @@ type Cache interface {
// After expiration, its information would be subtracted.
AssumePod
(
pod
*
api
.
Pod
)
error
// ForgetPod removes an assumed pod from cache.
ForgetPod
(
pod
*
api
.
Pod
)
error
// AddPod either confirms a pod if it's assumed, or adds it back if it's expired.
// If added back, the pod's information would be added again.
AddPod
(
pod
*
api
.
Pod
)
error
...
...
plugin/pkg/scheduler/testing/fake_cache.go
View file @
97458787
...
...
@@ -32,6 +32,8 @@ func (f *FakeCache) AssumePod(pod *api.Pod) error {
return
nil
}
func
(
f
*
FakeCache
)
ForgetPod
(
pod
*
api
.
Pod
)
error
{
return
nil
}
func
(
f
*
FakeCache
)
AddPod
(
pod
*
api
.
Pod
)
error
{
return
nil
}
func
(
f
*
FakeCache
)
UpdatePod
(
oldPod
,
newPod
*
api
.
Pod
)
error
{
return
nil
}
...
...
plugin/pkg/scheduler/testing/pods_to_cache.go
View file @
97458787
...
...
@@ -25,9 +25,9 @@ import (
// PodsToCache is used for testing
type
PodsToCache
[]
*
api
.
Pod
func
(
p
PodsToCache
)
AssumePod
(
pod
*
api
.
Pod
)
error
{
return
nil
}
func
(
p
PodsToCache
)
AssumePod
(
pod
*
api
.
Pod
)
error
{
return
nil
}
func
(
p
PodsToCache
)
ForgetPod
(
pod
*
api
.
Pod
)
error
{
return
nil
}
func
(
p
PodsToCache
)
AddPod
(
pod
*
api
.
Pod
)
error
{
return
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