Skip terminal Pods with a deletion timestamp from the Daemonset sync (#118716)
* Skip terminal Pods with a deletion timestamp from the Daemonset sync Change-Id: I64a347a87c02ee2bd48be10e6fff380c8c81f742 * Review comments and fix integration test Change-Id: I3eb5ec62bce8b4b150726a1e9b2b517c4e993713 * Include deleted terminal pods in history Change-Id: I8b921157e6be1c809dd59f8035ec259ea4d96301
This commit is contained in:

committed by
GitHub

parent
6dbb1c6cf0
commit
a4519665fe
@@ -752,7 +752,7 @@ func (dsc *DaemonSetsController) getDaemonPods(ctx context.Context, ds *apps.Dae
|
||||
// This also reconciles ControllerRef by adopting/orphaning.
|
||||
// Note that returned Pods are pointers to objects in the cache.
|
||||
// If you want to modify one, you need to deep-copy it first.
|
||||
func (dsc *DaemonSetsController) getNodesToDaemonPods(ctx context.Context, ds *apps.DaemonSet) (map[string][]*v1.Pod, error) {
|
||||
func (dsc *DaemonSetsController) getNodesToDaemonPods(ctx context.Context, ds *apps.DaemonSet, includeDeletedTerminal bool) (map[string][]*v1.Pod, error) {
|
||||
claimedPods, err := dsc.getDaemonPods(ctx, ds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -761,6 +761,12 @@ func (dsc *DaemonSetsController) getNodesToDaemonPods(ctx context.Context, ds *a
|
||||
nodeToDaemonPods := make(map[string][]*v1.Pod)
|
||||
logger := klog.FromContext(ctx)
|
||||
for _, pod := range claimedPods {
|
||||
if !includeDeletedTerminal && podutil.IsPodTerminal(pod) && pod.DeletionTimestamp != nil {
|
||||
// This Pod has a finalizer or is already scheduled for deletion from the
|
||||
// store by the kubelet or the Pod GC. The DS controller doesn't have
|
||||
// anything else to do with it.
|
||||
continue
|
||||
}
|
||||
nodeName, err := util.GetTargetNodeName(pod)
|
||||
if err != nil {
|
||||
logger.Info("Failed to get target node name of Pod in DaemonSet",
|
||||
@@ -953,7 +959,7 @@ func (dsc *DaemonSetsController) updateDaemonSet(ctx context.Context, ds *apps.D
|
||||
// syncNodes with a list of pods to remove and a list of nodes to run a Pod of ds.
|
||||
func (dsc *DaemonSetsController) manage(ctx context.Context, ds *apps.DaemonSet, nodeList []*v1.Node, hash string) error {
|
||||
// Find out the pods which are created for the nodes by DaemonSet.
|
||||
nodeToDaemonPods, err := dsc.getNodesToDaemonPods(ctx, ds)
|
||||
nodeToDaemonPods, err := dsc.getNodesToDaemonPods(ctx, ds, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get node to daemon pod mapping for daemon set %q: %v", ds.Name, err)
|
||||
}
|
||||
@@ -1154,7 +1160,7 @@ func storeDaemonSetStatus(
|
||||
func (dsc *DaemonSetsController) updateDaemonSetStatus(ctx context.Context, ds *apps.DaemonSet, nodeList []*v1.Node, hash string, updateObservedGen bool) error {
|
||||
logger := klog.FromContext(ctx)
|
||||
logger.V(4).Info("Updating daemon set status")
|
||||
nodeToDaemonPods, err := dsc.getNodesToDaemonPods(ctx, ds)
|
||||
nodeToDaemonPods, err := dsc.getNodesToDaemonPods(ctx, ds, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't get node to daemon pod mapping for daemon set %q: %v", ds.Name, err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user