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
28e6bbc1
Commit
28e6bbc1
authored
Jan 18, 2019
by
wangqingcan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
acquire lock before operating unschedulablepodsmap
parent
54dc9db1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
11 deletions
+23
-11
scheduling_queue_test.go
pkg/scheduler/internal/queue/scheduling_queue_test.go
+23
-11
No files found.
pkg/scheduler/internal/queue/scheduling_queue_test.go
View file @
28e6bbc1
...
@@ -95,6 +95,18 @@ var highPriorityPod, highPriNominatedPod, medPriorityPod, unschedulablePod = v1.
...
@@ -95,6 +95,18 @@ var highPriorityPod, highPriNominatedPod, medPriorityPod, unschedulablePod = v1.
},
},
}
}
func
addOrUpdateUnschedulablePod
(
p
*
PriorityQueue
,
pod
*
v1
.
Pod
)
{
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
p
.
unschedulableQ
.
addOrUpdate
(
pod
)
}
func
getUnschedulablePod
(
p
*
PriorityQueue
,
pod
*
v1
.
Pod
)
*
v1
.
Pod
{
p
.
lock
.
Lock
()
defer
p
.
lock
.
Unlock
()
return
p
.
unschedulableQ
.
get
(
pod
)
}
func
TestPriorityQueue_Add
(
t
*
testing
.
T
)
{
func
TestPriorityQueue_Add
(
t
*
testing
.
T
)
{
q
:=
NewPriorityQueue
(
nil
)
q
:=
NewPriorityQueue
(
nil
)
if
err
:=
q
.
Add
(
&
medPriorityPod
);
err
!=
nil
{
if
err
:=
q
.
Add
(
&
medPriorityPod
);
err
!=
nil
{
...
@@ -134,7 +146,7 @@ func TestPriorityQueue_Add(t *testing.T) {
...
@@ -134,7 +146,7 @@ func TestPriorityQueue_Add(t *testing.T) {
func
TestPriorityQueue_AddIfNotPresent
(
t
*
testing
.
T
)
{
func
TestPriorityQueue_AddIfNotPresent
(
t
*
testing
.
T
)
{
q
:=
NewPriorityQueue
(
nil
)
q
:=
NewPriorityQueue
(
nil
)
q
.
unschedulableQ
.
addOrUpdate
(
&
highPriNominatedPod
)
addOrUpdateUnschedulablePod
(
q
,
&
highPriNominatedPod
)
q
.
AddIfNotPresent
(
&
highPriNominatedPod
)
// Must not add anything.
q
.
AddIfNotPresent
(
&
highPriNominatedPod
)
// Must not add anything.
q
.
AddIfNotPresent
(
&
medPriorityPod
)
q
.
AddIfNotPresent
(
&
medPriorityPod
)
q
.
AddIfNotPresent
(
&
unschedulablePod
)
q
.
AddIfNotPresent
(
&
unschedulablePod
)
...
@@ -159,7 +171,7 @@ func TestPriorityQueue_AddIfNotPresent(t *testing.T) {
...
@@ -159,7 +171,7 @@ func TestPriorityQueue_AddIfNotPresent(t *testing.T) {
if
len
(
q
.
nominatedPods
.
nominatedPods
[
"node1"
])
!=
2
{
if
len
(
q
.
nominatedPods
.
nominatedPods
[
"node1"
])
!=
2
{
t
.
Errorf
(
"Expected medPriorityPod and unschedulablePod to be still present in nomindatePods: %v"
,
q
.
nominatedPods
.
nominatedPods
[
"node1"
])
t
.
Errorf
(
"Expected medPriorityPod and unschedulablePod to be still present in nomindatePods: %v"
,
q
.
nominatedPods
.
nominatedPods
[
"node1"
])
}
}
if
q
.
unschedulableQ
.
get
(
&
highPriNominatedPod
)
!=
&
highPriNominatedPod
{
if
getUnschedulablePod
(
q
,
&
highPriNominatedPod
)
!=
&
highPriNominatedPod
{
t
.
Errorf
(
"Pod %v was not found in the unschedulableQ."
,
highPriNominatedPod
.
Name
)
t
.
Errorf
(
"Pod %v was not found in the unschedulableQ."
,
highPriNominatedPod
.
Name
)
}
}
}
}
...
@@ -192,7 +204,7 @@ func TestPriorityQueue_AddUnschedulableIfNotPresent(t *testing.T) {
...
@@ -192,7 +204,7 @@ func TestPriorityQueue_AddUnschedulableIfNotPresent(t *testing.T) {
if
len
(
q
.
nominatedPods
.
nominatedPods
)
!=
1
{
if
len
(
q
.
nominatedPods
.
nominatedPods
)
!=
1
{
t
.
Errorf
(
"Expected nomindatePods to have one element: %v"
,
q
.
nominatedPods
)
t
.
Errorf
(
"Expected nomindatePods to have one element: %v"
,
q
.
nominatedPods
)
}
}
if
q
.
unschedulableQ
.
get
(
&
unschedulablePod
)
!=
&
unschedulablePod
{
if
getUnschedulablePod
(
q
,
&
unschedulablePod
)
!=
&
unschedulablePod
{
t
.
Errorf
(
"Pod %v was not found in the unschedulableQ."
,
unschedulablePod
.
Name
)
t
.
Errorf
(
"Pod %v was not found in the unschedulableQ."
,
unschedulablePod
.
Name
)
}
}
}
}
...
@@ -277,8 +289,8 @@ func TestPriorityQueue_Delete(t *testing.T) {
...
@@ -277,8 +289,8 @@ func TestPriorityQueue_Delete(t *testing.T) {
func
TestPriorityQueue_MoveAllToActiveQueue
(
t
*
testing
.
T
)
{
func
TestPriorityQueue_MoveAllToActiveQueue
(
t
*
testing
.
T
)
{
q
:=
NewPriorityQueue
(
nil
)
q
:=
NewPriorityQueue
(
nil
)
q
.
Add
(
&
medPriorityPod
)
q
.
Add
(
&
medPriorityPod
)
q
.
unschedulableQ
.
addOrUpdate
(
&
unschedulablePod
)
addOrUpdateUnschedulablePod
(
q
,
&
unschedulablePod
)
q
.
unschedulableQ
.
addOrUpdate
(
&
highPriorityPod
)
addOrUpdateUnschedulablePod
(
q
,
&
highPriorityPod
)
q
.
MoveAllToActiveQueue
()
q
.
MoveAllToActiveQueue
()
if
q
.
activeQ
.
Len
()
!=
3
{
if
q
.
activeQ
.
Len
()
!=
3
{
t
.
Error
(
"Expected all items to be in activeQ."
)
t
.
Error
(
"Expected all items to be in activeQ."
)
...
@@ -324,19 +336,19 @@ func TestPriorityQueue_AssignedPodAdded(t *testing.T) {
...
@@ -324,19 +336,19 @@ func TestPriorityQueue_AssignedPodAdded(t *testing.T) {
q
:=
NewPriorityQueue
(
nil
)
q
:=
NewPriorityQueue
(
nil
)
q
.
Add
(
&
medPriorityPod
)
q
.
Add
(
&
medPriorityPod
)
// Add a couple of pods to the unschedulableQ.
// Add a couple of pods to the unschedulableQ.
q
.
unschedulableQ
.
addOrUpdate
(
&
unschedulablePod
)
addOrUpdateUnschedulablePod
(
q
,
&
unschedulablePod
)
q
.
unschedulableQ
.
addOrUpdate
(
affinityPod
)
addOrUpdateUnschedulablePod
(
q
,
affinityPod
)
// Simulate addition of an assigned pod. The pod has matching labels for
// Simulate addition of an assigned pod. The pod has matching labels for
// affinityPod. So, affinityPod should go to activeQ.
// affinityPod. So, affinityPod should go to activeQ.
q
.
AssignedPodAdded
(
&
labelPod
)
q
.
AssignedPodAdded
(
&
labelPod
)
if
q
.
unschedulableQ
.
get
(
affinityPod
)
!=
nil
{
if
getUnschedulablePod
(
q
,
affinityPod
)
!=
nil
{
t
.
Error
(
"affinityPod is still in the unschedulableQ."
)
t
.
Error
(
"affinityPod is still in the unschedulableQ."
)
}
}
if
_
,
exists
,
_
:=
q
.
activeQ
.
Get
(
affinityPod
);
!
exists
{
if
_
,
exists
,
_
:=
q
.
activeQ
.
Get
(
affinityPod
);
!
exists
{
t
.
Error
(
"affinityPod is not moved to activeQ."
)
t
.
Error
(
"affinityPod is not moved to activeQ."
)
}
}
// Check that the other pod is still in the unschedulableQ.
// Check that the other pod is still in the unschedulableQ.
if
q
.
unschedulableQ
.
get
(
&
unschedulablePod
)
==
nil
{
if
getUnschedulablePod
(
q
,
&
unschedulablePod
)
==
nil
{
t
.
Error
(
"unschedulablePod is not in the unschedulableQ."
)
t
.
Error
(
"unschedulablePod is not in the unschedulableQ."
)
}
}
}
}
...
@@ -361,8 +373,8 @@ func TestPriorityQueue_NominatedPodsForNode(t *testing.T) {
...
@@ -361,8 +373,8 @@ func TestPriorityQueue_NominatedPodsForNode(t *testing.T) {
func
TestPriorityQueue_PendingPods
(
t
*
testing
.
T
)
{
func
TestPriorityQueue_PendingPods
(
t
*
testing
.
T
)
{
q
:=
NewPriorityQueue
(
nil
)
q
:=
NewPriorityQueue
(
nil
)
q
.
Add
(
&
medPriorityPod
)
q
.
Add
(
&
medPriorityPod
)
q
.
unschedulableQ
.
addOrUpdate
(
&
unschedulablePod
)
addOrUpdateUnschedulablePod
(
q
,
&
unschedulablePod
)
q
.
unschedulableQ
.
addOrUpdate
(
&
highPriorityPod
)
addOrUpdateUnschedulablePod
(
q
,
&
highPriorityPod
)
expectedList
:=
[]
*
v1
.
Pod
{
&
medPriorityPod
,
&
unschedulablePod
,
&
highPriorityPod
}
expectedList
:=
[]
*
v1
.
Pod
{
&
medPriorityPod
,
&
unschedulablePod
,
&
highPriorityPod
}
if
!
reflect
.
DeepEqual
(
expectedList
,
q
.
PendingPods
())
{
if
!
reflect
.
DeepEqual
(
expectedList
,
q
.
PendingPods
())
{
t
.
Error
(
"Unexpected list of pending Pods for node."
)
t
.
Error
(
"Unexpected list of pending Pods for node."
)
...
...
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