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
d167fa27
Commit
d167fa27
authored
Jul 27, 2015
by
Mike Danese
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename StoreToControllerLister -> StoreToReplicationControllerLister to make…
rename StoreToControllerLister -> StoreToReplicationControllerLister to make room for more controllers
parent
6e8648f8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
36 deletions
+36
-36
listers.go
pkg/client/cache/listers.go
+7
-7
listers_test.go
pkg/client/cache/listers_test.go
+2
-2
replication_controller.go
pkg/controller/replication_controller.go
+5
-5
replication_controller_test.go
pkg/controller/replication_controller_test.go
+22
-22
No files found.
pkg/client/cache/listers.go
View file @
d167fa27
...
...
@@ -172,13 +172,13 @@ func (s *StoreToNodeLister) GetNodeInfo(id string) (*api.Node, error) {
return
minion
.
(
*
api
.
Node
),
nil
}
// StoreToControllerLister gives a store List and Exists methods. The store must contain only ReplicationControllers.
type
StoreToControllerLister
struct
{
// StoreTo
Replication
ControllerLister gives a store List and Exists methods. The store must contain only ReplicationControllers.
type
StoreTo
Replication
ControllerLister
struct
{
Store
}
// Exists checks if the given rc exists in the store.
func
(
s
*
StoreToControllerLister
)
Exists
(
controller
*
api
.
ReplicationController
)
(
bool
,
error
)
{
func
(
s
*
StoreTo
Replication
ControllerLister
)
Exists
(
controller
*
api
.
ReplicationController
)
(
bool
,
error
)
{
_
,
exists
,
err
:=
s
.
Store
.
Get
(
controller
)
if
err
!=
nil
{
return
false
,
err
...
...
@@ -186,17 +186,17 @@ func (s *StoreToControllerLister) Exists(controller *api.ReplicationController)
return
exists
,
nil
}
// StoreToControllerLister lists all controllers in the store.
// StoreTo
Replication
ControllerLister lists all controllers in the store.
// TODO: converge on the interface in pkg/client
func
(
s
*
StoreToControllerLister
)
List
()
(
controllers
[]
api
.
ReplicationController
,
err
error
)
{
func
(
s
*
StoreTo
Replication
ControllerLister
)
List
()
(
controllers
[]
api
.
ReplicationController
,
err
error
)
{
for
_
,
c
:=
range
s
.
Store
.
List
()
{
controllers
=
append
(
controllers
,
*
(
c
.
(
*
api
.
ReplicationController
)))
}
return
controllers
,
nil
}
// GetPodControllers returns a list of controllers managing a pod. Returns an error only if no matching controllers are found.
func
(
s
*
StoreToControllerLister
)
GetPodControllers
(
pod
*
api
.
Pod
)
(
controllers
[]
api
.
ReplicationController
,
err
error
)
{
// GetPodControllers returns a list of
replication
controllers managing a pod. Returns an error only if no matching controllers are found.
func
(
s
*
StoreTo
Replication
ControllerLister
)
GetPodControllers
(
pod
*
api
.
Pod
)
(
controllers
[]
api
.
ReplicationController
,
err
error
)
{
var
selector
labels
.
Selector
var
rc
api
.
ReplicationController
...
...
pkg/client/cache/listers_test.go
View file @
d167fa27
...
...
@@ -45,9 +45,9 @@ func TestStoreToMinionLister(t *testing.T) {
}
}
func
TestStoreToControllerLister
(
t
*
testing
.
T
)
{
func
TestStoreTo
Replication
ControllerLister
(
t
*
testing
.
T
)
{
store
:=
NewStore
(
MetaNamespaceKeyFunc
)
lister
:=
StoreToControllerLister
{
store
}
lister
:=
StoreTo
Replication
ControllerLister
{
store
}
testCases
:=
[]
struct
{
inRCs
[]
*
api
.
ReplicationController
list
func
()
([]
api
.
ReplicationController
,
error
)
...
...
pkg/controller/replication_controller.go
View file @
d167fa27
...
...
@@ -91,8 +91,8 @@ type ReplicationManager struct {
// A TTLCache of pod creates/deletes each rc expects to see
expectations
RCExpectationsManager
// A store of controllers, populated by the rcController
controllerStore
cache
.
StoreTo
ControllerLister
// A store of
replication
controllers, populated by the rcController
rcStore
cache
.
StoreToReplication
ControllerLister
// A store of pods, populated by the podController
podStore
cache
.
StoreToPodLister
// Watches changes to all replication controllers
...
...
@@ -120,7 +120,7 @@ func NewReplicationManager(kubeClient client.Interface, burstReplicas int) *Repl
queue
:
workqueue
.
New
(),
}
rm
.
controller
Store
.
Store
,
rm
.
rcController
=
framework
.
NewInformer
(
rm
.
rc
Store
.
Store
,
rm
.
rcController
=
framework
.
NewInformer
(
&
cache
.
ListWatch
{
ListFunc
:
func
()
(
runtime
.
Object
,
error
)
{
return
rm
.
kubeClient
.
ReplicationControllers
(
api
.
NamespaceAll
)
.
List
(
labels
.
Everything
())
...
...
@@ -204,7 +204,7 @@ func (rm *ReplicationManager) Run(workers int, stopCh <-chan struct{}) {
// getPodControllers returns the controller managing the given pod.
// TODO: Surface that we are ignoring multiple controllers for a single pod.
func
(
rm
*
ReplicationManager
)
getPodControllers
(
pod
*
api
.
Pod
)
*
api
.
ReplicationController
{
controllers
,
err
:=
rm
.
controller
Store
.
GetPodControllers
(
pod
)
controllers
,
err
:=
rm
.
rc
Store
.
GetPodControllers
(
pod
)
if
err
!=
nil
{
glog
.
V
(
4
)
.
Infof
(
"No controllers found for pod %v, replication manager will avoid syncing"
,
pod
.
Name
)
return
nil
...
...
@@ -376,7 +376,7 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
glog
.
V
(
4
)
.
Infof
(
"Finished syncing controller %q (%v)"
,
key
,
time
.
Now
()
.
Sub
(
startTime
))
}()
obj
,
exists
,
err
:=
rm
.
controller
Store
.
Store
.
GetByKey
(
key
)
obj
,
exists
,
err
:=
rm
.
rc
Store
.
Store
.
GetByKey
(
key
)
if
!
exists
{
glog
.
Infof
(
"Replication Controller has been deleted %v"
,
key
)
rm
.
expectations
.
DeleteExpectations
(
key
)
...
...
pkg/controller/replication_controller_test.go
View file @
d167fa27
...
...
@@ -229,7 +229,7 @@ func TestSyncReplicationControllerDoesNothing(t *testing.T) {
// 2 running pods, a controller with 2 replicas, sync is a no-op
controllerSpec
:=
newReplicationController
(
2
)
manager
.
controller
Store
.
Store
.
Add
(
controllerSpec
)
manager
.
rc
Store
.
Store
.
Add
(
controllerSpec
)
newPodList
(
manager
.
podStore
.
Store
,
2
,
api
.
PodRunning
,
controllerSpec
)
manager
.
podControl
=
&
fakePodControl
...
...
@@ -246,7 +246,7 @@ func TestSyncReplicationControllerDeletes(t *testing.T) {
// 2 running pods and a controller with 1 replica, one pod delete expected
controllerSpec
:=
newReplicationController
(
1
)
manager
.
controller
Store
.
Store
.
Add
(
controllerSpec
)
manager
.
rc
Store
.
Store
.
Add
(
controllerSpec
)
newPodList
(
manager
.
podStore
.
Store
,
2
,
api
.
PodRunning
,
controllerSpec
)
manager
.
syncReplicationController
(
getKey
(
controllerSpec
,
t
))
...
...
@@ -269,7 +269,7 @@ func TestDeleteFinalStateUnknown(t *testing.T) {
// The DeletedFinalStateUnknown object should cause the rc manager to insert
// the controller matching the selectors of the deleted pod into the work queue.
controllerSpec
:=
newReplicationController
(
1
)
manager
.
controller
Store
.
Store
.
Add
(
controllerSpec
)
manager
.
rc
Store
.
Store
.
Add
(
controllerSpec
)
pods
:=
newPodList
(
nil
,
1
,
api
.
PodRunning
,
controllerSpec
)
manager
.
deletePod
(
cache
.
DeletedFinalStateUnknown
{
Key
:
"foo"
,
Obj
:
&
pods
.
Items
[
0
]})
...
...
@@ -293,7 +293,7 @@ func TestSyncReplicationControllerCreates(t *testing.T) {
// A controller with 2 replicas and no pods in the store, 2 creates expected
controller
:=
newReplicationController
(
2
)
manager
.
controller
Store
.
Store
.
Add
(
controller
)
manager
.
rc
Store
.
Store
.
Add
(
controller
)
fakePodControl
:=
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
...
...
@@ -355,7 +355,7 @@ func TestStatusUpdatesWithoutReplicasChange(t *testing.T) {
// Steady state for the replication controller, no Status.Replicas updates expected
activePods
:=
5
rc
:=
newReplicationController
(
activePods
)
manager
.
controller
Store
.
Store
.
Add
(
rc
)
manager
.
rc
Store
.
Store
.
Add
(
rc
)
rc
.
Status
=
api
.
ReplicationControllerStatus
{
Replicas
:
activePods
}
newPodList
(
manager
.
podStore
.
Store
,
activePods
,
api
.
PodRunning
,
rc
)
...
...
@@ -397,7 +397,7 @@ func TestControllerUpdateReplicas(t *testing.T) {
// Insufficient number of pods in the system, and Status.Replicas is wrong;
// Status.Replica should update to match number of pods in system, 1 new pod should be created.
rc
:=
newReplicationController
(
5
)
manager
.
controller
Store
.
Store
.
Add
(
rc
)
manager
.
rc
Store
.
Store
.
Add
(
rc
)
rc
.
Status
=
api
.
ReplicationControllerStatus
{
Replicas
:
2
,
ObservedGeneration
:
0
}
rc
.
Generation
=
1
newPodList
(
manager
.
podStore
.
Store
,
4
,
api
.
PodRunning
,
rc
)
...
...
@@ -586,7 +586,7 @@ func TestSyncReplicationControllerDormancy(t *testing.T) {
manager
.
podControl
=
&
fakePodControl
controllerSpec
:=
newReplicationController
(
2
)
manager
.
controller
Store
.
Store
.
Add
(
controllerSpec
)
manager
.
rc
Store
.
Store
.
Add
(
controllerSpec
)
newPodList
(
manager
.
podStore
.
Store
,
1
,
api
.
PodRunning
,
controllerSpec
)
// Creates a replica and sets expectations
...
...
@@ -668,7 +668,7 @@ func TestPodControllerLookup(t *testing.T) {
}
for
_
,
c
:=
range
testCases
{
for
_
,
r
:=
range
c
.
inRCs
{
manager
.
controller
Store
.
Add
(
r
)
manager
.
rc
Store
.
Add
(
r
)
}
if
rc
:=
manager
.
getPodControllers
(
c
.
pod
);
rc
!=
nil
{
if
c
.
outRCName
!=
rc
.
Name
{
...
...
@@ -699,7 +699,7 @@ func TestWatchControllers(t *testing.T) {
// and closes the received channel to indicate that the test can finish.
manager
.
syncHandler
=
func
(
key
string
)
error
{
obj
,
exists
,
err
:=
manager
.
controller
Store
.
Store
.
GetByKey
(
key
)
obj
,
exists
,
err
:=
manager
.
rc
Store
.
Store
.
GetByKey
(
key
)
if
!
exists
||
err
!=
nil
{
t
.
Errorf
(
"Expected to find controller under key %v"
,
key
)
}
...
...
@@ -735,13 +735,13 @@ func TestWatchPods(t *testing.T) {
// Put one rc and one pod into the controller's stores
testControllerSpec
:=
newReplicationController
(
1
)
manager
.
controller
Store
.
Store
.
Add
(
testControllerSpec
)
manager
.
rc
Store
.
Store
.
Add
(
testControllerSpec
)
received
:=
make
(
chan
string
)
// The pod update sent through the fakeWatcher should figure out the managing rc and
// send it into the syncHandler.
manager
.
syncHandler
=
func
(
key
string
)
error
{
obj
,
exists
,
err
:=
manager
.
controller
Store
.
Store
.
GetByKey
(
key
)
obj
,
exists
,
err
:=
manager
.
rc
Store
.
Store
.
GetByKey
(
key
)
if
!
exists
||
err
!=
nil
{
t
.
Errorf
(
"Expected to find controller under key %v"
,
key
)
}
...
...
@@ -780,7 +780,7 @@ func TestUpdatePods(t *testing.T) {
received
:=
make
(
chan
string
)
manager
.
syncHandler
=
func
(
key
string
)
error
{
obj
,
exists
,
err
:=
manager
.
controller
Store
.
Store
.
GetByKey
(
key
)
obj
,
exists
,
err
:=
manager
.
rc
Store
.
Store
.
GetByKey
(
key
)
if
!
exists
||
err
!=
nil
{
t
.
Errorf
(
"Expected to find controller under key %v"
,
key
)
}
...
...
@@ -794,11 +794,11 @@ func TestUpdatePods(t *testing.T) {
// Put 2 rcs and one pod into the controller's stores
testControllerSpec1
:=
newReplicationController
(
1
)
manager
.
controller
Store
.
Store
.
Add
(
testControllerSpec1
)
manager
.
rc
Store
.
Store
.
Add
(
testControllerSpec1
)
testControllerSpec2
:=
*
testControllerSpec1
testControllerSpec2
.
Spec
.
Selector
=
map
[
string
]
string
{
"bar"
:
"foo"
}
testControllerSpec2
.
Name
=
"barfoo"
manager
.
controller
Store
.
Store
.
Add
(
&
testControllerSpec2
)
manager
.
rc
Store
.
Store
.
Add
(
&
testControllerSpec2
)
// Put one pod in the podStore
pod1
:=
newPodList
(
manager
.
podStore
.
Store
,
1
,
api
.
PodRunning
,
testControllerSpec1
)
.
Items
[
0
]
...
...
@@ -837,7 +837,7 @@ func TestControllerUpdateRequeue(t *testing.T) {
manager
.
podStoreSynced
=
alwaysReady
rc
:=
newReplicationController
(
1
)
manager
.
controller
Store
.
Store
.
Add
(
rc
)
manager
.
rc
Store
.
Store
.
Add
(
rc
)
rc
.
Status
=
api
.
ReplicationControllerStatus
{
Replicas
:
2
}
newPodList
(
manager
.
podStore
.
Store
,
1
,
api
.
PodRunning
,
rc
)
...
...
@@ -915,7 +915,7 @@ func doTestControllerBurstReplicas(t *testing.T, burstReplicas, numReplicas int)
manager
.
podControl
=
&
fakePodControl
controllerSpec
:=
newReplicationController
(
numReplicas
)
manager
.
controller
Store
.
Store
.
Add
(
controllerSpec
)
manager
.
rc
Store
.
Store
.
Add
(
controllerSpec
)
expectedPods
:=
0
pods
:=
newPodList
(
nil
,
numReplicas
,
api
.
PodPending
,
controllerSpec
)
...
...
@@ -924,7 +924,7 @@ func doTestControllerBurstReplicas(t *testing.T, burstReplicas, numReplicas int)
for
_
,
replicas
:=
range
[]
int
{
numReplicas
,
0
}
{
controllerSpec
.
Spec
.
Replicas
=
replicas
manager
.
controller
Store
.
Store
.
Add
(
controllerSpec
)
manager
.
rc
Store
.
Store
.
Add
(
controllerSpec
)
for
i
:=
0
;
i
<
numReplicas
;
i
+=
burstReplicas
{
manager
.
syncReplicationController
(
getKey
(
controllerSpec
,
t
))
...
...
@@ -1030,7 +1030,7 @@ func TestRCSyncExpectations(t *testing.T) {
manager
.
podControl
=
&
fakePodControl
controllerSpec
:=
newReplicationController
(
2
)
manager
.
controller
Store
.
Store
.
Add
(
controllerSpec
)
manager
.
rc
Store
.
Store
.
Add
(
controllerSpec
)
pods
:=
newPodList
(
nil
,
2
,
api
.
PodPending
,
controllerSpec
)
manager
.
podStore
.
Store
.
Add
(
&
pods
.
Items
[
0
])
postExpectationsPod
:=
pods
.
Items
[
1
]
...
...
@@ -1053,7 +1053,7 @@ func TestDeleteControllerAndExpectations(t *testing.T) {
manager
.
podStoreSynced
=
alwaysReady
rc
:=
newReplicationController
(
1
)
manager
.
controller
Store
.
Store
.
Add
(
rc
)
manager
.
rc
Store
.
Store
.
Add
(
rc
)
fakePodControl
:=
FakePodControl
{}
manager
.
podControl
=
&
fakePodControl
...
...
@@ -1069,7 +1069,7 @@ func TestDeleteControllerAndExpectations(t *testing.T) {
if
!
exists
||
err
!=
nil
{
t
.
Errorf
(
"No expectations found for rc"
)
}
manager
.
controller
Store
.
Delete
(
rc
)
manager
.
rc
Store
.
Delete
(
rc
)
manager
.
syncReplicationController
(
getKey
(
rc
,
t
))
if
_
,
exists
,
err
=
manager
.
expectations
.
GetExpectations
(
rc
);
exists
{
...
...
@@ -1094,7 +1094,7 @@ func TestRCManagerNotReady(t *testing.T) {
// want to end up creating replicas in this case until the pod reflector
// has synced, so the rc manager should just requeue the rc.
controllerSpec
:=
newReplicationController
(
1
)
manager
.
controller
Store
.
Store
.
Add
(
controllerSpec
)
manager
.
rc
Store
.
Store
.
Add
(
controllerSpec
)
rcKey
:=
getKey
(
controllerSpec
,
t
)
manager
.
syncReplicationController
(
rcKey
)
...
...
@@ -1137,7 +1137,7 @@ func TestOverlappingRCs(t *testing.T) {
}
shuffledControllers
:=
shuffle
(
controllers
)
for
j
:=
range
shuffledControllers
{
manager
.
controller
Store
.
Store
.
Add
(
shuffledControllers
[
j
])
manager
.
rc
Store
.
Store
.
Add
(
shuffledControllers
[
j
])
}
// Add a pod and make sure only the oldest rc is synced
pods
:=
newPodList
(
nil
,
1
,
api
.
PodPending
,
controllers
[
0
])
...
...
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