mirror of https://github.com/k3s-io/k3s
Merge pull request #11903 from mikedanese/renamers
rename StoreToControllerLister -> StoreToReplicationControllerListerpull/6/head
commit
c5bffaaf31
|
@ -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 {
|
||||
// StoreToReplicationControllerLister gives a store List and Exists methods. The store must contain only ReplicationControllers.
|
||||
type StoreToReplicationControllerLister struct {
|
||||
Store
|
||||
}
|
||||
|
||||
// Exists checks if the given rc exists in the store.
|
||||
func (s *StoreToControllerLister) Exists(controller *api.ReplicationController) (bool, error) {
|
||||
func (s *StoreToReplicationControllerLister) 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.
|
||||
// StoreToReplicationControllerLister 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 *StoreToReplicationControllerLister) 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 *StoreToReplicationControllerLister) GetPodControllers(pod *api.Pod) (controllers []api.ReplicationController, err error) {
|
||||
var selector labels.Selector
|
||||
var rc api.ReplicationController
|
||||
|
||||
|
|
|
@ -45,9 +45,9 @@ func TestStoreToMinionLister(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestStoreToControllerLister(t *testing.T) {
|
||||
func TestStoreToReplicationControllerLister(t *testing.T) {
|
||||
store := NewStore(MetaNamespaceKeyFunc)
|
||||
lister := StoreToControllerLister{store}
|
||||
lister := StoreToReplicationControllerLister{store}
|
||||
testCases := []struct {
|
||||
inRCs []*api.ReplicationController
|
||||
list func() ([]api.ReplicationController, error)
|
||||
|
|
|
@ -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.StoreToControllerLister
|
||||
// A store of replication controllers, populated by the rcController
|
||||
rcStore cache.StoreToReplicationControllerLister
|
||||
// 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.controllerStore.Store, rm.rcController = framework.NewInformer(
|
||||
rm.rcStore.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.controllerStore.GetPodControllers(pod)
|
||||
controllers, err := rm.rcStore.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.controllerStore.Store.GetByKey(key)
|
||||
obj, exists, err := rm.rcStore.Store.GetByKey(key)
|
||||
if !exists {
|
||||
glog.Infof("Replication Controller has been deleted %v", key)
|
||||
rm.expectations.DeleteExpectations(key)
|
||||
|
|
|
@ -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.controllerStore.Store.Add(controllerSpec)
|
||||
manager.rcStore.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.controllerStore.Store.Add(controllerSpec)
|
||||
manager.rcStore.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.controllerStore.Store.Add(controllerSpec)
|
||||
manager.rcStore.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.controllerStore.Store.Add(controller)
|
||||
manager.rcStore.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.controllerStore.Store.Add(rc)
|
||||
manager.rcStore.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.controllerStore.Store.Add(rc)
|
||||
manager.rcStore.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.controllerStore.Store.Add(controllerSpec)
|
||||
manager.rcStore.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.controllerStore.Add(r)
|
||||
manager.rcStore.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.controllerStore.Store.GetByKey(key)
|
||||
obj, exists, err := manager.rcStore.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.controllerStore.Store.Add(testControllerSpec)
|
||||
manager.rcStore.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.controllerStore.Store.GetByKey(key)
|
||||
obj, exists, err := manager.rcStore.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.controllerStore.Store.GetByKey(key)
|
||||
obj, exists, err := manager.rcStore.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.controllerStore.Store.Add(testControllerSpec1)
|
||||
manager.rcStore.Store.Add(testControllerSpec1)
|
||||
testControllerSpec2 := *testControllerSpec1
|
||||
testControllerSpec2.Spec.Selector = map[string]string{"bar": "foo"}
|
||||
testControllerSpec2.Name = "barfoo"
|
||||
manager.controllerStore.Store.Add(&testControllerSpec2)
|
||||
manager.rcStore.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.controllerStore.Store.Add(rc)
|
||||
manager.rcStore.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.controllerStore.Store.Add(controllerSpec)
|
||||
manager.rcStore.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.controllerStore.Store.Add(controllerSpec)
|
||||
manager.rcStore.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.controllerStore.Store.Add(controllerSpec)
|
||||
manager.rcStore.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.controllerStore.Store.Add(rc)
|
||||
manager.rcStore.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.controllerStore.Delete(rc)
|
||||
manager.rcStore.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.controllerStore.Store.Add(controllerSpec)
|
||||
manager.rcStore.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.controllerStore.Store.Add(shuffledControllers[j])
|
||||
manager.rcStore.Store.Add(shuffledControllers[j])
|
||||
}
|
||||
// Add a pod and make sure only the oldest rc is synced
|
||||
pods := newPodList(nil, 1, api.PodPending, controllers[0])
|
||||
|
|
Loading…
Reference in New Issue