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
060218a8
Unverified
Commit
060218a8
authored
Oct 15, 2018
by
k8s-ci-robot
Committed by
GitHub
Oct 15, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #69412 from tossmilestone/scheduler-factory-test
Refactor scheduler factory test
parents
b11211ed
a96a390d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
100 deletions
+73
-100
logsforobject_test.go
pkg/kubectl/polymorphichelpers/logsforobject_test.go
+1
-1
BUILD
pkg/scheduler/factory/BUILD
+3
-3
factory_test.go
pkg/scheduler/factory/factory_test.go
+56
-94
fake_pod_expansion.go
...nt-go/kubernetes/typed/core/v1/fake/fake_pod_expansion.go
+13
-2
No files found.
pkg/kubectl/polymorphichelpers/logsforobject_test.go
View file @
060218a8
...
...
@@ -253,7 +253,7 @@ func getLogsAction(namespace string, opts *corev1.PodLogOptions) testclient.Acti
action
.
Verb
=
"get"
action
.
Namespace
=
namespace
action
.
Resource
=
podsResource
action
.
Subresource
=
"log
s
"
action
.
Subresource
=
"log"
action
.
Value
=
opts
return
action
}
pkg/scheduler/factory/BUILD
View file @
060218a8
...
...
@@ -74,13 +74,13 @@ go_test(
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/client-go/informers:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
"//staging/src/k8s.io/client-go/rest:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
"//staging/src/k8s.io/client-go/kubernetes/typed/core/v1/fake:go_default_library",
"//staging/src/k8s.io/client-go/testing:go_default_library",
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
"//staging/src/k8s.io/client-go/util/testing:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
)
...
...
pkg/scheduler/factory/factory_test.go
View file @
060218a8
...
...
@@ -19,8 +19,6 @@ package factory
import
(
"errors"
"fmt"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"time"
...
...
@@ -28,13 +26,13 @@ import (
"k8s.io/api/core/v1"
metav1
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/client-go/informers"
clientset
"k8s.io/client-go/kubernetes"
restclient
"k8s.io/client-go/rest"
"k8s.io/client-go/kubernetes/fake"
fakeV1
"k8s.io/client-go/kubernetes/typed/core/v1/fake"
clienttesting
"k8s.io/client-go/testing"
"k8s.io/client-go/tools/cache"
utiltesting
"k8s.io/client-go/util/testing"
apitesting
"k8s.io/kubernetes/pkg/api/testing"
"k8s.io/kubernetes/pkg/scheduler/algorithm"
schedulerapi
"k8s.io/kubernetes/pkg/scheduler/api"
...
...
@@ -53,14 +51,7 @@ const (
)
func
TestCreate
(
t
*
testing
.
T
)
{
handler
:=
utiltesting
.
FakeHandler
{
StatusCode
:
500
,
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"
}}})
client
:=
fake
.
NewSimpleClientset
()
factory
:=
newConfigFactory
(
client
,
v1
.
DefaultHardPodAffinitySymmetricWeight
)
factory
.
Create
()
}
...
...
@@ -71,14 +62,7 @@ func TestCreateFromConfig(t *testing.T) {
var
configData
[]
byte
var
policy
schedulerapi
.
Policy
handler
:=
utiltesting
.
FakeHandler
{
StatusCode
:
500
,
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"
}}})
client
:=
fake
.
NewSimpleClientset
()
factory
:=
newConfigFactory
(
client
,
v1
.
DefaultHardPodAffinitySymmetricWeight
)
// Pre-register some predicate and priority functions
...
...
@@ -116,14 +100,7 @@ func TestCreateFromConfigWithHardPodAffinitySymmetricWeight(t *testing.T) {
var
configData
[]
byte
var
policy
schedulerapi
.
Policy
handler
:=
utiltesting
.
FakeHandler
{
StatusCode
:
500
,
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"
}}})
client
:=
fake
.
NewSimpleClientset
()
factory
:=
newConfigFactory
(
client
,
v1
.
DefaultHardPodAffinitySymmetricWeight
)
// Pre-register some predicate and priority functions
...
...
@@ -162,14 +139,7 @@ func TestCreateFromEmptyConfig(t *testing.T) {
var
configData
[]
byte
var
policy
schedulerapi
.
Policy
handler
:=
utiltesting
.
FakeHandler
{
StatusCode
:
500
,
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"
}}})
client
:=
fake
.
NewSimpleClientset
()
factory
:=
newConfigFactory
(
client
,
v1
.
DefaultHardPodAffinitySymmetricWeight
)
configData
=
[]
byte
(
`{}`
)
...
...
@@ -184,14 +154,7 @@ func TestCreateFromEmptyConfig(t *testing.T) {
// predicate/priority.
// The predicate/priority from DefaultProvider will be used.
func
TestCreateFromConfigWithUnspecifiedPredicatesOrPriorities
(
t
*
testing
.
T
)
{
handler
:=
utiltesting
.
FakeHandler
{
StatusCode
:
500
,
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"
}}})
client
:=
fake
.
NewSimpleClientset
()
factory
:=
newConfigFactory
(
client
,
v1
.
DefaultHardPodAffinitySymmetricWeight
)
RegisterFitPredicate
(
"PredicateOne"
,
PredicateOne
)
...
...
@@ -224,14 +187,7 @@ func TestCreateFromConfigWithUnspecifiedPredicatesOrPriorities(t *testing.T) {
// predicate/priority.
// Empty predicate/priority sets will be used.
func
TestCreateFromConfigWithEmptyPredicatesOrPriorities
(
t
*
testing
.
T
)
{
handler
:=
utiltesting
.
FakeHandler
{
StatusCode
:
500
,
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"
}}})
client
:=
fake
.
NewSimpleClientset
()
factory
:=
newConfigFactory
(
client
,
v1
.
DefaultHardPodAffinitySymmetricWeight
)
RegisterFitPredicate
(
"PredicateOne"
,
PredicateOne
)
...
...
@@ -283,24 +239,14 @@ func TestDefaultErrorFunc(t *testing.T) {
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
"foo"
,
Namespace
:
"bar"
},
Spec
:
apitesting
.
V1DeepEqualSafePodSpec
(),
}
handler
:=
utiltesting
.
FakeHandler
{
StatusCode
:
200
,
ResponseBody
:
runtime
.
EncodeOrDie
(
schedulertesting
.
Test
.
Codec
(),
testPod
),
T
:
t
,
}
mux
:=
http
.
NewServeMux
()
// FakeHandler mustn't be sent requests other than the one you want to test.
mux
.
Handle
(
schedulertesting
.
Test
.
ResourcePath
(
string
(
v1
.
ResourcePods
),
"bar"
,
"foo"
),
&
handler
)
server
:=
httptest
.
NewServer
(
mux
)
defer
server
.
Close
()
client
:=
clientset
.
NewForConfigOrDie
(
&
restclient
.
Config
{
Host
:
server
.
URL
,
ContentConfig
:
restclient
.
ContentConfig
{
GroupVersion
:
&
schema
.
GroupVersion
{
Group
:
""
,
Version
:
"v1"
}}})
client
:=
fake
.
NewSimpleClientset
(
&
v1
.
PodList
{
Items
:
[]
v1
.
Pod
{
*
testPod
}})
factory
:=
newConfigFactory
(
client
,
v1
.
DefaultHardPodAffinitySymmetricWeight
)
queue
:=
&
internalqueue
.
FIFO
{
FIFO
:
cache
.
NewFIFO
(
cache
.
MetaNamespaceKeyFunc
)}
podBackoff
:=
util
.
CreatePodBackoff
(
1
*
time
.
Millisecond
,
1
*
time
.
Second
)
errFunc
:=
factory
.
MakeDefaultErrorFunc
(
podBackoff
,
queue
)
errFunc
(
testPod
,
nil
)
for
{
// This is a terrible way to do this but I plan on replacing this
// whole error handling system in the future. The test will time
...
...
@@ -310,7 +256,27 @@ func TestDefaultErrorFunc(t *testing.T) {
if
!
exists
{
continue
}
handler
.
ValidateRequest
(
t
,
schedulertesting
.
Test
.
ResourcePath
(
string
(
v1
.
ResourcePods
),
"bar"
,
"foo"
),
"GET"
,
nil
)
requestReceived
:=
false
actions
:=
client
.
Actions
()
for
_
,
a
:=
range
actions
{
if
a
.
GetVerb
()
==
"get"
{
getAction
,
ok
:=
a
.
(
clienttesting
.
GetAction
)
if
!
ok
{
t
.
Errorf
(
"Can't cast action object to GetAction interface"
)
break
}
name
:=
getAction
.
GetName
()
ns
:=
a
.
GetNamespace
()
if
name
!=
"foo"
||
ns
!=
"bar"
{
t
.
Errorf
(
"Expected name %s namespace %s, got %s %s"
,
"foo"
,
"bar"
,
name
,
ns
)
}
requestReceived
=
true
}
}
if
!
requestReceived
{
t
.
Errorf
(
"Get pod request not received"
)
}
if
e
,
a
:=
testPod
,
got
;
!
reflect
.
DeepEqual
(
e
,
a
)
{
t
.
Errorf
(
"Expected %v, got %v"
,
e
,
a
)
}
...
...
@@ -371,35 +337,38 @@ func TestBind(t *testing.T) {
}
func
testBind
(
binding
*
v1
.
Binding
,
t
*
testing
.
T
)
{
handler
:=
utiltesting
.
FakeHandler
{
StatusCode
:
200
,
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"
}}})
testPod
:=
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
binding
.
GetName
(),
Namespace
:
metav1
.
NamespaceDefault
},
Spec
:
apitesting
.
V1DeepEqualSafePodSpec
(),
}
client
:=
fake
.
NewSimpleClientset
(
&
v1
.
PodList
{
Items
:
[]
v1
.
Pod
{
*
testPod
}})
b
:=
binder
{
client
}
if
err
:=
b
.
Bind
(
binding
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error: %v"
,
err
)
return
}
pod
:=
client
.
CoreV1
()
.
Pods
(
metav1
.
NamespaceDefault
)
.
(
*
fakeV1
.
FakePods
)
bind
,
err
:=
pod
.
GetBinding
(
binding
.
GetName
())
if
err
!=
nil
{
t
.
Fatalf
(
"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
)
bind
.
APIVersion
=
""
bind
.
Kind
=
""
body
:=
runtime
.
EncodeOrDie
(
schedulertesting
.
Test
.
Codec
(),
bind
)
if
expectedBody
!=
body
{
t
.
Errorf
(
"Expected body %s, Got %s"
,
expectedBody
,
body
)
}
}
func
TestInvalidHardPodAffinitySymmetricWeight
(
t
*
testing
.
T
)
{
handler
:=
utiltesting
.
FakeHandler
{
StatusCode
:
500
,
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"
}}})
client
:=
fake
.
NewSimpleClientset
()
// factory of "default-scheduler"
factory
:=
newConfigFactory
(
client
,
-
1
)
_
,
err
:=
factory
.
Create
()
...
...
@@ -409,14 +378,7 @@ func TestInvalidHardPodAffinitySymmetricWeight(t *testing.T) {
}
func
TestInvalidFactoryArgs
(
t
*
testing
.
T
)
{
handler
:=
utiltesting
.
FakeHandler
{
StatusCode
:
500
,
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"
}}})
client
:=
fake
.
NewSimpleClientset
()
testCases
:=
[]
struct
{
name
string
...
...
@@ -539,7 +501,7 @@ func TestSkipPodUpdate(t *testing.T) {
}
}
func
newConfigFactory
(
client
*
clientset
.
Clientset
,
hardPodAffinitySymmetricWeight
int32
)
Configurator
{
func
newConfigFactory
(
client
clientset
.
Interface
,
hardPodAffinitySymmetricWeight
int32
)
Configurator
{
informerFactory
:=
informers
.
NewSharedInformerFactory
(
client
,
0
)
return
NewConfigFactory
(
&
ConfigFactoryArgs
{
v1
.
DefaultSchedulerName
,
...
...
staging/src/k8s.io/client-go/kubernetes/typed/core/v1/fake/fake_pod_expansion.go
View file @
060218a8
...
...
@@ -26,20 +26,31 @@ import (
func
(
c
*
FakePods
)
Bind
(
binding
*
v1
.
Binding
)
error
{
action
:=
core
.
CreateActionImpl
{}
action
.
Verb
=
"create"
action
.
Namespace
=
binding
.
Namespace
action
.
Resource
=
podsResource
action
.
Subresource
=
"binding
s
"
action
.
Subresource
=
"binding"
action
.
Object
=
binding
_
,
err
:=
c
.
Fake
.
Invokes
(
action
,
binding
)
return
err
}
func
(
c
*
FakePods
)
GetBinding
(
name
string
)
(
result
*
v1
.
Binding
,
err
error
)
{
obj
,
err
:=
c
.
Fake
.
Invokes
(
core
.
NewGetSubresourceAction
(
podsResource
,
c
.
ns
,
"binding"
,
name
),
&
v1
.
Binding
{})
if
obj
==
nil
{
return
nil
,
err
}
return
obj
.
(
*
v1
.
Binding
),
err
}
func
(
c
*
FakePods
)
GetLogs
(
name
string
,
opts
*
v1
.
PodLogOptions
)
*
restclient
.
Request
{
action
:=
core
.
GenericActionImpl
{}
action
.
Verb
=
"get"
action
.
Namespace
=
c
.
ns
action
.
Resource
=
podsResource
action
.
Subresource
=
"log
s
"
action
.
Subresource
=
"log"
action
.
Value
=
opts
_
,
_
=
c
.
Fake
.
Invokes
(
action
,
&
v1
.
Pod
{})
...
...
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