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
d584bf4d
Commit
d584bf4d
authored
Aug 02, 2017
by
Julia Evans
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix incorrect call to 'bind' in scheduler
parent
508ccc40
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
9 deletions
+24
-9
scheduler.go
plugin/pkg/scheduler/scheduler.go
+9
-7
scheduler_test.go
plugin/pkg/scheduler/scheduler_test.go
+10
-1
fake_cache.go
plugin/pkg/scheduler/testing/fake_cache.go
+5
-1
No files found.
plugin/pkg/scheduler/scheduler.go
View file @
d584bf4d
...
@@ -185,14 +185,14 @@ func (sched *Scheduler) schedule(pod *v1.Pod) (string, error) {
...
@@ -185,14 +185,14 @@ func (sched *Scheduler) schedule(pod *v1.Pod) (string, error) {
}
}
// assume signals to the cache that a pod is already in the cache, so that binding can be asnychronous.
// assume signals to the cache that a pod is already in the cache, so that binding can be asnychronous.
func
(
sched
*
Scheduler
)
assume
(
pod
*
v1
.
Pod
,
host
string
)
error
{
// assume modifies `assumed`.
func
(
sched
*
Scheduler
)
assume
(
assumed
*
v1
.
Pod
,
host
string
)
error
{
// Optimistically assume that the binding will succeed and send it to apiserver
// Optimistically assume that the binding will succeed and send it to apiserver
// in the background.
// in the background.
// If the binding fails, scheduler will release resources allocated to assumed pod
// If the binding fails, scheduler will release resources allocated to assumed pod
// immediately.
// immediately.
assumed
:=
*
pod
assumed
.
Spec
.
NodeName
=
host
assumed
.
Spec
.
NodeName
=
host
if
err
:=
sched
.
config
.
SchedulerCache
.
AssumePod
(
&
assumed
);
err
!=
nil
{
if
err
:=
sched
.
config
.
SchedulerCache
.
AssumePod
(
assumed
);
err
!=
nil
{
glog
.
Errorf
(
"scheduler cache AssumePod failed: %v"
,
err
)
glog
.
Errorf
(
"scheduler cache AssumePod failed: %v"
,
err
)
// TODO: This means that a given pod is already in cache (which means it
// TODO: This means that a given pod is already in cache (which means it
// is either assumed or already added). This is most probably result of a
// is either assumed or already added). This is most probably result of a
...
@@ -207,7 +207,7 @@ func (sched *Scheduler) assume(pod *v1.Pod, host string) error {
...
@@ -207,7 +207,7 @@ func (sched *Scheduler) assume(pod *v1.Pod, host string) error {
// predicates in equivalence cache.
// predicates in equivalence cache.
// If the binding fails, these invalidated item will not break anything.
// If the binding fails, these invalidated item will not break anything.
if
sched
.
config
.
Ecache
!=
nil
{
if
sched
.
config
.
Ecache
!=
nil
{
sched
.
config
.
Ecache
.
InvalidateCachedPredicateItemForPodAdd
(
po
d
,
host
)
sched
.
config
.
Ecache
.
InvalidateCachedPredicateItemForPodAdd
(
assume
d
,
host
)
}
}
return
nil
return
nil
}
}
...
@@ -264,15 +264,17 @@ func (sched *Scheduler) scheduleOne() {
...
@@ -264,15 +264,17 @@ func (sched *Scheduler) scheduleOne() {
// Tell the cache to assume that a pod now is running on a given node, even though it hasn't been bound yet.
// Tell the cache to assume that a pod now is running on a given node, even though it hasn't been bound yet.
// This allows us to keep scheduling without waiting on binding to occur.
// This allows us to keep scheduling without waiting on binding to occur.
err
=
sched
.
assume
(
pod
,
suggestedHost
)
assumedPod
:=
*
pod
// assume modifies `assumedPod` by setting NodeName=suggestedHost
err
=
sched
.
assume
(
&
assumedPod
,
suggestedHost
)
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
// bind the pod to its host asynchronously (we can do this b/c of the assumption step above).
// bind the pod to its host asynchronously (we can do this b/c of the assumption step above).
go
func
()
{
go
func
()
{
err
:=
sched
.
bind
(
p
od
,
&
v1
.
Binding
{
err
:=
sched
.
bind
(
&
assumedP
od
,
&
v1
.
Binding
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Namespace
:
pod
.
Namespace
,
Name
:
pod
.
Name
,
UID
:
p
od
.
UID
},
ObjectMeta
:
metav1
.
ObjectMeta
{
Namespace
:
assumedPod
.
Namespace
,
Name
:
assumedPod
.
Name
,
UID
:
assumedP
od
.
UID
},
Target
:
v1
.
ObjectReference
{
Target
:
v1
.
ObjectReference
{
Kind
:
"Node"
,
Kind
:
"Node"
,
Name
:
suggestedHost
,
Name
:
suggestedHost
,
...
...
plugin/pkg/scheduler/scheduler_test.go
View file @
d584bf4d
...
@@ -115,6 +115,7 @@ func TestScheduler(t *testing.T) {
...
@@ -115,6 +115,7 @@ func TestScheduler(t *testing.T) {
sendPod
*
v1
.
Pod
sendPod
*
v1
.
Pod
algo
algorithm
.
ScheduleAlgorithm
algo
algorithm
.
ScheduleAlgorithm
expectErrorPod
*
v1
.
Pod
expectErrorPod
*
v1
.
Pod
expectForgetPod
*
v1
.
Pod
expectAssumedPod
*
v1
.
Pod
expectAssumedPod
*
v1
.
Pod
expectError
error
expectError
error
expectBind
*
v1
.
Binding
expectBind
*
v1
.
Binding
...
@@ -139,7 +140,8 @@ func TestScheduler(t *testing.T) {
...
@@ -139,7 +140,8 @@ func TestScheduler(t *testing.T) {
expectAssumedPod
:
podWithID
(
"foo"
,
testNode
.
Name
),
expectAssumedPod
:
podWithID
(
"foo"
,
testNode
.
Name
),
injectBindError
:
errB
,
injectBindError
:
errB
,
expectError
:
errB
,
expectError
:
errB
,
expectErrorPod
:
podWithID
(
"foo"
,
""
),
expectErrorPod
:
podWithID
(
"foo"
,
testNode
.
Name
),
expectForgetPod
:
podWithID
(
"foo"
,
testNode
.
Name
),
eventReason
:
"FailedScheduling"
,
eventReason
:
"FailedScheduling"
,
},
{
},
{
sendPod
:
deletingPod
(
"foo"
),
sendPod
:
deletingPod
(
"foo"
),
...
@@ -151,11 +153,15 @@ func TestScheduler(t *testing.T) {
...
@@ -151,11 +153,15 @@ func TestScheduler(t *testing.T) {
for
i
,
item
:=
range
table
{
for
i
,
item
:=
range
table
{
var
gotError
error
var
gotError
error
var
gotPod
*
v1
.
Pod
var
gotPod
*
v1
.
Pod
var
gotForgetPod
*
v1
.
Pod
var
gotAssumedPod
*
v1
.
Pod
var
gotAssumedPod
*
v1
.
Pod
var
gotBinding
*
v1
.
Binding
var
gotBinding
*
v1
.
Binding
configurator
:=
&
FakeConfigurator
{
configurator
:=
&
FakeConfigurator
{
Config
:
&
Config
{
Config
:
&
Config
{
SchedulerCache
:
&
schedulertesting
.
FakeCache
{
SchedulerCache
:
&
schedulertesting
.
FakeCache
{
ForgetFunc
:
func
(
pod
*
v1
.
Pod
)
{
gotForgetPod
=
pod
},
AssumeFunc
:
func
(
pod
*
v1
.
Pod
)
{
AssumeFunc
:
func
(
pod
*
v1
.
Pod
)
{
gotAssumedPod
=
pod
gotAssumedPod
=
pod
},
},
...
@@ -196,6 +202,9 @@ func TestScheduler(t *testing.T) {
...
@@ -196,6 +202,9 @@ func TestScheduler(t *testing.T) {
if
e
,
a
:=
item
.
expectErrorPod
,
gotPod
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
if
e
,
a
:=
item
.
expectErrorPod
,
gotPod
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"%v: error pod: wanted %v, got %v"
,
i
,
e
,
a
)
t
.
Errorf
(
"%v: error pod: wanted %v, got %v"
,
i
,
e
,
a
)
}
}
if
e
,
a
:=
item
.
expectForgetPod
,
gotForgetPod
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"%v: forget pod: wanted %v, got %v"
,
i
,
e
,
a
)
}
if
e
,
a
:=
item
.
expectError
,
gotError
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
if
e
,
a
:=
item
.
expectError
,
gotError
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"%v: error: wanted %v, got %v"
,
i
,
e
,
a
)
t
.
Errorf
(
"%v: error: wanted %v, got %v"
,
i
,
e
,
a
)
}
}
...
...
plugin/pkg/scheduler/testing/fake_cache.go
View file @
d584bf4d
...
@@ -25,6 +25,7 @@ import (
...
@@ -25,6 +25,7 @@ import (
// FakeCache is used for testing
// FakeCache is used for testing
type
FakeCache
struct
{
type
FakeCache
struct
{
AssumeFunc
func
(
*
v1
.
Pod
)
AssumeFunc
func
(
*
v1
.
Pod
)
ForgetFunc
func
(
*
v1
.
Pod
)
}
}
func
(
f
*
FakeCache
)
AssumePod
(
pod
*
v1
.
Pod
)
error
{
func
(
f
*
FakeCache
)
AssumePod
(
pod
*
v1
.
Pod
)
error
{
...
@@ -34,7 +35,10 @@ func (f *FakeCache) AssumePod(pod *v1.Pod) error {
...
@@ -34,7 +35,10 @@ func (f *FakeCache) AssumePod(pod *v1.Pod) error {
func
(
f
*
FakeCache
)
FinishBinding
(
pod
*
v1
.
Pod
)
error
{
return
nil
}
func
(
f
*
FakeCache
)
FinishBinding
(
pod
*
v1
.
Pod
)
error
{
return
nil
}
func
(
f
*
FakeCache
)
ForgetPod
(
pod
*
v1
.
Pod
)
error
{
return
nil
}
func
(
f
*
FakeCache
)
ForgetPod
(
pod
*
v1
.
Pod
)
error
{
f
.
ForgetFunc
(
pod
)
return
nil
}
func
(
f
*
FakeCache
)
AddPod
(
pod
*
v1
.
Pod
)
error
{
return
nil
}
func
(
f
*
FakeCache
)
AddPod
(
pod
*
v1
.
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