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
2da7e8d4
Commit
2da7e8d4
authored
Sep 25, 2015
by
Brian Grant
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #14316 from mikedanese/dedup
consolidate a bunch of FakePodControl testclients into a shared one
parents
a0872fbd
824768d6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
168 deletions
+100
-168
controller_utils.go
pkg/controller/controller_utils.go
+50
-2
controller_test.go
pkg/controller/daemon/controller_test.go
+8
-47
controller_test.go
pkg/controller/job/controller_test.go
+16
-55
replication_controller_test.go
pkg/controller/replication/replication_controller_test.go
+26
-64
No files found.
pkg/controller/controller_utils.go
View file @
2da7e8d4
...
@@ -18,9 +18,9 @@ package controller
...
@@ -18,9 +18,9 @@ package controller
import
(
import
(
"fmt"
"fmt"
"time"
"sync"
"sync/atomic"
"sync/atomic"
"time"
"github.com/golang/glog"
"github.com/golang/glog"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
@@ -226,6 +226,8 @@ type RealPodControl struct {
...
@@ -226,6 +226,8 @@ type RealPodControl struct {
Recorder
record
.
EventRecorder
Recorder
record
.
EventRecorder
}
}
var
_
PodControlInterface
=
&
RealPodControl
{}
func
getPodsLabelSet
(
template
*
api
.
PodTemplateSpec
)
labels
.
Set
{
func
getPodsLabelSet
(
template
*
api
.
PodTemplateSpec
)
labels
.
Set
{
desiredLabels
:=
make
(
labels
.
Set
)
desiredLabels
:=
make
(
labels
.
Set
)
for
k
,
v
:=
range
template
.
Labels
{
for
k
,
v
:=
range
template
.
Labels
{
...
@@ -312,6 +314,52 @@ func (r RealPodControl) DeletePod(namespace, podID string) error {
...
@@ -312,6 +314,52 @@ func (r RealPodControl) DeletePod(namespace, podID string) error {
return
r
.
KubeClient
.
Pods
(
namespace
)
.
Delete
(
podID
,
nil
)
return
r
.
KubeClient
.
Pods
(
namespace
)
.
Delete
(
podID
,
nil
)
}
}
type
FakePodControl
struct
{
sync
.
Mutex
Templates
[]
api
.
PodTemplateSpec
DeletePodName
[]
string
Err
error
}
var
_
PodControlInterface
=
&
FakePodControl
{}
func
(
f
*
FakePodControl
)
CreatePods
(
namespace
string
,
spec
*
api
.
PodTemplateSpec
,
object
runtime
.
Object
)
error
{
f
.
Lock
()
defer
f
.
Unlock
()
if
f
.
Err
!=
nil
{
return
f
.
Err
}
f
.
Templates
=
append
(
f
.
Templates
,
*
spec
)
return
nil
}
func
(
f
*
FakePodControl
)
CreatePodsOnNode
(
nodeName
,
namespace
string
,
template
*
api
.
PodTemplateSpec
,
object
runtime
.
Object
)
error
{
f
.
Lock
()
defer
f
.
Unlock
()
if
f
.
Err
!=
nil
{
return
f
.
Err
}
f
.
Templates
=
append
(
f
.
Templates
,
*
template
)
return
nil
}
func
(
f
*
FakePodControl
)
DeletePod
(
namespace
string
,
podName
string
)
error
{
f
.
Lock
()
defer
f
.
Unlock
()
if
f
.
Err
!=
nil
{
return
f
.
Err
}
f
.
DeletePodName
=
append
(
f
.
DeletePodName
,
podName
)
return
nil
}
func
(
f
*
FakePodControl
)
Clear
()
{
f
.
Lock
()
defer
f
.
Unlock
()
f
.
DeletePodName
=
[]
string
{}
f
.
Templates
=
[]
api
.
PodTemplateSpec
{}
}
// ActivePods type allows custom sorting of pods so a controller can pick the best ones to delete.
// ActivePods type allows custom sorting of pods so a controller can pick the best ones to delete.
type
ActivePods
[]
*
api
.
Pod
type
ActivePods
[]
*
api
.
Pod
...
...
pkg/controller/daemon/controller_test.go
View file @
2da7e8d4
...
@@ -18,7 +18,6 @@ package daemon
...
@@ -18,7 +18,6 @@ package daemon
import
(
import
(
"fmt"
"fmt"
"sync"
"testing"
"testing"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
...
@@ -28,7 +27,6 @@ import (
...
@@ -28,7 +27,6 @@ import (
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/client/cache"
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/securitycontext"
"k8s.io/kubernetes/pkg/securitycontext"
)
)
...
@@ -39,47 +37,10 @@ var (
...
@@ -39,47 +37,10 @@ var (
simpleNodeLabel2
=
map
[
string
]
string
{
"color"
:
"red"
,
"speed"
:
"fast"
}
simpleNodeLabel2
=
map
[
string
]
string
{
"color"
:
"red"
,
"speed"
:
"fast"
}
)
)
type
FakePodControl
struct
{
podSpec
[]
api
.
PodTemplateSpec
deletePodName
[]
string
lock
sync
.
Mutex
err
error
}
func
init
()
{
func
init
()
{
api
.
ForTesting_ReferencesAllowBlankSelfLinks
=
true
api
.
ForTesting_ReferencesAllowBlankSelfLinks
=
true
}
}
func
(
f
*
FakePodControl
)
CreatePods
(
namespace
string
,
spec
*
api
.
PodTemplateSpec
,
object
runtime
.
Object
)
error
{
return
nil
}
func
(
f
*
FakePodControl
)
CreatePodsOnNode
(
nodeName
,
namespace
string
,
spec
*
api
.
PodTemplateSpec
,
object
runtime
.
Object
)
error
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
if
f
.
err
!=
nil
{
return
f
.
err
}
f
.
podSpec
=
append
(
f
.
podSpec
,
*
spec
)
return
nil
}
func
(
f
*
FakePodControl
)
DeletePod
(
namespace
string
,
podName
string
)
error
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
if
f
.
err
!=
nil
{
return
f
.
err
}
f
.
deletePodName
=
append
(
f
.
deletePodName
,
podName
)
return
nil
}
func
(
f
*
FakePodControl
)
clear
()
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
f
.
deletePodName
=
[]
string
{}
f
.
podSpec
=
[]
api
.
PodTemplateSpec
{}
}
func
newDaemonSet
(
name
string
)
*
experimental
.
DaemonSet
{
func
newDaemonSet
(
name
string
)
*
experimental
.
DaemonSet
{
return
&
experimental
.
DaemonSet
{
return
&
experimental
.
DaemonSet
{
TypeMeta
:
unversioned
.
TypeMeta
{
APIVersion
:
testapi
.
Experimental
.
Version
()},
TypeMeta
:
unversioned
.
TypeMeta
{
APIVersion
:
testapi
.
Experimental
.
Version
()},
...
@@ -157,24 +118,24 @@ func addPods(podStore cache.Store, nodeName string, label map[string]string, num
...
@@ -157,24 +118,24 @@ func addPods(podStore cache.Store, nodeName string, label map[string]string, num
}
}
}
}
func
newTestController
()
(
*
DaemonSetsController
,
*
FakePodControl
)
{
func
newTestController
()
(
*
DaemonSetsController
,
*
controller
.
FakePodControl
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
GroupAndVersion
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
GroupAndVersion
()})
manager
:=
NewDaemonSetsController
(
client
)
manager
:=
NewDaemonSetsController
(
client
)
podControl
:=
&
FakePodControl
{}
podControl
:=
&
controller
.
FakePodControl
{}
manager
.
podControl
=
podControl
manager
.
podControl
=
podControl
return
manager
,
podControl
return
manager
,
podControl
}
}
func
validateSyncDaemonSets
(
t
*
testing
.
T
,
fakePodControl
*
FakePodControl
,
expectedCreates
,
expectedDeletes
int
)
{
func
validateSyncDaemonSets
(
t
*
testing
.
T
,
fakePodControl
*
controller
.
FakePodControl
,
expectedCreates
,
expectedDeletes
int
)
{
if
len
(
fakePodControl
.
podSpec
)
!=
expectedCreates
{
if
len
(
fakePodControl
.
Templates
)
!=
expectedCreates
{
t
.
Errorf
(
"Unexpected number of creates. Expected %d, saw %d
\n
"
,
expectedCreates
,
len
(
fakePodControl
.
podSpec
))
t
.
Errorf
(
"Unexpected number of creates. Expected %d, saw %d
\n
"
,
expectedCreates
,
len
(
fakePodControl
.
Templates
))
}
}
if
len
(
fakePodControl
.
d
eletePodName
)
!=
expectedDeletes
{
if
len
(
fakePodControl
.
D
eletePodName
)
!=
expectedDeletes
{
t
.
Errorf
(
"Unexpected number of deletes. Expected %d, saw %d
\n
"
,
expectedDeletes
,
len
(
fakePodControl
.
d
eletePodName
))
t
.
Errorf
(
"Unexpected number of deletes. Expected %d, saw %d
\n
"
,
expectedDeletes
,
len
(
fakePodControl
.
D
eletePodName
))
}
}
}
}
func
syncAndValidateDaemonSets
(
t
*
testing
.
T
,
manager
*
DaemonSetsController
,
ds
*
experimental
.
DaemonSet
,
podControl
*
FakePodControl
,
expectedCreates
,
expectedDeletes
int
)
{
func
syncAndValidateDaemonSets
(
t
*
testing
.
T
,
manager
*
DaemonSetsController
,
ds
*
experimental
.
DaemonSet
,
podControl
*
controller
.
FakePodControl
,
expectedCreates
,
expectedDeletes
int
)
{
key
,
err
:=
controller
.
KeyFunc
(
ds
)
key
,
err
:=
controller
.
KeyFunc
(
ds
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Could not get key for daemon."
)
t
.
Errorf
(
"Could not get key for daemon."
)
...
...
pkg/controller/job/controller_test.go
View file @
2da7e8d4
...
@@ -18,7 +18,6 @@ package job
...
@@ -18,7 +18,6 @@ package job
import
(
import
(
"fmt"
"fmt"
"sync"
"testing"
"testing"
"time"
"time"
...
@@ -29,7 +28,6 @@ import (
...
@@ -29,7 +28,6 @@ import (
client
"k8s.io/kubernetes/pkg/client/unversioned"
client
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/controller"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/pkg/watch"
)
)
...
@@ -42,43 +40,6 @@ const controllerTimeout = 500 * time.Millisecond
...
@@ -42,43 +40,6 @@ const controllerTimeout = 500 * time.Millisecond
var
alwaysReady
=
func
()
bool
{
return
true
}
var
alwaysReady
=
func
()
bool
{
return
true
}
type
FakePodControl
struct
{
podSpec
[]
api
.
PodTemplateSpec
deletePodName
[]
string
lock
sync
.
Mutex
err
error
}
func
(
f
*
FakePodControl
)
CreatePods
(
namespace
string
,
spec
*
api
.
PodTemplateSpec
,
object
runtime
.
Object
)
error
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
if
f
.
err
!=
nil
{
return
f
.
err
}
f
.
podSpec
=
append
(
f
.
podSpec
,
*
spec
)
return
nil
}
func
(
f
*
FakePodControl
)
CreatePodsOnNode
(
nodeName
,
namespace
string
,
template
*
api
.
PodTemplateSpec
,
object
runtime
.
Object
)
error
{
return
nil
}
func
(
f
*
FakePodControl
)
DeletePod
(
namespace
string
,
podName
string
)
error
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
if
f
.
err
!=
nil
{
return
f
.
err
}
f
.
deletePodName
=
append
(
f
.
deletePodName
,
podName
)
return
nil
}
func
(
f
*
FakePodControl
)
clear
()
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
f
.
deletePodName
=
[]
string
{}
f
.
podSpec
=
[]
api
.
PodTemplateSpec
{}
}
func
newJob
(
parallelism
,
completions
int
)
*
experimental
.
Job
{
func
newJob
(
parallelism
,
completions
int
)
*
experimental
.
Job
{
return
&
experimental
.
Job
{
return
&
experimental
.
Job
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
...
@@ -207,7 +168,7 @@ func TestControllerSyncJob(t *testing.T) {
...
@@ -207,7 +168,7 @@ func TestControllerSyncJob(t *testing.T) {
// job manager setup
// job manager setup
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
GroupAndVersion
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
GroupAndVersion
()})
manager
:=
NewJobController
(
client
)
manager
:=
NewJobController
(
client
)
fakePodControl
:=
FakePodControl
{
e
rr
:
tc
.
podControllerError
}
fakePodControl
:=
controller
.
FakePodControl
{
E
rr
:
tc
.
podControllerError
}
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
var
actual
*
experimental
.
Job
var
actual
*
experimental
.
Job
...
@@ -236,11 +197,11 @@ func TestControllerSyncJob(t *testing.T) {
...
@@ -236,11 +197,11 @@ func TestControllerSyncJob(t *testing.T) {
}
}
// validate created/deleted pods
// validate created/deleted pods
if
len
(
fakePodControl
.
podSpec
)
!=
tc
.
expectedCreations
{
if
len
(
fakePodControl
.
Templates
)
!=
tc
.
expectedCreations
{
t
.
Errorf
(
"%s: unexpected number of creates. Expected %d, saw %d
\n
"
,
name
,
tc
.
expectedCreations
,
len
(
fakePodControl
.
podSpec
))
t
.
Errorf
(
"%s: unexpected number of creates. Expected %d, saw %d
\n
"
,
name
,
tc
.
expectedCreations
,
len
(
fakePodControl
.
Templates
))
}
}
if
len
(
fakePodControl
.
d
eletePodName
)
!=
tc
.
expectedDeletions
{
if
len
(
fakePodControl
.
D
eletePodName
)
!=
tc
.
expectedDeletions
{
t
.
Errorf
(
"%s: unexpected number of deletes. Expected %d, saw %d
\n
"
,
name
,
tc
.
expectedDeletions
,
len
(
fakePodControl
.
d
eletePodName
))
t
.
Errorf
(
"%s: unexpected number of deletes. Expected %d, saw %d
\n
"
,
name
,
tc
.
expectedDeletions
,
len
(
fakePodControl
.
D
eletePodName
))
}
}
// validate status
// validate status
if
actual
.
Status
.
Active
!=
tc
.
expectedActive
{
if
actual
.
Status
.
Active
!=
tc
.
expectedActive
{
...
@@ -271,7 +232,7 @@ func TestControllerSyncJob(t *testing.T) {
...
@@ -271,7 +232,7 @@ func TestControllerSyncJob(t *testing.T) {
func
TestSyncJobDeleted
(
t
*
testing
.
T
)
{
func
TestSyncJobDeleted
(
t
*
testing
.
T
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
GroupAndVersion
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
GroupAndVersion
()})
manager
:=
NewJobController
(
client
)
manager
:=
NewJobController
(
client
)
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
manager
.
updateHandler
=
func
(
job
*
experimental
.
Job
)
error
{
return
nil
}
manager
.
updateHandler
=
func
(
job
*
experimental
.
Job
)
error
{
return
nil
}
...
@@ -280,18 +241,18 @@ func TestSyncJobDeleted(t *testing.T) {
...
@@ -280,18 +241,18 @@ func TestSyncJobDeleted(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"Unexpected error when syncing jobs %v"
,
err
)
t
.
Errorf
(
"Unexpected error when syncing jobs %v"
,
err
)
}
}
if
len
(
fakePodControl
.
podSpec
)
!=
0
{
if
len
(
fakePodControl
.
Templates
)
!=
0
{
t
.
Errorf
(
"Unexpected number of creates. Expected %d, saw %d
\n
"
,
0
,
len
(
fakePodControl
.
podSpec
))
t
.
Errorf
(
"Unexpected number of creates. Expected %d, saw %d
\n
"
,
0
,
len
(
fakePodControl
.
Templates
))
}
}
if
len
(
fakePodControl
.
d
eletePodName
)
!=
0
{
if
len
(
fakePodControl
.
D
eletePodName
)
!=
0
{
t
.
Errorf
(
"Unexpected number of deletes. Expected %d, saw %d
\n
"
,
0
,
len
(
fakePodControl
.
d
eletePodName
))
t
.
Errorf
(
"Unexpected number of deletes. Expected %d, saw %d
\n
"
,
0
,
len
(
fakePodControl
.
D
eletePodName
))
}
}
}
}
func
TestSyncJobUpdateRequeue
(
t
*
testing
.
T
)
{
func
TestSyncJobUpdateRequeue
(
t
*
testing
.
T
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
GroupAndVersion
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
GroupAndVersion
()})
manager
:=
NewJobController
(
client
)
manager
:=
NewJobController
(
client
)
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
manager
.
updateHandler
=
func
(
job
*
experimental
.
Job
)
error
{
return
fmt
.
Errorf
(
"Fake error"
)
}
manager
.
updateHandler
=
func
(
job
*
experimental
.
Job
)
error
{
return
fmt
.
Errorf
(
"Fake error"
)
}
...
@@ -401,7 +362,7 @@ func (fe FakeJobExpectations) SatisfiedExpectations(controllerKey string) bool {
...
@@ -401,7 +362,7 @@ func (fe FakeJobExpectations) SatisfiedExpectations(controllerKey string) bool {
func
TestSyncJobExpectations
(
t
*
testing
.
T
)
{
func
TestSyncJobExpectations
(
t
*
testing
.
T
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
GroupAndVersion
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
GroupAndVersion
()})
manager
:=
NewJobController
(
client
)
manager
:=
NewJobController
(
client
)
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
manager
.
updateHandler
=
func
(
job
*
experimental
.
Job
)
error
{
return
nil
}
manager
.
updateHandler
=
func
(
job
*
experimental
.
Job
)
error
{
return
nil
}
...
@@ -420,11 +381,11 @@ func TestSyncJobExpectations(t *testing.T) {
...
@@ -420,11 +381,11 @@ func TestSyncJobExpectations(t *testing.T) {
},
},
}
}
manager
.
syncJob
(
getKey
(
job
,
t
))
manager
.
syncJob
(
getKey
(
job
,
t
))
if
len
(
fakePodControl
.
podSpec
)
!=
0
{
if
len
(
fakePodControl
.
Templates
)
!=
0
{
t
.
Errorf
(
"Unexpected number of creates. Expected %d, saw %d
\n
"
,
0
,
len
(
fakePodControl
.
podSpec
))
t
.
Errorf
(
"Unexpected number of creates. Expected %d, saw %d
\n
"
,
0
,
len
(
fakePodControl
.
Templates
))
}
}
if
len
(
fakePodControl
.
d
eletePodName
)
!=
0
{
if
len
(
fakePodControl
.
D
eletePodName
)
!=
0
{
t
.
Errorf
(
"Unexpected number of deletes. Expected %d, saw %d
\n
"
,
0
,
len
(
fakePodControl
.
d
eletePodName
))
t
.
Errorf
(
"Unexpected number of deletes. Expected %d, saw %d
\n
"
,
0
,
len
(
fakePodControl
.
D
eletePodName
))
}
}
}
}
...
...
pkg/controller/replication/replication_controller_test.go
View file @
2da7e8d4
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"fmt"
"fmt"
"math/rand"
"math/rand"
"net/http/httptest"
"net/http/httptest"
"sync"
"testing"
"testing"
"time"
"time"
...
@@ -38,49 +37,12 @@ import (
...
@@ -38,49 +37,12 @@ import (
"k8s.io/kubernetes/pkg/watch"
"k8s.io/kubernetes/pkg/watch"
)
)
type
FakePodControl
struct
{
controllerSpec
[]
api
.
PodTemplateSpec
deletePodName
[]
string
lock
sync
.
Mutex
err
error
}
var
alwaysReady
=
func
()
bool
{
return
true
}
var
alwaysReady
=
func
()
bool
{
return
true
}
func
init
()
{
func
init
()
{
api
.
ForTesting_ReferencesAllowBlankSelfLinks
=
true
api
.
ForTesting_ReferencesAllowBlankSelfLinks
=
true
}
}
func
(
f
*
FakePodControl
)
CreatePods
(
namespace
string
,
spec
*
api
.
PodTemplateSpec
,
object
runtime
.
Object
)
error
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
if
f
.
err
!=
nil
{
return
f
.
err
}
f
.
controllerSpec
=
append
(
f
.
controllerSpec
,
*
spec
)
return
nil
}
func
(
f
*
FakePodControl
)
CreatePodsOnNode
(
nodeName
,
namespace
string
,
template
*
api
.
PodTemplateSpec
,
object
runtime
.
Object
)
error
{
return
nil
}
func
(
f
*
FakePodControl
)
DeletePod
(
namespace
string
,
podName
string
)
error
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
if
f
.
err
!=
nil
{
return
f
.
err
}
f
.
deletePodName
=
append
(
f
.
deletePodName
,
podName
)
return
nil
}
func
(
f
*
FakePodControl
)
clear
()
{
f
.
lock
.
Lock
()
defer
f
.
lock
.
Unlock
()
f
.
deletePodName
=
[]
string
{}
f
.
controllerSpec
=
[]
api
.
PodTemplateSpec
{}
}
func
getKey
(
rc
*
api
.
ReplicationController
,
t
*
testing
.
T
)
string
{
func
getKey
(
rc
*
api
.
ReplicationController
,
t
*
testing
.
T
)
string
{
if
key
,
err
:=
controller
.
KeyFunc
(
rc
);
err
!=
nil
{
if
key
,
err
:=
controller
.
KeyFunc
(
rc
);
err
!=
nil
{
t
.
Errorf
(
"Unexpected error getting key for rc %v: %v"
,
rc
.
Name
,
err
)
t
.
Errorf
(
"Unexpected error getting key for rc %v: %v"
,
rc
.
Name
,
err
)
...
@@ -152,12 +114,12 @@ func newPodList(store cache.Store, count int, status api.PodPhase, rc *api.Repli
...
@@ -152,12 +114,12 @@ func newPodList(store cache.Store, count int, status api.PodPhase, rc *api.Repli
}
}
}
}
func
validateSyncReplication
(
t
*
testing
.
T
,
fakePodControl
*
FakePodControl
,
expectedCreates
,
expectedDeletes
int
)
{
func
validateSyncReplication
(
t
*
testing
.
T
,
fakePodControl
*
controller
.
FakePodControl
,
expectedCreates
,
expectedDeletes
int
)
{
if
len
(
fakePodControl
.
controllerSpec
)
!=
expectedCreates
{
if
len
(
fakePodControl
.
Templates
)
!=
expectedCreates
{
t
.
Errorf
(
"Unexpected number of creates. Expected %d, saw %d
\n
"
,
expectedCreates
,
len
(
fakePodControl
.
controllerSpec
))
t
.
Errorf
(
"Unexpected number of creates. Expected %d, saw %d
\n
"
,
expectedCreates
,
len
(
fakePodControl
.
Templates
))
}
}
if
len
(
fakePodControl
.
d
eletePodName
)
!=
expectedDeletes
{
if
len
(
fakePodControl
.
D
eletePodName
)
!=
expectedDeletes
{
t
.
Errorf
(
"Unexpected number of deletes. Expected %d, saw %d
\n
"
,
expectedDeletes
,
len
(
fakePodControl
.
d
eletePodName
))
t
.
Errorf
(
"Unexpected number of deletes. Expected %d, saw %d
\n
"
,
expectedDeletes
,
len
(
fakePodControl
.
D
eletePodName
))
}
}
}
}
...
@@ -172,7 +134,7 @@ type serverResponse struct {
...
@@ -172,7 +134,7 @@ type serverResponse struct {
func
TestSyncReplicationControllerDoesNothing
(
t
*
testing
.
T
)
{
func
TestSyncReplicationControllerDoesNothing
(
t
*
testing
.
T
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
:=
NewReplicationManager
(
client
,
BurstReplicas
)
manager
:=
NewReplicationManager
(
client
,
BurstReplicas
)
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
...
@@ -188,7 +150,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) {
...
@@ -188,7 +150,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) {
func
TestSyncReplicationControllerDeletes
(
t
*
testing
.
T
)
{
func
TestSyncReplicationControllerDeletes
(
t
*
testing
.
T
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
:=
NewReplicationManager
(
client
,
BurstReplicas
)
manager
:=
NewReplicationManager
(
client
,
BurstReplicas
)
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
...
@@ -204,7 +166,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {
...
@@ -204,7 +166,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {
func
TestDeleteFinalStateUnknown
(
t
*
testing
.
T
)
{
func
TestDeleteFinalStateUnknown
(
t
*
testing
.
T
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
:=
NewReplicationManager
(
client
,
BurstReplicas
)
manager
:=
NewReplicationManager
(
client
,
BurstReplicas
)
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
...
@@ -241,12 +203,12 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
...
@@ -241,12 +203,12 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
// A controller with 2 replicas and no pods in the store, 2 creates expected
// A controller with 2 replicas and no pods in the store, 2 creates expected
controller
:=
newReplicationController
(
2
)
rc
:=
newReplicationController
(
2
)
manager
.
rcStore
.
Store
.
Add
(
controller
)
manager
.
rcStore
.
Store
.
Add
(
rc
)
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
manager
.
syncReplicationController
(
getKey
(
controller
,
t
))
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
validateSyncReplication
(
t
,
&
fakePodControl
,
2
,
0
)
validateSyncReplication
(
t
,
&
fakePodControl
,
2
,
0
)
}
}
...
@@ -269,7 +231,7 @@ func TestStatusUpdatesWithoutReplicasChange(t *testing.T) {
...
@@ -269,7 +231,7 @@ func TestStatusUpdatesWithoutReplicasChange(t *testing.T) {
rc
.
Status
=
api
.
ReplicationControllerStatus
{
Replicas
:
activePods
}
rc
.
Status
=
api
.
ReplicationControllerStatus
{
Replicas
:
activePods
}
newPodList
(
manager
.
podStore
.
Store
,
activePods
,
api
.
PodRunning
,
rc
)
newPodList
(
manager
.
podStore
.
Store
,
activePods
,
api
.
PodRunning
,
rc
)
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
...
@@ -316,7 +278,7 @@ func TestControllerUpdateReplicas(t *testing.T) {
...
@@ -316,7 +278,7 @@ func TestControllerUpdateReplicas(t *testing.T) {
response
:=
runtime
.
EncodeOrDie
(
testapi
.
Default
.
Codec
(),
&
api
.
ReplicationController
{})
response
:=
runtime
.
EncodeOrDie
(
testapi
.
Default
.
Codec
(),
&
api
.
ReplicationController
{})
fakeHandler
.
ResponseBody
=
response
fakeHandler
.
ResponseBody
=
response
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
...
@@ -340,7 +302,7 @@ func TestSyncReplicationControllerDormancy(t *testing.T) {
...
@@ -340,7 +302,7 @@ func TestSyncReplicationControllerDormancy(t *testing.T) {
defer
testServer
.
Close
()
defer
testServer
.
Close
()
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
testServer
.
URL
,
Version
:
testapi
.
Default
.
Version
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
testServer
.
URL
,
Version
:
testapi
.
Default
.
Version
()})
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
:=
NewReplicationManager
(
client
,
BurstReplicas
)
manager
:=
NewReplicationManager
(
client
,
BurstReplicas
)
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
...
@@ -356,7 +318,7 @@ func TestSyncReplicationControllerDormancy(t *testing.T) {
...
@@ -356,7 +318,7 @@ func TestSyncReplicationControllerDormancy(t *testing.T) {
// Expectations prevents replicas but not an update on status
// Expectations prevents replicas but not an update on status
controllerSpec
.
Status
.
Replicas
=
0
controllerSpec
.
Status
.
Replicas
=
0
fakePodControl
.
c
lear
()
fakePodControl
.
C
lear
()
manager
.
syncReplicationController
(
getKey
(
controllerSpec
,
t
))
manager
.
syncReplicationController
(
getKey
(
controllerSpec
,
t
))
validateSyncReplication
(
t
,
&
fakePodControl
,
0
,
0
)
validateSyncReplication
(
t
,
&
fakePodControl
,
0
,
0
)
...
@@ -370,14 +332,14 @@ func TestSyncReplicationControllerDormancy(t *testing.T) {
...
@@ -370,14 +332,14 @@ func TestSyncReplicationControllerDormancy(t *testing.T) {
// fakePodControl error will prevent this, leaving expectations at 0, 0
// fakePodControl error will prevent this, leaving expectations at 0, 0
manager
.
expectations
.
CreationObserved
(
rcKey
)
manager
.
expectations
.
CreationObserved
(
rcKey
)
controllerSpec
.
Status
.
Replicas
=
1
controllerSpec
.
Status
.
Replicas
=
1
fakePodControl
.
c
lear
()
fakePodControl
.
C
lear
()
fakePodControl
.
e
rr
=
fmt
.
Errorf
(
"Fake Error"
)
fakePodControl
.
E
rr
=
fmt
.
Errorf
(
"Fake Error"
)
manager
.
syncReplicationController
(
getKey
(
controllerSpec
,
t
))
manager
.
syncReplicationController
(
getKey
(
controllerSpec
,
t
))
validateSyncReplication
(
t
,
&
fakePodControl
,
0
,
0
)
validateSyncReplication
(
t
,
&
fakePodControl
,
0
,
0
)
// This replica should not need a Lowering of expectations, since the previous create failed
// This replica should not need a Lowering of expectations, since the previous create failed
fakePodControl
.
e
rr
=
nil
fakePodControl
.
E
rr
=
nil
manager
.
syncReplicationController
(
getKey
(
controllerSpec
,
t
))
manager
.
syncReplicationController
(
getKey
(
controllerSpec
,
t
))
validateSyncReplication
(
t
,
&
fakePodControl
,
1
,
0
)
validateSyncReplication
(
t
,
&
fakePodControl
,
1
,
0
)
...
@@ -610,7 +572,7 @@ func TestControllerUpdateRequeue(t *testing.T) {
...
@@ -610,7 +572,7 @@ func TestControllerUpdateRequeue(t *testing.T) {
rc
.
Status
=
api
.
ReplicationControllerStatus
{
Replicas
:
2
}
rc
.
Status
=
api
.
ReplicationControllerStatus
{
Replicas
:
2
}
newPodList
(
manager
.
podStore
.
Store
,
1
,
api
.
PodRunning
,
rc
)
newPodList
(
manager
.
podStore
.
Store
,
1
,
api
.
PodRunning
,
rc
)
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
...
@@ -682,7 +644,7 @@ func TestControllerUpdateStatusWithFailure(t *testing.T) {
...
@@ -682,7 +644,7 @@ func TestControllerUpdateStatusWithFailure(t *testing.T) {
func
doTestControllerBurstReplicas
(
t
*
testing
.
T
,
burstReplicas
,
numReplicas
int
)
{
func
doTestControllerBurstReplicas
(
t
*
testing
.
T
,
burstReplicas
,
numReplicas
int
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
:=
NewReplicationManager
(
client
,
burstReplicas
)
manager
:=
NewReplicationManager
(
client
,
burstReplicas
)
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
...
@@ -754,7 +716,7 @@ func doTestControllerBurstReplicas(t *testing.T, burstReplicas, numReplicas int)
...
@@ -754,7 +716,7 @@ func doTestControllerBurstReplicas(t *testing.T, burstReplicas, numReplicas int)
}
}
// Check that the rc didn't take any action for all the above pods
// Check that the rc didn't take any action for all the above pods
fakePodControl
.
c
lear
()
fakePodControl
.
C
lear
()
manager
.
syncReplicationController
(
getKey
(
controllerSpec
,
t
))
manager
.
syncReplicationController
(
getKey
(
controllerSpec
,
t
))
validateSyncReplication
(
t
,
&
fakePodControl
,
0
,
0
)
validateSyncReplication
(
t
,
&
fakePodControl
,
0
,
0
)
...
@@ -802,7 +764,7 @@ func (fe FakeRCExpectations) SatisfiedExpectations(controllerKey string) bool {
...
@@ -802,7 +764,7 @@ func (fe FakeRCExpectations) SatisfiedExpectations(controllerKey string) bool {
// and checking expectations.
// and checking expectations.
func
TestRCSyncExpectations
(
t
*
testing
.
T
)
{
func
TestRCSyncExpectations
(
t
*
testing
.
T
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
:=
NewReplicationManager
(
client
,
2
)
manager
:=
NewReplicationManager
(
client
,
2
)
manager
.
podStoreSynced
=
alwaysReady
manager
.
podStoreSynced
=
alwaysReady
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
...
@@ -833,13 +795,13 @@ func TestDeleteControllerAndExpectations(t *testing.T) {
...
@@ -833,13 +795,13 @@ func TestDeleteControllerAndExpectations(t *testing.T) {
rc
:=
newReplicationController
(
1
)
rc
:=
newReplicationController
(
1
)
manager
.
rcStore
.
Store
.
Add
(
rc
)
manager
.
rcStore
.
Store
.
Add
(
rc
)
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
// This should set expectations for the rc
// This should set expectations for the rc
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
validateSyncReplication
(
t
,
&
fakePodControl
,
1
,
0
)
validateSyncReplication
(
t
,
&
fakePodControl
,
1
,
0
)
fakePodControl
.
c
lear
()
fakePodControl
.
C
lear
()
// Get the RC key
// Get the RC key
rcKey
,
err
:=
controller
.
KeyFunc
(
rc
)
rcKey
,
err
:=
controller
.
KeyFunc
(
rc
)
...
@@ -869,7 +831,7 @@ func TestDeleteControllerAndExpectations(t *testing.T) {
...
@@ -869,7 +831,7 @@ func TestDeleteControllerAndExpectations(t *testing.T) {
func
TestRCManagerNotReady
(
t
*
testing
.
T
)
{
func
TestRCManagerNotReady
(
t
*
testing
.
T
)
{
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
client
:=
client
.
NewOrDie
(
&
client
.
Config
{
Host
:
""
,
Version
:
testapi
.
Default
.
Version
()})
fakePodControl
:=
FakePodControl
{}
fakePodControl
:=
controller
.
FakePodControl
{}
manager
:=
NewReplicationManager
(
client
,
2
)
manager
:=
NewReplicationManager
(
client
,
2
)
manager
.
podControl
=
&
fakePodControl
manager
.
podControl
=
&
fakePodControl
manager
.
podStoreSynced
=
func
()
bool
{
return
false
}
manager
.
podStoreSynced
=
func
()
bool
{
return
false
}
...
...
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