mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	controller: adopt pods only when controller is not deleted
This commit is contained in:
		@@ -577,15 +577,6 @@ func (rsc *ReplicaSetController) syncReplicaSet(key string) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	rs := *obj.(*extensions.ReplicaSet)
 | 
						rs := *obj.(*extensions.ReplicaSet)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check the expectations of the ReplicaSet before counting active pods, otherwise a new pod can sneak
 | 
					 | 
				
			||||||
	// in and update the expectations after we've retrieved active pods from the store. If a new pod enters
 | 
					 | 
				
			||||||
	// the store after we've checked the expectation, the ReplicaSet sync is just deferred till the next
 | 
					 | 
				
			||||||
	// relist.
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		utilruntime.HandleError(fmt.Errorf("Couldn't get key for ReplicaSet %#v: %v", rs, err))
 | 
					 | 
				
			||||||
		// Explicitly return nil to avoid re-enqueue bad key
 | 
					 | 
				
			||||||
		return nil
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	rsNeedsSync := rsc.expectations.SatisfiedExpectations(key)
 | 
						rsNeedsSync := rsc.expectations.SatisfiedExpectations(key)
 | 
				
			||||||
	selector, err := metav1.LabelSelectorAsSelector(rs.Spec.Selector)
 | 
						selector, err := metav1.LabelSelectorAsSelector(rs.Spec.Selector)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -606,16 +597,19 @@ func (rsc *ReplicaSetController) syncReplicaSet(key string) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		cm := controller.NewPodControllerRefManager(rsc.podControl, rs.ObjectMeta, selector, getRSKind())
 | 
							cm := controller.NewPodControllerRefManager(rsc.podControl, rs.ObjectMeta, selector, getRSKind())
 | 
				
			||||||
		matchesAndControlled, matchesNeedsController, controlledDoesNotMatch := cm.Classify(pods)
 | 
							matchesAndControlled, matchesNeedsController, controlledDoesNotMatch := cm.Classify(pods)
 | 
				
			||||||
		for _, pod := range matchesNeedsController {
 | 
							// Adopt pods only if this replica set is not going to be deleted.
 | 
				
			||||||
			err := cm.AdoptPod(pod)
 | 
							if rs.DeletionTimestamp == nil {
 | 
				
			||||||
			// continue to next pod if adoption fails.
 | 
								for _, pod := range matchesNeedsController {
 | 
				
			||||||
			if err != nil {
 | 
									err := cm.AdoptPod(pod)
 | 
				
			||||||
				// If the pod no longer exists, don't even log the error.
 | 
									// continue to next pod if adoption fails.
 | 
				
			||||||
				if !errors.IsNotFound(err) {
 | 
									if err != nil {
 | 
				
			||||||
					utilruntime.HandleError(err)
 | 
										// If the pod no longer exists, don't even log the error.
 | 
				
			||||||
 | 
										if !errors.IsNotFound(err) {
 | 
				
			||||||
 | 
											utilruntime.HandleError(err)
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										matchesAndControlled = append(matchesAndControlled, pod)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				matchesAndControlled = append(matchesAndControlled, pod)
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		filteredPods = matchesAndControlled
 | 
							filteredPods = matchesAndControlled
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -666,16 +666,8 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	rc := *obj.(*v1.ReplicationController)
 | 
						rc := *obj.(*v1.ReplicationController)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Check the expectations of the rc before counting active pods, otherwise a new pod can sneak in
 | 
					 | 
				
			||||||
	// and update the expectations after we've retrieved active pods from the store. If a new pod enters
 | 
					 | 
				
			||||||
	// the store after we've checked the expectation, the rc sync is just deferred till the next relist.
 | 
					 | 
				
			||||||
	rcKey, err := controller.KeyFunc(&rc)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		glog.Errorf("Couldn't get key for replication controller %#v: %v", rc, err)
 | 
					 | 
				
			||||||
		return err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	trace.Step("ReplicationController restored")
 | 
						trace.Step("ReplicationController restored")
 | 
				
			||||||
	rcNeedsSync := rm.expectations.SatisfiedExpectations(rcKey)
 | 
						rcNeedsSync := rm.expectations.SatisfiedExpectations(key)
 | 
				
			||||||
	trace.Step("Expectations restored")
 | 
						trace.Step("Expectations restored")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// NOTE: filteredPods are pointing to objects from cache - if you need to
 | 
						// NOTE: filteredPods are pointing to objects from cache - if you need to
 | 
				
			||||||
@@ -693,16 +685,19 @@ func (rm *ReplicationManager) syncReplicationController(key string) error {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
		cm := controller.NewPodControllerRefManager(rm.podControl, rc.ObjectMeta, labels.Set(rc.Spec.Selector).AsSelectorPreValidated(), getRCKind())
 | 
							cm := controller.NewPodControllerRefManager(rm.podControl, rc.ObjectMeta, labels.Set(rc.Spec.Selector).AsSelectorPreValidated(), getRCKind())
 | 
				
			||||||
		matchesAndControlled, matchesNeedsController, controlledDoesNotMatch := cm.Classify(pods)
 | 
							matchesAndControlled, matchesNeedsController, controlledDoesNotMatch := cm.Classify(pods)
 | 
				
			||||||
		for _, pod := range matchesNeedsController {
 | 
							// Adopt pods only if this replication controller is not going to be deleted.
 | 
				
			||||||
			err := cm.AdoptPod(pod)
 | 
							if rc.DeletionTimestamp == nil {
 | 
				
			||||||
			// continue to next pod if adoption fails.
 | 
								for _, pod := range matchesNeedsController {
 | 
				
			||||||
			if err != nil {
 | 
									err := cm.AdoptPod(pod)
 | 
				
			||||||
				// If the pod no longer exists, don't even log the error.
 | 
									// continue to next pod if adoption fails.
 | 
				
			||||||
				if !errors.IsNotFound(err) {
 | 
									if err != nil {
 | 
				
			||||||
					utilruntime.HandleError(err)
 | 
										// If the pod no longer exists, don't even log the error.
 | 
				
			||||||
 | 
										if !errors.IsNotFound(err) {
 | 
				
			||||||
 | 
											utilruntime.HandleError(err)
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									} else {
 | 
				
			||||||
 | 
										matchesAndControlled = append(matchesAndControlled, pod)
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			} else {
 | 
					 | 
				
			||||||
				matchesAndControlled = append(matchesAndControlled, pod)
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		filteredPods = matchesAndControlled
 | 
							filteredPods = matchesAndControlled
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user