ControllerRefManager: Don't always filter inactive Pods.

Some controllers, like DaemonSet, want to see all Pods.
This commit is contained in:
Anthony Yeh
2017-02-25 12:39:49 -08:00
parent db6665251a
commit 01d025a7cc
3 changed files with 21 additions and 14 deletions

View File

@@ -559,17 +559,23 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
rcNeedsSync := rm.expectations.SatisfiedExpectations(key)
trace.Step("Expectations restored")
// NOTE: filteredPods are pointing to objects from cache - if you need to
// modify them, you need to copy it first.
// TODO: Do the List and Filter in a single pass, or use an index.
var filteredPods []*v1.Pod
// list all pods to include the pods that don't match the rc's selector
// anymore but has the stale controller ref.
// TODO: Do the List and Filter in a single pass, or use an index.
pods, err := rm.podLister.Pods(rc.Namespace).List(labels.Everything())
if err != nil {
return err
}
// Ignore inactive pods.
var filteredPods []*v1.Pod
for _, pod := range pods {
if controller.IsPodActive(pod) {
filteredPods = append(filteredPods, pod)
}
}
cm := controller.NewPodControllerRefManager(rm.podControl, rc, labels.Set(rc.Spec.Selector).AsSelectorPreValidated(), controllerKind)
// NOTE: filteredPods are pointing to objects from cache - if you need to
// modify them, you need to copy it first.
filteredPods, err = cm.ClaimPods(pods)
if err != nil {
return err