Skip to content

Commit 61ec184

Browse files
committed
Add filtering before DeleteOrEvictPods
1 parent a0c0aa1 commit 61ec184

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pkg/node/node.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ const (
6161
RebalanceRecommendationTaint = "aws-node-termination-handler/rebalance-recommendation"
6262

6363
maxTaintValueLength = 63
64+
daemonSet = "DaemonSet"
6465
)
6566

6667
const (
@@ -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+
650669
func 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+
841869
type recorderInterface interface {
842870
AnnotatedEventf(object runtime.Object, annotations map[string]string, eventType, reason, messageFmt string, args ...interface{})
843871
}

0 commit comments

Comments
 (0)