@@ -61,6 +61,7 @@ const (
61
61
RebalanceRecommendationTaint = "aws-node-termination-handler/rebalance-recommendation"
62
62
63
63
maxTaintValueLength = 63
64
+ daemonSet = "DaemonSet"
64
65
)
65
66
66
67
const (
@@ -144,6 +145,7 @@ func (n Node) CordonAndDrain(nodeName string, reason string, recorder recorderIn
144
145
}
145
146
if n .nthConfig .UseAPIServerCacheToListPods {
146
147
if pods != nil {
148
+ pods = n .FilterOutDaemonSetPods (pods )
147
149
err = n .drainHelper .DeleteOrEvictPods (pods .Items )
148
150
}
149
151
} else {
@@ -647,6 +649,23 @@ func (n Node) fetchAllPods(nodeName string) (*corev1.PodList, error) {
647
649
return n .drainHelper .Client .CoreV1 ().Pods ("" ).List (context .TODO (), listOptions )
648
650
}
649
651
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
+
650
669
func getDrainHelper (nthConfig config.Config , clientset * kubernetes.Clientset ) (* drain.Helper , error ) {
651
670
drainHelper := & drain.Helper {
652
671
Ctx : context .TODO (),
@@ -838,6 +857,15 @@ func filterPodForDeletion(podName, podNamespace string) func(pod corev1.Pod) dra
838
857
}
839
858
}
840
859
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
+
841
869
type recorderInterface interface {
842
870
AnnotatedEventf (object runtime.Object , annotations map [string ]string , eventType , reason , messageFmt string , args ... interface {})
843
871
}
0 commit comments