@@ -61,6 +61,7 @@ const (
6161 RebalanceRecommendationTaint = "aws-node-termination-handler/rebalance-recommendation"
6262
6363 maxTaintValueLength = 63
64+ daemonSet = "DaemonSet"
6465)
6566
6667const (
@@ -144,6 +145,7 @@ func (n Node) CordonAndDrain(nodeName string, reason string, recorder recorderIn
144145 }
145146 if n .nthConfig .UseAPIServerCacheToListPods {
146147 if pods != nil {
148+ pods = n .FilterOutDaemonSetPods (pods )
147149 err = n .drainHelper .DeleteOrEvictPods (pods .Items )
148150 }
149151 } else {
@@ -647,6 +649,23 @@ func (n Node) fetchAllPods(nodeName string) (*corev1.PodList, error) {
647649 return n .drainHelper .Client .CoreV1 ().Pods ("" ).List (context .TODO (), listOptions )
648650}
649651
652+ // FilterOutDaemonSetPods filters a list of pods to exclude DaemonSet pods when IgnoreDaemonSets is enabled
653+ func (n * Node ) FilterOutDaemonSetPods (pods * corev1.PodList ) * corev1.PodList {
654+ if ! n .nthConfig .IgnoreDaemonSets {
655+ return pods
656+ }
657+
658+ var nonDaemonSetPods []corev1.Pod
659+ for _ , pod := range pods .Items {
660+ if ! isDaemonSetPod (pod ) {
661+ nonDaemonSetPods = append (nonDaemonSetPods , pod )
662+ }
663+ }
664+
665+ pods .Items = nonDaemonSetPods
666+ return pods
667+ }
668+
650669func getDrainHelper (nthConfig config.Config , clientset * kubernetes.Clientset ) (* drain.Helper , error ) {
651670 drainHelper := & drain.Helper {
652671 Ctx : context .TODO (),
@@ -838,6 +857,15 @@ func filterPodForDeletion(podName, podNamespace string) func(pod corev1.Pod) dra
838857 }
839858}
840859
860+ func isDaemonSetPod (pod corev1.Pod ) bool {
861+ for _ , owner := range pod .OwnerReferences {
862+ if owner .Kind == daemonSet {
863+ return true
864+ }
865+ }
866+ return false
867+ }
868+
841869type recorderInterface interface {
842870 AnnotatedEventf (object runtime.Object , annotations map [string ]string , eventType , reason , messageFmt string , args ... interface {})
843871}
0 commit comments