From 337e12a64fd9111077922a3fc42256cde29c66b1 Mon Sep 17 00:00:00 2001 From: Marcelo Guerrero Date: Tue, 9 Jul 2024 12:41:01 +0200 Subject: [PATCH] WIP Skip pods marked for deletion In cases where the amount of ips is limited, pods affected by a node shutdown remain in Terminating state and do not release their allocations. Deployments are not able to create pods in healthy nodes due to the lack of ips. These changes force the ip reconciler to skip pods marked as deletion by a Taint Manager. The toleration node.kubernetes.io/unreachable is expected to trigger this. However, it is safe if other tolerations with NoExecute also trigger the cleaning up. Signed-off-by: Marcelo Guerrero --- pkg/reconciler/wrappedPod.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/reconciler/wrappedPod.go b/pkg/reconciler/wrappedPod.go index cb5e871df..95ec524ab 100644 --- a/pkg/reconciler/wrappedPod.go +++ b/pkg/reconciler/wrappedPod.go @@ -46,6 +46,12 @@ func indexPods(livePodList []v1.Pod, whereaboutsPodNames map[string]void) map[st if _, isWhereaboutsPod := whereaboutsPodNames[podRef]; !isWhereaboutsPod { continue } + + if isPodMarkedForDeletion(pod.Status.Conditions) { + logging.Debugf("Pod %s is marked for deletion; skipping", podRef) + continue + } + wrappedPod := wrapPod(pod) if wrappedPod != nil { podMap[podRef] = *wrappedPod @@ -54,6 +60,15 @@ func indexPods(livePodList []v1.Pod, whereaboutsPodNames map[string]void) map[st return podMap } +func isPodMarkedForDeletion(conditions []v1.PodCondition) bool { + for _, c := range conditions { + if c.Type == v1.DisruptionTarget && c.Status == v1.ConditionTrue && c.Reason == "DeletionByTaintManager" { + return true + } + } + return false +} + func getFlatIPSet(pod v1.Pod) (map[string]void, error) { var empty void ipSet := map[string]void{}