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
c6379cef
Commit
c6379cef
authored
May 10, 2018
by
John Calabrese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use subtest for table units
parent
4da73a5f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
231 additions
and
171 deletions
+231
-171
cache_comparer_test.go
pkg/scheduler/factory/cache_comparer_test.go
+108
-78
factory_test.go
pkg/scheduler/factory/factory_test.go
+102
-78
plugins_test.go
pkg/scheduler/factory/plugins_test.go
+21
-15
No files found.
pkg/scheduler/factory/cache_comparer_test.go
View file @
c6379cef
...
@@ -27,27 +27,29 @@ import (
...
@@ -27,27 +27,29 @@ import (
)
)
func
TestCompareNodes
(
t
*
testing
.
T
)
{
func
TestCompareNodes
(
t
*
testing
.
T
)
{
compare
:=
compareStrategy
{}
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
actual
[]
string
actual
[]
string
cached
[]
string
cached
[]
string
missing
[]
string
missing
[]
string
redundant
[]
string
redundant
[]
string
}{
}{
{
{
name
:
"redundant cached value"
,
actual
:
[]
string
{
"foo"
,
"bar"
},
actual
:
[]
string
{
"foo"
,
"bar"
},
cached
:
[]
string
{
"bar"
,
"foo"
,
"foobar"
},
cached
:
[]
string
{
"bar"
,
"foo"
,
"foobar"
},
missing
:
[]
string
{},
missing
:
[]
string
{},
redundant
:
[]
string
{
"foobar"
},
redundant
:
[]
string
{
"foobar"
},
},
},
{
{
name
:
"missing cached value"
,
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
cached
:
[]
string
{
"bar"
,
"foo"
},
cached
:
[]
string
{
"bar"
,
"foo"
},
missing
:
[]
string
{
"foobar"
},
missing
:
[]
string
{
"foobar"
},
redundant
:
[]
string
{},
redundant
:
[]
string
{},
},
},
{
{
name
:
"proper cache set"
,
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
cached
:
[]
string
{
"bar"
,
"foobar"
,
"foo"
},
cached
:
[]
string
{
"bar"
,
"foobar"
,
"foo"
},
missing
:
[]
string
{},
missing
:
[]
string
{},
...
@@ -56,34 +58,40 @@ func TestCompareNodes(t *testing.T) {
...
@@ -56,34 +58,40 @@ func TestCompareNodes(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
nodes
:=
[]
*
v1
.
Node
{}
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
for
_
,
nodeName
:=
range
test
.
actual
{
testCompareNodes
(
test
.
actual
,
test
.
cached
,
test
.
missing
,
test
.
redundant
,
t
)
node
:=
&
v1
.
Node
{}
})
node
.
Name
=
nodeName
}
nodes
=
append
(
nodes
,
node
)
}
}
nodeInfo
:=
make
(
map
[
string
]
*
schedulercache
.
NodeInfo
)
func
testCompareNodes
(
actual
,
cached
,
missing
,
redundant
[]
string
,
t
*
testing
.
T
)
{
for
_
,
nodeName
:=
range
test
.
cached
{
compare
:=
compareStrategy
{}
nodeInfo
[
nodeName
]
=
&
schedulercache
.
NodeInfo
{}
nodes
:=
[]
*
v1
.
Node
{}
}
for
_
,
nodeName
:=
range
actual
{
node
:=
&
v1
.
Node
{}
node
.
Name
=
nodeName
nodes
=
append
(
nodes
,
node
)
}
nodeInfo
:=
make
(
map
[
string
]
*
schedulercache
.
NodeInfo
)
for
_
,
nodeName
:=
range
cached
{
nodeInfo
[
nodeName
]
=
&
schedulercache
.
NodeInfo
{}
}
m
,
r
:=
compare
.
CompareNodes
(
nodes
,
nodeInfo
)
m
,
r
:=
compare
.
CompareNodes
(
nodes
,
nodeInfo
)
if
!
reflect
.
DeepEqual
(
m
,
test
.
missing
)
{
if
!
reflect
.
DeepEqual
(
m
,
missing
)
{
t
.
Errorf
(
"missing expected to be %s; got %s"
,
test
.
missing
,
m
)
t
.
Errorf
(
"missing expected to be %s; got %s"
,
missing
,
m
)
}
}
if
!
reflect
.
DeepEqual
(
r
,
test
.
redundant
)
{
if
!
reflect
.
DeepEqual
(
r
,
redundant
)
{
t
.
Errorf
(
"redundant expected to be %s; got %s"
,
test
.
redundant
,
r
)
t
.
Errorf
(
"redundant expected to be %s; got %s"
,
redundant
,
r
)
}
}
}
}
}
func
TestComparePods
(
t
*
testing
.
T
)
{
func
TestComparePods
(
t
*
testing
.
T
)
{
compare
:=
compareStrategy
{}
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
actual
[]
string
actual
[]
string
cached
[]
string
cached
[]
string
queued
[]
string
queued
[]
string
...
@@ -91,6 +99,7 @@ func TestComparePods(t *testing.T) {
...
@@ -91,6 +99,7 @@ func TestComparePods(t *testing.T) {
redundant
[]
string
redundant
[]
string
}{
}{
{
{
name
:
"redundant cached value"
,
actual
:
[]
string
{
"foo"
,
"bar"
},
actual
:
[]
string
{
"foo"
,
"bar"
},
cached
:
[]
string
{
"bar"
,
"foo"
,
"foobar"
},
cached
:
[]
string
{
"bar"
,
"foo"
,
"foobar"
},
queued
:
[]
string
{},
queued
:
[]
string
{},
...
@@ -98,6 +107,7 @@ func TestComparePods(t *testing.T) {
...
@@ -98,6 +107,7 @@ func TestComparePods(t *testing.T) {
redundant
:
[]
string
{
"foobar"
},
redundant
:
[]
string
{
"foobar"
},
},
},
{
{
name
:
"redundant and queued values"
,
actual
:
[]
string
{
"foo"
,
"bar"
},
actual
:
[]
string
{
"foo"
,
"bar"
},
cached
:
[]
string
{
"foo"
,
"foobar"
},
cached
:
[]
string
{
"foo"
,
"foobar"
},
queued
:
[]
string
{
"bar"
},
queued
:
[]
string
{
"bar"
},
...
@@ -105,6 +115,7 @@ func TestComparePods(t *testing.T) {
...
@@ -105,6 +115,7 @@ func TestComparePods(t *testing.T) {
redundant
:
[]
string
{
"foobar"
},
redundant
:
[]
string
{
"foobar"
},
},
},
{
{
name
:
"missing cached value"
,
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
cached
:
[]
string
{
"bar"
,
"foo"
},
cached
:
[]
string
{
"bar"
,
"foo"
},
queued
:
[]
string
{},
queued
:
[]
string
{},
...
@@ -112,6 +123,7 @@ func TestComparePods(t *testing.T) {
...
@@ -112,6 +123,7 @@ func TestComparePods(t *testing.T) {
redundant
:
[]
string
{},
redundant
:
[]
string
{},
},
},
{
{
name
:
"missing and queued values"
,
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
cached
:
[]
string
{
"foo"
},
cached
:
[]
string
{
"foo"
},
queued
:
[]
string
{
"bar"
},
queued
:
[]
string
{
"bar"
},
...
@@ -119,6 +131,7 @@ func TestComparePods(t *testing.T) {
...
@@ -119,6 +131,7 @@ func TestComparePods(t *testing.T) {
redundant
:
[]
string
{},
redundant
:
[]
string
{},
},
},
{
{
name
:
"correct cache set"
,
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
cached
:
[]
string
{
"bar"
,
"foobar"
,
"foo"
},
cached
:
[]
string
{
"bar"
,
"foobar"
,
"foo"
},
queued
:
[]
string
{},
queued
:
[]
string
{},
...
@@ -126,6 +139,7 @@ func TestComparePods(t *testing.T) {
...
@@ -126,6 +139,7 @@ func TestComparePods(t *testing.T) {
redundant
:
[]
string
{},
redundant
:
[]
string
{},
},
},
{
{
name
:
"queued cache value"
,
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
cached
:
[]
string
{
"foobar"
,
"foo"
},
cached
:
[]
string
{
"foobar"
,
"foo"
},
queued
:
[]
string
{
"bar"
},
queued
:
[]
string
{
"bar"
},
...
@@ -135,64 +149,73 @@ func TestComparePods(t *testing.T) {
...
@@ -135,64 +149,73 @@ func TestComparePods(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
pods
:=
[]
*
v1
.
Pod
{}
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
for
_
,
uid
:=
range
test
.
actual
{
testComparePods
(
test
.
actual
,
test
.
cached
,
test
.
queued
,
test
.
missing
,
test
.
redundant
,
t
)
pod
:=
&
v1
.
Pod
{}
})
pod
.
UID
=
types
.
UID
(
uid
)
pods
=
append
(
pods
,
pod
)
}
queuedPods
:=
[]
*
v1
.
Pod
{}
for
_
,
uid
:=
range
test
.
queued
{
pod
:=
&
v1
.
Pod
{}
pod
.
UID
=
types
.
UID
(
uid
)
queuedPods
=
append
(
queuedPods
,
pod
)
}
nodeInfo
:=
make
(
map
[
string
]
*
schedulercache
.
NodeInfo
)
for
_
,
uid
:=
range
test
.
cached
{
pod
:=
&
v1
.
Pod
{}
pod
.
UID
=
types
.
UID
(
uid
)
pod
.
Namespace
=
"ns"
pod
.
Name
=
uid
nodeInfo
[
uid
]
=
schedulercache
.
NewNodeInfo
(
pod
)
}
m
,
r
:=
compare
.
ComparePods
(
pods
,
queuedPods
,
nodeInfo
)
if
!
reflect
.
DeepEqual
(
m
,
test
.
missing
)
{
t
.
Errorf
(
"missing expected to be %s; got %s"
,
test
.
missing
,
m
)
}
if
!
reflect
.
DeepEqual
(
r
,
test
.
redundant
)
{
t
.
Errorf
(
"redundant expected to be %s; got %s"
,
test
.
redundant
,
r
)
}
}
}
}
}
func
TestComparePdbs
(
t
*
testing
.
T
)
{
func
testComparePods
(
actual
,
cached
,
queued
,
missing
,
redundant
[]
string
,
t
*
testing
.
T
)
{
compare
:=
compareStrategy
{}
compare
:=
compareStrategy
{}
pods
:=
[]
*
v1
.
Pod
{}
for
_
,
uid
:=
range
actual
{
pod
:=
&
v1
.
Pod
{}
pod
.
UID
=
types
.
UID
(
uid
)
pods
=
append
(
pods
,
pod
)
}
queuedPods
:=
[]
*
v1
.
Pod
{}
for
_
,
uid
:=
range
queued
{
pod
:=
&
v1
.
Pod
{}
pod
.
UID
=
types
.
UID
(
uid
)
queuedPods
=
append
(
queuedPods
,
pod
)
}
nodeInfo
:=
make
(
map
[
string
]
*
schedulercache
.
NodeInfo
)
for
_
,
uid
:=
range
cached
{
pod
:=
&
v1
.
Pod
{}
pod
.
UID
=
types
.
UID
(
uid
)
pod
.
Namespace
=
"ns"
pod
.
Name
=
uid
nodeInfo
[
uid
]
=
schedulercache
.
NewNodeInfo
(
pod
)
}
m
,
r
:=
compare
.
ComparePods
(
pods
,
queuedPods
,
nodeInfo
)
if
!
reflect
.
DeepEqual
(
m
,
missing
)
{
t
.
Errorf
(
"missing expected to be %s; got %s"
,
missing
,
m
)
}
if
!
reflect
.
DeepEqual
(
r
,
redundant
)
{
t
.
Errorf
(
"redundant expected to be %s; got %s"
,
redundant
,
r
)
}
}
func
TestComparePdbs
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
actual
[]
string
actual
[]
string
cached
[]
string
cached
[]
string
missing
[]
string
missing
[]
string
redundant
[]
string
redundant
[]
string
}{
}{
{
{
name
:
"redundant cache value"
,
actual
:
[]
string
{
"foo"
,
"bar"
},
actual
:
[]
string
{
"foo"
,
"bar"
},
cached
:
[]
string
{
"bar"
,
"foo"
,
"foobar"
},
cached
:
[]
string
{
"bar"
,
"foo"
,
"foobar"
},
missing
:
[]
string
{},
missing
:
[]
string
{},
redundant
:
[]
string
{
"foobar"
},
redundant
:
[]
string
{
"foobar"
},
},
},
{
{
name
:
"missing cache value"
,
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
cached
:
[]
string
{
"bar"
,
"foo"
},
cached
:
[]
string
{
"bar"
,
"foo"
},
missing
:
[]
string
{
"foobar"
},
missing
:
[]
string
{
"foobar"
},
redundant
:
[]
string
{},
redundant
:
[]
string
{},
},
},
{
{
name
:
"correct cache"
,
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
actual
:
[]
string
{
"foo"
,
"bar"
,
"foobar"
},
cached
:
[]
string
{
"bar"
,
"foobar"
,
"foo"
},
cached
:
[]
string
{
"bar"
,
"foobar"
,
"foo"
},
missing
:
[]
string
{},
missing
:
[]
string
{},
...
@@ -201,28 +224,35 @@ func TestComparePdbs(t *testing.T) {
...
@@ -201,28 +224,35 @@ func TestComparePdbs(t *testing.T) {
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
pdbs
:=
[]
*
policy
.
PodDisruptionBudget
{}
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
for
_
,
uid
:=
range
test
.
actual
{
testComparePdbs
(
test
.
actual
,
test
.
cached
,
test
.
missing
,
test
.
redundant
,
t
)
pdb
:=
&
policy
.
PodDisruptionBudget
{}
})
pdb
.
UID
=
types
.
UID
(
uid
)
}
pdbs
=
append
(
pdbs
,
pdb
)
}
}
func
testComparePdbs
(
actual
,
cached
,
missing
,
redundant
[]
string
,
t
*
testing
.
T
)
{
cache
:=
make
(
map
[
string
]
*
policy
.
PodDisruptionBudget
)
compare
:=
compareStrategy
{}
for
_
,
uid
:=
range
test
.
cached
{
pdbs
:=
[]
*
policy
.
PodDisruptionBudget
{}
pdb
:=
&
policy
.
PodDisruptionBudget
{}
for
_
,
uid
:=
range
actual
{
pdb
.
UID
=
types
.
UID
(
uid
)
pdb
:=
&
policy
.
PodDisruptionBudget
{}
cache
[
uid
]
=
pdb
pdb
.
UID
=
types
.
UID
(
uid
)
}
pdbs
=
append
(
pdbs
,
pdb
)
}
m
,
r
:=
compare
.
ComparePdbs
(
pdbs
,
cache
)
cache
:=
make
(
map
[
string
]
*
policy
.
PodDisruptionBudget
)
if
!
reflect
.
DeepEqual
(
m
,
test
.
missing
)
{
for
_
,
uid
:=
range
cached
{
t
.
Errorf
(
"missing expected to be %s; got %s"
,
test
.
missing
,
m
)
pdb
:=
&
policy
.
PodDisruptionBudget
{}
}
pdb
.
UID
=
types
.
UID
(
uid
)
cache
[
uid
]
=
pdb
if
!
reflect
.
DeepEqual
(
r
,
test
.
redundant
)
{
}
t
.
Errorf
(
"redundant expected to be %s; got %s"
,
test
.
redundant
,
r
)
}
m
,
r
:=
compare
.
ComparePdbs
(
pdbs
,
cache
)
if
!
reflect
.
DeepEqual
(
m
,
missing
)
{
t
.
Errorf
(
"missing expected to be %s; got %s"
,
missing
,
m
)
}
if
!
reflect
.
DeepEqual
(
r
,
redundant
)
{
t
.
Errorf
(
"redundant expected to be %s; got %s"
,
redundant
,
r
)
}
}
}
}
pkg/scheduler/factory/factory_test.go
View file @
c6379cef
...
@@ -331,51 +331,63 @@ func TestNodeEnumerator(t *testing.T) {
...
@@ -331,51 +331,63 @@ func TestNodeEnumerator(t *testing.T) {
t
.
Fatalf
(
"expected %v, got %v"
,
e
,
a
)
t
.
Fatalf
(
"expected %v, got %v"
,
e
,
a
)
}
}
for
i
:=
range
testList
.
Items
{
for
i
:=
range
testList
.
Items
{
gotObj
:=
me
.
Get
(
i
)
t
.
Run
(
fmt
.
Sprintf
(
"node enumerator/%v"
,
i
),
func
(
t
*
testing
.
T
)
{
if
e
,
a
:=
testList
.
Items
[
i
]
.
Name
,
gotObj
.
(
*
v1
.
Node
)
.
Name
;
e
!=
a
{
gotObj
:=
me
.
Get
(
i
)
t
.
Errorf
(
"Expected %v, got %v"
,
e
,
a
)
if
e
,
a
:=
testList
.
Items
[
i
]
.
Name
,
gotObj
.
(
*
v1
.
Node
)
.
Name
;
e
!=
a
{
}
t
.
Errorf
(
"Expected %v, got %v"
,
e
,
a
)
if
e
,
a
:=
&
testList
.
Items
[
i
],
gotObj
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
}
t
.
Errorf
(
"Expected %#v, got %v#"
,
e
,
a
)
if
e
,
a
:=
&
testList
.
Items
[
i
],
gotObj
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
}
t
.
Errorf
(
"Expected %#v, got %v#"
,
e
,
a
)
}
})
}
}
}
}
func
TestBind
(
t
*
testing
.
T
)
{
func
TestBind
(
t
*
testing
.
T
)
{
table
:=
[]
struct
{
table
:=
[]
struct
{
name
string
binding
*
v1
.
Binding
binding
*
v1
.
Binding
}{
}{
{
binding
:
&
v1
.
Binding
{
{
ObjectMeta
:
metav1
.
ObjectMeta
{
name
:
"binding can bind and validate request"
,
Namespace
:
metav1
.
NamespaceDefault
,
binding
:
&
v1
.
Binding
{
Name
:
"foo"
,
ObjectMeta
:
metav1
.
ObjectMeta
{
},
Namespace
:
metav1
.
NamespaceDefault
,
Target
:
v1
.
ObjectReference
{
Name
:
"foo"
,
Name
:
"foohost.kubernetes.mydomain.com"
,
},
Target
:
v1
.
ObjectReference
{
Name
:
"foohost.kubernetes.mydomain.com"
,
},
},
},
}
}
,
},
}
}
for
_
,
item
:=
range
table
{
for
_
,
test
:=
range
table
{
handler
:=
utiltesting
.
FakeHandler
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
StatusCode
:
200
,
testBind
(
test
.
binding
,
t
)
ResponseBody
:
""
,
})
T
:
t
,
}
}
}
server
:=
httptest
.
NewServer
(
&
handler
)
defer
server
.
Close
()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
server
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
schema
.
GroupVersion
{
Group
:
""
,
Version
:
"v1"
}}})
b
:=
binder
{
client
}
if
err
:=
b
.
Bind
(
item
.
binding
);
err
!=
nil
{
func
testBind
(
binding
*
v1
.
Binding
,
t
*
testing
.
T
)
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
handler
:=
utiltesting
.
FakeHandler
{
continue
StatusCode
:
200
,
}
ResponseBody
:
""
,
expectedBody
:=
runtime
.
EncodeOrDie
(
schedulertesting
.
Test
.
Codec
(),
item
.
binding
)
T
:
t
,
handler
.
ValidateRequest
(
t
,
}
schedulertesting
.
Test
.
SubResourcePath
(
string
(
v1
.
ResourcePods
),
metav1
.
NamespaceDefault
,
"foo"
,
"binding"
),
server
:=
httptest
.
NewServer
(
&
handler
)
"POST"
,
&
expectedBody
)
defer
server
.
Close
()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
server
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
schema
.
GroupVersion
{
Group
:
""
,
Version
:
"v1"
}}})
b
:=
binder
{
client
}
if
err
:=
b
.
Bind
(
binding
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
return
}
}
expectedBody
:=
runtime
.
EncodeOrDie
(
schedulertesting
.
Test
.
Codec
(),
binding
)
handler
.
ValidateRequest
(
t
,
schedulertesting
.
Test
.
SubResourcePath
(
string
(
v1
.
ResourcePods
),
metav1
.
NamespaceDefault
,
"foo"
,
"binding"
),
"POST"
,
&
expectedBody
)
}
}
func
TestInvalidHardPodAffinitySymmetricWeight
(
t
*
testing
.
T
)
{
func
TestInvalidHardPodAffinitySymmetricWeight
(
t
*
testing
.
T
)
{
...
@@ -406,38 +418,44 @@ func TestInvalidFactoryArgs(t *testing.T) {
...
@@ -406,38 +418,44 @@ func TestInvalidFactoryArgs(t *testing.T) {
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
server
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
schema
.
GroupVersion
{
Group
:
""
,
Version
:
"v1"
}}})
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
server
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
schema
.
GroupVersion
{
Group
:
""
,
Version
:
"v1"
}}})
testCases
:=
[]
struct
{
testCases
:=
[]
struct
{
name
string
hardPodAffinitySymmetricWeight
int32
hardPodAffinitySymmetricWeight
int32
expectErr
string
expectErr
string
}{
}{
{
{
name
:
"symmetric weight below range"
,
hardPodAffinitySymmetricWeight
:
-
1
,
hardPodAffinitySymmetricWeight
:
-
1
,
expectErr
:
"invalid hardPodAffinitySymmetricWeight: -1, must be in the range 0-100"
,
expectErr
:
"invalid hardPodAffinitySymmetricWeight: -1, must be in the range 0-100"
,
},
},
{
{
name
:
"symmetric weight above range"
,
hardPodAffinitySymmetricWeight
:
101
,
hardPodAffinitySymmetricWeight
:
101
,
expectErr
:
"invalid hardPodAffinitySymmetricWeight: 101, must be in the range 0-100"
,
expectErr
:
"invalid hardPodAffinitySymmetricWeight: 101, must be in the range 0-100"
,
},
},
}
}
for
_
,
test
:=
range
testCases
{
for
_
,
test
:=
range
testCases
{
factory
:=
newConfigFactory
(
client
,
test
.
hardPodAffinitySymmetricWeight
)
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
_
,
err
:=
factory
.
Create
()
factory
:=
newConfigFactory
(
client
,
test
.
hardPodAffinitySymmetricWeight
)
if
err
==
nil
{
_
,
err
:=
factory
.
Create
()
t
.
Errorf
(
"expected err: %s, got nothing"
,
test
.
expectErr
)
if
err
==
nil
{
}
t
.
Errorf
(
"expected err: %s, got nothing"
,
test
.
expectErr
)
}
})
}
}
}
}
func
TestSkipPodUpdate
(
t
*
testing
.
T
)
{
func
TestSkipPodUpdate
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
[]
struct
{
table
:=
[]
struct
{
pod
*
v1
.
Pod
pod
*
v1
.
Pod
isAssumedPodFunc
func
(
*
v1
.
Pod
)
bool
isAssumedPodFunc
func
(
*
v1
.
Pod
)
bool
getPodFunc
func
(
*
v1
.
Pod
)
*
v1
.
Pod
getPodFunc
func
(
*
v1
.
Pod
)
*
v1
.
Pod
expected
bool
expected
bool
name
string
}{
}{
// Non-assumed pod should not be skipped.
{
{
name
:
"Non-assumed pod"
,
pod
:
&
v1
.
Pod
{
pod
:
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pod-0"
,
Name
:
"pod-0"
,
...
@@ -453,9 +471,8 @@ func TestSkipPodUpdate(t *testing.T) {
...
@@ -453,9 +471,8 @@ func TestSkipPodUpdate(t *testing.T) {
},
},
expected
:
false
,
expected
:
false
,
},
},
// Pod update (with changes on ResourceVersion, Spec.NodeName and/or
// Annotations) for an already assumed pod should be skipped.
{
{
name
:
"with changes on ResourceVersion, Spec.NodeName and/or Annotations"
,
pod
:
&
v1
.
Pod
{
pod
:
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pod-0"
,
Name
:
"pod-0"
,
...
@@ -483,9 +500,8 @@ func TestSkipPodUpdate(t *testing.T) {
...
@@ -483,9 +500,8 @@ func TestSkipPodUpdate(t *testing.T) {
},
},
expected
:
true
,
expected
:
true
,
},
},
// Pod update (with changes on Labels) for an already assumed pod
// should not be skipped.
{
{
name
:
"with changes on Labels"
,
pod
:
&
v1
.
Pod
{
pod
:
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"pod-0"
,
Name
:
"pod-0"
,
...
@@ -505,17 +521,20 @@ func TestSkipPodUpdate(t *testing.T) {
...
@@ -505,17 +521,20 @@ func TestSkipPodUpdate(t *testing.T) {
},
},
expected
:
false
,
expected
:
false
,
},
},
}
{
}
c
:=
&
configFactory
{
for
_
,
test
:=
range
table
{
schedulerCache
:
&
schedulertesting
.
FakeCache
{
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
IsAssumedPodFunc
:
test
.
isAssumedPodFunc
,
c
:=
&
configFactory
{
GetPodFunc
:
test
.
getPodFunc
,
schedulerCache
:
&
schedulertesting
.
FakeCache
{
},
IsAssumedPodFunc
:
test
.
isAssumedPodFunc
,
}
GetPodFunc
:
test
.
getPodFunc
,
got
:=
c
.
skipPodUpdate
(
test
.
pod
)
},
if
got
!=
test
.
expected
{
}
t
.
Errorf
(
"skipPodUpdate() = %t, expected = %t"
,
got
,
test
.
expected
)
got
:=
c
.
skipPodUpdate
(
test
.
pod
)
}
if
got
!=
test
.
expected
{
t
.
Errorf
(
"skipPodUpdate() = %t, expected = %t"
,
got
,
test
.
expected
)
}
})
}
}
}
}
...
@@ -593,24 +612,22 @@ func (f *fakeExtender) IsInterested(pod *v1.Pod) bool {
...
@@ -593,24 +612,22 @@ func (f *fakeExtender) IsInterested(pod *v1.Pod) bool {
}
}
func
TestGetBinderFunc
(
t
*
testing
.
T
)
{
func
TestGetBinderFunc
(
t
*
testing
.
T
)
{
for
_
,
test
:=
range
[]
struct
{
table
:=
[]
struct
{
podName
string
podName
string
extenders
[]
algorithm
.
SchedulerExtender
extenders
[]
algorithm
.
SchedulerExtender
expectedBinderType
string
expectedBinderType
string
name
string
}{
}{
// Expect to return the default binder because the extender is not a
// binder, even though it's interested in the pod.
{
{
name
:
"the extender is not a binder"
,
podName
:
"pod0"
,
podName
:
"pod0"
,
extenders
:
[]
algorithm
.
SchedulerExtender
{
extenders
:
[]
algorithm
.
SchedulerExtender
{
&
fakeExtender
{
isBinder
:
false
,
interestedPodName
:
"pod0"
},
&
fakeExtender
{
isBinder
:
false
,
interestedPodName
:
"pod0"
},
},
},
expectedBinderType
:
"*factory.binder"
,
expectedBinderType
:
"*factory.binder"
,
},
},
// Expect to return the fake binder because one of the extenders is a
// binder and it's interested in the pod.
{
{
name
:
"one of the extenders is a binder and interested in pod"
,
podName
:
"pod0"
,
podName
:
"pod0"
,
extenders
:
[]
algorithm
.
SchedulerExtender
{
extenders
:
[]
algorithm
.
SchedulerExtender
{
&
fakeExtender
{
isBinder
:
false
,
interestedPodName
:
"pod0"
},
&
fakeExtender
{
isBinder
:
false
,
interestedPodName
:
"pod0"
},
...
@@ -618,9 +635,8 @@ func TestGetBinderFunc(t *testing.T) {
...
@@ -618,9 +635,8 @@ func TestGetBinderFunc(t *testing.T) {
},
},
expectedBinderType
:
"*factory.fakeExtender"
,
expectedBinderType
:
"*factory.fakeExtender"
,
},
},
// Expect to return the default binder because one of the extenders is
// a binder but the binder is not interested in the pod.
{
{
name
:
"one of the extenders is a binder, but not interested in pod"
,
podName
:
"pod1"
,
podName
:
"pod1"
,
extenders
:
[]
algorithm
.
SchedulerExtender
{
extenders
:
[]
algorithm
.
SchedulerExtender
{
&
fakeExtender
{
isBinder
:
false
,
interestedPodName
:
"pod1"
},
&
fakeExtender
{
isBinder
:
false
,
interestedPodName
:
"pod1"
},
...
@@ -628,20 +644,28 @@ func TestGetBinderFunc(t *testing.T) {
...
@@ -628,20 +644,28 @@ func TestGetBinderFunc(t *testing.T) {
},
},
expectedBinderType
:
"*factory.binder"
,
expectedBinderType
:
"*factory.binder"
,
},
},
}
{
}
pod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
for
_
,
test
:=
range
table
{
Name
:
test
.
podName
,
t
.
Run
(
test
.
name
,
func
(
t
*
testing
.
T
)
{
},
testGetBinderFunc
(
test
.
expectedBinderType
,
test
.
podName
,
test
.
extenders
,
t
)
}
})
}
}
f
:=
&
configFactory
{}
func
testGetBinderFunc
(
expectedBinderType
,
podName
string
,
extenders
[]
algorithm
.
SchedulerExtender
,
t
*
testing
.
T
)
{
binderFunc
:=
f
.
getBinderFunc
(
test
.
extenders
)
pod
:=
&
v1
.
Pod
{
binder
:=
binderFunc
(
pod
)
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
podName
,
},
}
binderType
:=
fmt
.
Sprintf
(
"%s"
,
reflect
.
TypeOf
(
binder
))
f
:=
&
configFactory
{}
if
binderType
!=
test
.
expectedBinderType
{
binderFunc
:=
f
.
getBinderFunc
(
extenders
)
t
.
Errorf
(
"Expected binder %q but got %q"
,
test
.
expectedBinderType
,
binderType
)
binder
:=
binderFunc
(
pod
)
}
binderType
:=
fmt
.
Sprintf
(
"%s"
,
reflect
.
TypeOf
(
binder
))
if
binderType
!=
expectedBinderType
{
t
.
Errorf
(
"Expected binder %q but got %q"
,
expectedBinderType
,
binderType
)
}
}
}
}
pkg/scheduler/factory/plugins_test.go
View file @
c6379cef
...
@@ -34,14 +34,18 @@ func TestAlgorithmNameValidation(t *testing.T) {
...
@@ -34,14 +34,18 @@ func TestAlgorithmNameValidation(t *testing.T) {
"Some,Alg:orithm"
,
"Some,Alg:orithm"
,
}
}
for
_
,
name
:=
range
algorithmNamesShouldValidate
{
for
_
,
name
:=
range
algorithmNamesShouldValidate
{
if
!
validName
.
MatchString
(
name
)
{
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
t
.
Errorf
(
"%v should be a valid algorithm name but is not valid."
,
name
)
if
!
validName
.
MatchString
(
name
)
{
}
t
.
Errorf
(
"should be a valid algorithm name but is not valid."
)
}
})
}
}
for
_
,
name
:=
range
algorithmNamesShouldNotValidate
{
for
_
,
name
:=
range
algorithmNamesShouldNotValidate
{
if
validName
.
MatchString
(
name
)
{
t
.
Run
(
name
,
func
(
t
*
testing
.
T
)
{
t
.
Errorf
(
"%v should be an invalid algorithm name but is valid."
,
name
)
if
validName
.
MatchString
(
name
)
{
}
t
.
Errorf
(
"should be an invalid algorithm name but is valid."
)
}
})
}
}
}
}
...
@@ -68,15 +72,17 @@ func TestValidatePriorityConfigOverFlow(t *testing.T) {
...
@@ -68,15 +72,17 @@ func TestValidatePriorityConfigOverFlow(t *testing.T) {
},
},
}
}
for
_
,
test
:=
range
tests
{
for
_
,
test
:=
range
tests
{
err
:=
validateSelectedConfigs
(
test
.
configs
)
t
.
Run
(
test
.
description
,
func
(
t
*
testing
.
T
)
{
if
test
.
expected
{
err
:=
validateSelectedConfigs
(
test
.
configs
)
if
err
==
nil
{
if
test
.
expected
{
t
.
Errorf
(
"Expected Overflow for %s"
,
test
.
description
)
if
err
==
nil
{
}
t
.
Errorf
(
"Expected Overflow"
)
}
else
{
}
if
err
!=
nil
{
}
else
{
t
.
Errorf
(
"Did not expect an overflow for %s"
,
test
.
description
)
if
err
!=
nil
{
t
.
Errorf
(
"Did not expect an overflow"
)
}
}
}
}
}
)
}
}
}
}
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