Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const (
RebalanceRecommendationTaint = "aws-node-termination-handler/rebalance-recommendation"

maxTaintValueLength = 63
daemonSet = "DaemonSet"
)

const (
Expand Down Expand Up @@ -144,6 +145,7 @@ func (n Node) CordonAndDrain(nodeName string, reason string, recorder recorderIn
}
if n.nthConfig.UseAPIServerCacheToListPods {
if pods != nil {
pods = n.filterOutDaemonSetPods(pods)
err = n.drainHelper.DeleteOrEvictPods(pods.Items)
}
} else {
Expand Down Expand Up @@ -647,6 +649,23 @@ func (n Node) fetchAllPods(nodeName string) (*corev1.PodList, error) {
return n.drainHelper.Client.CoreV1().Pods("").List(context.TODO(), listOptions)
}

// filterOutDaemonSetPods filters a list of pods to exclude DaemonSet pods when IgnoreDaemonSets is enabled
func (n *Node) filterOutDaemonSetPods(pods *corev1.PodList) *corev1.PodList {
if !n.nthConfig.IgnoreDaemonSets {
return pods
}

var nonDaemonSetPods []corev1.Pod
for _, pod := range pods.Items {
if !isDaemonSetPod(pod) {
nonDaemonSetPods = append(nonDaemonSetPods, pod)
}
}

pods.Items = nonDaemonSetPods
return pods
}

func getDrainHelper(nthConfig config.Config, clientset *kubernetes.Clientset) (*drain.Helper, error) {
drainHelper := &drain.Helper{
Ctx: context.TODO(),
Expand Down Expand Up @@ -838,6 +857,15 @@ func filterPodForDeletion(podName, podNamespace string) func(pod corev1.Pod) dra
}
}

func isDaemonSetPod(pod corev1.Pod) bool {
for _, owner := range pod.OwnerReferences {
if owner.Kind == daemonSet {
return true
}
}
return false
}

type recorderInterface interface {
AnnotatedEventf(object runtime.Object, annotations map[string]string, eventType, reason, messageFmt string, args ...interface{})
}
Loading