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
c4df3a2c
Unverified
Commit
c4df3a2c
authored
May 08, 2019
by
Wei Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent `predicatesOrdering` from escaping from UT
- sets `predicatesOrdering` back to original value in UT
parent
5bd88c85
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
9 deletions
+16
-9
predicates.go
pkg/scheduler/algorithm/predicates/predicates.go
+0
-5
utils.go
pkg/scheduler/algorithm/predicates/utils.go
+10
-0
generic_scheduler_test.go
pkg/scheduler/core/generic_scheduler_test.go
+6
-4
No files found.
pkg/scheduler/algorithm/predicates/predicates.go
View file @
c4df3a2c
...
...
@@ -173,11 +173,6 @@ func Ordering() []string {
return
predicatesOrdering
}
// SetPredicatesOrdering sets the ordering of predicates.
func
SetPredicatesOrdering
(
names
[]
string
)
{
predicatesOrdering
=
names
}
// GetPersistentVolumeInfo returns a persistent volume object by PV ID.
func
(
c
*
CachedPersistentVolumeInfo
)
GetPersistentVolumeInfo
(
pvID
string
)
(
*
v1
.
PersistentVolume
,
error
)
{
return
c
.
Get
(
pvID
)
...
...
pkg/scheduler/algorithm/predicates/utils.go
View file @
c4df3a2c
...
...
@@ -77,3 +77,13 @@ func portsConflict(existingPorts schedulernodeinfo.HostPortInfo, wantPorts []*v1
return
false
}
// SetPredicatesOrderingDuringTest sets the predicatesOrdering to the specified
// value, and returns a function that restores the original value.
func
SetPredicatesOrderingDuringTest
(
value
[]
string
)
func
()
{
origVal
:=
predicatesOrdering
predicatesOrdering
=
value
return
func
()
{
predicatesOrdering
=
origVal
}
}
pkg/scheduler/core/generic_scheduler_test.go
View file @
c4df3a2c
...
...
@@ -217,7 +217,7 @@ func TestSelectHost(t *testing.T) {
}
func
TestGenericScheduler
(
t
*
testing
.
T
)
{
algorithmpredicates
.
SetPredicatesOrdering
(
order
)
defer
algorithmpredicates
.
SetPredicatesOrderingDuringTest
(
order
)(
)
tests
:=
[]
struct
{
name
string
predicates
map
[
string
]
algorithmpredicates
.
FitPredicate
...
...
@@ -479,7 +479,6 @@ func TestGenericScheduler(t *testing.T) {
// makeScheduler makes a simple genericScheduler for testing.
func
makeScheduler
(
predicates
map
[
string
]
algorithmpredicates
.
FitPredicate
,
nodes
[]
*
v1
.
Node
)
*
genericScheduler
{
algorithmpredicates
.
SetPredicatesOrdering
(
order
)
cache
:=
internalcache
.
New
(
time
.
Duration
(
0
),
wait
.
NeverStop
)
fwk
,
_
:=
framework
.
NewFramework
(
EmptyPluginRegistry
,
nil
)
for
_
,
n
:=
range
nodes
{
...
...
@@ -503,6 +502,7 @@ func makeScheduler(predicates map[string]algorithmpredicates.FitPredicate, nodes
}
func
TestFindFitAllError
(
t
*
testing
.
T
)
{
defer
algorithmpredicates
.
SetPredicatesOrderingDuringTest
(
order
)()
predicates
:=
map
[
string
]
algorithmpredicates
.
FitPredicate
{
"true"
:
truePredicate
,
"matches"
:
matchesPredicate
}
nodes
:=
makeNodeList
([]
string
{
"3"
,
"2"
,
"1"
})
scheduler
:=
makeScheduler
(
predicates
,
nodes
)
...
...
@@ -531,6 +531,7 @@ func TestFindFitAllError(t *testing.T) {
}
func
TestFindFitSomeError
(
t
*
testing
.
T
)
{
defer
algorithmpredicates
.
SetPredicatesOrderingDuringTest
(
order
)()
predicates
:=
map
[
string
]
algorithmpredicates
.
FitPredicate
{
"true"
:
truePredicate
,
"matches"
:
matchesPredicate
}
nodes
:=
makeNodeList
([]
string
{
"3"
,
"2"
,
"1"
})
scheduler
:=
makeScheduler
(
predicates
,
nodes
)
...
...
@@ -846,7 +847,7 @@ var startTime20190107 = metav1.Date(2019, 1, 7, 1, 1, 1, 0, time.UTC)
// TestSelectNodesForPreemption tests selectNodesForPreemption. This test assumes
// that podsFitsOnNode works correctly and is tested separately.
func
TestSelectNodesForPreemption
(
t
*
testing
.
T
)
{
algorithmpredicates
.
SetPredicatesOrdering
(
order
)
defer
algorithmpredicates
.
SetPredicatesOrderingDuringTest
(
order
)(
)
tests
:=
[]
struct
{
name
string
predicates
map
[
string
]
algorithmpredicates
.
FitPredicate
...
...
@@ -1005,7 +1006,7 @@ func TestSelectNodesForPreemption(t *testing.T) {
// TestPickOneNodeForPreemption tests pickOneNodeForPreemption.
func
TestPickOneNodeForPreemption
(
t
*
testing
.
T
)
{
algorithmpredicates
.
SetPredicatesOrdering
(
order
)
defer
algorithmpredicates
.
SetPredicatesOrderingDuringTest
(
order
)(
)
tests
:=
[]
struct
{
name
string
predicates
map
[
string
]
algorithmpredicates
.
FitPredicate
...
...
@@ -1321,6 +1322,7 @@ func TestNodesWherePreemptionMightHelp(t *testing.T) {
}
func
TestPreempt
(
t
*
testing
.
T
)
{
defer
algorithmpredicates
.
SetPredicatesOrderingDuringTest
(
order
)()
failedPredMap
:=
FailedPredicateMap
{
"machine1"
:
[]
algorithmpredicates
.
PredicateFailureReason
{
algorithmpredicates
.
NewInsufficientResourceError
(
v1
.
ResourceMemory
,
1000
,
500
,
300
)},
"machine2"
:
[]
algorithmpredicates
.
PredicateFailureReason
{
algorithmpredicates
.
ErrDiskConflict
},
...
...
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