From 993162dd44c7b53588b3caf3d44bbc2097e8384b Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:29:37 +0100 Subject: [PATCH 01/39] refactor(TestPodAntiAffinity): replace test.BuildTestNode with buildTestNode helper --- .../pod_antiaffinity_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 1b6affa2d..3a09d8af1 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -33,18 +33,22 @@ import ( "sigs.k8s.io/descheduler/test" ) +func buildTestNode(name string, apply func(*v1.Node)) *v1.Node { + return test.BuildTestNode(name, 2000, 3000, 10, apply) +} + func TestPodAntiAffinity(t *testing.T) { - node1 := test.BuildTestNode("n1", 2000, 3000, 10, func(node *v1.Node) { + node1 := buildTestNode("n1", func(node *v1.Node) { node.ObjectMeta.Labels = map[string]string{ "region": "main-region", } }) - node2 := test.BuildTestNode("n2", 2000, 3000, 10, func(node *v1.Node) { + node2 := buildTestNode("n2", func(node *v1.Node) { node.ObjectMeta.Labels = map[string]string{ "datacenter": "east", } }) - node3 := test.BuildTestNode("n3", 2000, 3000, 10, func(node *v1.Node) { + node3 := buildTestNode("n3", func(node *v1.Node) { node.Spec = v1.NodeSpec{ Unschedulable: true, } From 1f856595f5f7dabfaaceeb79da4e0e296ceef896 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:31:42 +0100 Subject: [PATCH 02/39] refactor(TestPodAntiAffinity): add nodeName constants refactor(TestPodAntiAffinity): replace node.Name with nodeName constants --- .../pod_antiaffinity_test.go | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 3a09d8af1..3ccd5240c 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -33,49 +33,57 @@ import ( "sigs.k8s.io/descheduler/test" ) +const ( + nodeName1 = "n1" + nodeName2 = "n2" + nodeName3 = "n3" + nodeName4 = "n4" + nodeName5 = "n5" +) + func buildTestNode(name string, apply func(*v1.Node)) *v1.Node { return test.BuildTestNode(name, 2000, 3000, 10, apply) } func TestPodAntiAffinity(t *testing.T) { - node1 := buildTestNode("n1", func(node *v1.Node) { + node1 := buildTestNode(nodeName1, func(node *v1.Node) { node.ObjectMeta.Labels = map[string]string{ "region": "main-region", } }) - node2 := buildTestNode("n2", func(node *v1.Node) { + node2 := buildTestNode(nodeName2, func(node *v1.Node) { node.ObjectMeta.Labels = map[string]string{ "datacenter": "east", } }) - node3 := buildTestNode("n3", func(node *v1.Node) { + node3 := buildTestNode(nodeName3, func(node *v1.Node) { node.Spec = v1.NodeSpec{ Unschedulable: true, } }) - node4 := test.BuildTestNode("n4", 2, 2, 1, nil) - node5 := test.BuildTestNode("n5", 200, 3000, 10, func(node *v1.Node) { + node4 := test.BuildTestNode(nodeName4, 2, 2, 1, nil) + node5 := test.BuildTestNode(nodeName5, 200, 3000, 10, func(node *v1.Node) { node.ObjectMeta.Labels = map[string]string{ "region": "main-region", } }) - p1 := test.BuildTestPod("p1", 100, 0, node1.Name, nil) - p2 := test.BuildTestPod("p2", 100, 0, node1.Name, nil) - p3 := test.BuildTestPod("p3", 100, 0, node1.Name, nil) - p4 := test.BuildTestPod("p4", 100, 0, node1.Name, nil) - p5 := test.BuildTestPod("p5", 100, 0, node1.Name, nil) - p6 := test.BuildTestPod("p6", 100, 0, node1.Name, nil) - p7 := test.BuildTestPod("p7", 100, 0, node1.Name, nil) - p8 := test.BuildTestPod("p8", 100, 0, node1.Name, nil) - p9 := test.BuildTestPod("p9", 100, 0, node1.Name, nil) - p10 := test.BuildTestPod("p10", 100, 0, node1.Name, nil) - p11 := test.BuildTestPod("p11", 100, 0, node5.Name, nil) + p1 := test.BuildTestPod("p1", 100, 0, nodeName1, nil) + p2 := test.BuildTestPod("p2", 100, 0, nodeName1, nil) + p3 := test.BuildTestPod("p3", 100, 0, nodeName1, nil) + p4 := test.BuildTestPod("p4", 100, 0, nodeName1, nil) + p5 := test.BuildTestPod("p5", 100, 0, nodeName1, nil) + p6 := test.BuildTestPod("p6", 100, 0, nodeName1, nil) + p7 := test.BuildTestPod("p7", 100, 0, nodeName1, nil) + p8 := test.BuildTestPod("p8", 100, 0, nodeName1, nil) + p9 := test.BuildTestPod("p9", 100, 0, nodeName1, nil) + p10 := test.BuildTestPod("p10", 100, 0, nodeName1, nil) + p11 := test.BuildTestPod("p11", 100, 0, nodeName5, nil) p9.DeletionTimestamp = &metav1.Time{} p10.DeletionTimestamp = &metav1.Time{} criticalPriority := utils.SystemCriticalPriority - nonEvictablePod := test.BuildTestPod("non-evict", 100, 0, node1.Name, func(pod *v1.Pod) { + nonEvictablePod := test.BuildTestPod("non-evict", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Spec.Priority = &criticalPriority }) p2.Labels = map[string]string{"foo": "bar"} From bba62ccb9319d7f1ec4e79bcd0f882998e8d6e35 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:39:03 +0100 Subject: [PATCH 03/39] refactor(TestPodAntiAffinity): extract setNodeMainRegionLabel helper --- .../pod_antiaffinity_test.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 3ccd5240c..878262b1e 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -45,12 +45,14 @@ func buildTestNode(name string, apply func(*v1.Node)) *v1.Node { return test.BuildTestNode(name, 2000, 3000, 10, apply) } +func setNodeMainRegionLabel(node *v1.Node) { + node.ObjectMeta.Labels = map[string]string{ + "region": "main-region", + } +} + func TestPodAntiAffinity(t *testing.T) { - node1 := buildTestNode(nodeName1, func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - "region": "main-region", - } - }) + node1 := buildTestNode(nodeName1, setNodeMainRegionLabel) node2 := buildTestNode(nodeName2, func(node *v1.Node) { node.ObjectMeta.Labels = map[string]string{ "datacenter": "east", @@ -62,11 +64,7 @@ func TestPodAntiAffinity(t *testing.T) { } }) node4 := test.BuildTestNode(nodeName4, 2, 2, 1, nil) - node5 := test.BuildTestNode(nodeName5, 200, 3000, 10, func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - "region": "main-region", - } - }) + node5 := test.BuildTestNode(nodeName5, 200, 3000, 10, setNodeMainRegionLabel) p1 := test.BuildTestPod("p1", 100, 0, nodeName1, nil) p2 := test.BuildTestPod("p2", 100, 0, nodeName1, nil) From 4ffabad669717c3dfcc64d8c1a0c20d1984721f1 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:45:07 +0100 Subject: [PATCH 04/39] refactor(TestPodAntiAffinity): create buildTestNode1 and inline node1 --- .../pod_antiaffinity_test.go | 117 +++++++++++------- 1 file changed, 74 insertions(+), 43 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 878262b1e..6f403c760 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -51,8 +51,11 @@ func setNodeMainRegionLabel(node *v1.Node) { } } +func buildTestNode1() *v1.Node { + return buildTestNode(nodeName1, setNodeMainRegionLabel) +} + func TestPodAntiAffinity(t *testing.T) { - node1 := buildTestNode(nodeName1, setNodeMainRegionLabel) node2 := buildTestNode(nodeName2, func(node *v1.Node) { node.ObjectMeta.Labels = map[string]string{ "datacenter": "east", @@ -135,87 +138,115 @@ func TestPodAntiAffinity(t *testing.T) { nodes []*v1.Node }{ { - description: "Maximum pods to evict - 0", - pods: []*v1.Pod{p1, p2, p3, p4}, - nodes: []*v1.Node{node1}, + description: "Maximum pods to evict - 0", + pods: []*v1.Pod{p1, p2, p3, p4}, + nodes: []*v1.Node{ + buildTestNode1(), + }, expectedEvictedPodCount: 3, }, { - description: "Maximum pods to evict - 3", - maxPodsToEvictPerNode: &uint3, - pods: []*v1.Pod{p1, p2, p3, p4}, - nodes: []*v1.Node{node1}, + description: "Maximum pods to evict - 3", + maxPodsToEvictPerNode: &uint3, + pods: []*v1.Pod{p1, p2, p3, p4}, + nodes: []*v1.Node{ + buildTestNode1(), + }, expectedEvictedPodCount: 3, }, { description: "Maximum pods to evict (maxPodsToEvictPerNamespace=3) - 3", maxNoOfPodsToEvictPerNamespace: &uint3, pods: []*v1.Pod{p1, p2, p3, p4}, - nodes: []*v1.Node{node1}, - expectedEvictedPodCount: 3, + nodes: []*v1.Node{ + buildTestNode1(), + }, + expectedEvictedPodCount: 3, }, { description: "Maximum pods to evict (maxNoOfPodsToEvictTotal)", maxNoOfPodsToEvictPerNamespace: &uint3, maxNoOfPodsToEvictTotal: &uint1, pods: []*v1.Pod{p1, p2, p3, p4}, - nodes: []*v1.Node{node1}, - expectedEvictedPodCount: 1, - }, - { - description: "Evict only 1 pod after sorting", - pods: []*v1.Pod{p5, p6, p7}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{ + buildTestNode1(), + }, expectedEvictedPodCount: 1, }, { - description: "Evicts pod that conflicts with critical pod (but does not evict critical pod)", - maxPodsToEvictPerNode: &uint1, - pods: []*v1.Pod{p1, nonEvictablePod}, - nodes: []*v1.Node{node1}, + description: "Evict only 1 pod after sorting", + pods: []*v1.Pod{p5, p6, p7}, + nodes: []*v1.Node{ + buildTestNode1(), + }, expectedEvictedPodCount: 1, }, { - description: "Evicts pod that conflicts with critical pod (but does not evict critical pod)", - maxPodsToEvictPerNode: &uint1, - pods: []*v1.Pod{p1, nonEvictablePod}, - nodes: []*v1.Node{node1}, + description: "Evicts pod that conflicts with critical pod (but does not evict critical pod)", + maxPodsToEvictPerNode: &uint1, + pods: []*v1.Pod{p1, nonEvictablePod}, + nodes: []*v1.Node{ + buildTestNode1(), + }, expectedEvictedPodCount: 1, }, { - description: "Won't evict pods because node selectors don't match available nodes", - maxPodsToEvictPerNode: &uint1, - pods: []*v1.Pod{p8, nonEvictablePod}, - nodes: []*v1.Node{node1, node2}, + description: "Evicts pod that conflicts with critical pod (but does not evict critical pod)", + maxPodsToEvictPerNode: &uint1, + pods: []*v1.Pod{p1, nonEvictablePod}, + nodes: []*v1.Node{ + buildTestNode1(), + }, + expectedEvictedPodCount: 1, + }, + { + description: "Won't evict pods because node selectors don't match available nodes", + maxPodsToEvictPerNode: &uint1, + pods: []*v1.Pod{p8, nonEvictablePod}, + nodes: []*v1.Node{ + buildTestNode1(), + node2, + }, expectedEvictedPodCount: 0, nodeFit: true, }, { - description: "Won't evict pods because only other node is not schedulable", - maxPodsToEvictPerNode: &uint1, - pods: []*v1.Pod{p8, nonEvictablePod}, - nodes: []*v1.Node{node1, node3}, + description: "Won't evict pods because only other node is not schedulable", + maxPodsToEvictPerNode: &uint1, + pods: []*v1.Pod{p8, nonEvictablePod}, + nodes: []*v1.Node{ + buildTestNode1(), + node3, + }, expectedEvictedPodCount: 0, nodeFit: true, }, { - description: "No pod to evicted since all pod terminating", - pods: []*v1.Pod{p9, p10}, - nodes: []*v1.Node{node1}, + description: "No pod to evicted since all pod terminating", + pods: []*v1.Pod{p9, p10}, + nodes: []*v1.Node{ + buildTestNode1(), + }, expectedEvictedPodCount: 0, }, { - description: "Won't evict pods because only other node doesn't have enough resources", - maxPodsToEvictPerNode: &uint3, - pods: []*v1.Pod{p1, p2, p3, p4}, - nodes: []*v1.Node{node1, node4}, + description: "Won't evict pods because only other node doesn't have enough resources", + maxPodsToEvictPerNode: &uint3, + pods: []*v1.Pod{p1, p2, p3, p4}, + nodes: []*v1.Node{ + buildTestNode1(), + node4, + }, expectedEvictedPodCount: 0, nodeFit: true, }, { - description: "Evict pod violating anti-affinity among different node (all pods have anti-affinity)", - pods: []*v1.Pod{p1, p11}, - nodes: []*v1.Node{node1, node5}, + description: "Evict pod violating anti-affinity among different node (all pods have anti-affinity)", + pods: []*v1.Pod{p1, p11}, + nodes: []*v1.Node{ + buildTestNode1(), + node5, + }, expectedEvictedPodCount: 1, nodeFit: false, }, From b797ca6ba278695c6d0cb189253700c72dc0cf58 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:47:04 +0100 Subject: [PATCH 05/39] refactor(TestPodAntiAffinity): inline node2, node3, node4, and node5 --- .../pod_antiaffinity_test.go | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 6f403c760..1a8d35219 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -56,18 +56,6 @@ func buildTestNode1() *v1.Node { } func TestPodAntiAffinity(t *testing.T) { - node2 := buildTestNode(nodeName2, func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - "datacenter": "east", - } - }) - node3 := buildTestNode(nodeName3, func(node *v1.Node) { - node.Spec = v1.NodeSpec{ - Unschedulable: true, - } - }) - node4 := test.BuildTestNode(nodeName4, 2, 2, 1, nil) - node5 := test.BuildTestNode(nodeName5, 200, 3000, 10, setNodeMainRegionLabel) p1 := test.BuildTestPod("p1", 100, 0, nodeName1, nil) p2 := test.BuildTestPod("p2", 100, 0, nodeName1, nil) @@ -205,7 +193,11 @@ func TestPodAntiAffinity(t *testing.T) { pods: []*v1.Pod{p8, nonEvictablePod}, nodes: []*v1.Node{ buildTestNode1(), - node2, + buildTestNode(nodeName2, func(node *v1.Node) { + node.ObjectMeta.Labels = map[string]string{ + "datacenter": "east", + } + }), }, expectedEvictedPodCount: 0, nodeFit: true, @@ -216,7 +208,11 @@ func TestPodAntiAffinity(t *testing.T) { pods: []*v1.Pod{p8, nonEvictablePod}, nodes: []*v1.Node{ buildTestNode1(), - node3, + buildTestNode(nodeName3, func(node *v1.Node) { + node.Spec = v1.NodeSpec{ + Unschedulable: true, + } + }), }, expectedEvictedPodCount: 0, nodeFit: true, @@ -235,7 +231,7 @@ func TestPodAntiAffinity(t *testing.T) { pods: []*v1.Pod{p1, p2, p3, p4}, nodes: []*v1.Node{ buildTestNode1(), - node4, + test.BuildTestNode(nodeName4, 2, 2, 1, nil), }, expectedEvictedPodCount: 0, nodeFit: true, @@ -245,7 +241,7 @@ func TestPodAntiAffinity(t *testing.T) { pods: []*v1.Pod{p1, p11}, nodes: []*v1.Node{ buildTestNode1(), - node5, + test.BuildTestNode(nodeName5, 200, 3000, 10, setNodeMainRegionLabel), }, expectedEvictedPodCount: 1, nodeFit: false, From 6e753ac5fb99de8fed2df3d50d0ade21affc75cd Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:52:02 +0100 Subject: [PATCH 06/39] refactor(TestPodAntiAffinity): create buildTestPod helper to deduplicate 100 and 0 literals --- .../pod_antiaffinity_test.go | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 1a8d35219..c1a95fac6 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -55,24 +55,28 @@ func buildTestNode1() *v1.Node { return buildTestNode(nodeName1, setNodeMainRegionLabel) } +func buildTestPod(name, nodeName string, apply func(*v1.Pod)) *v1.Pod { + return test.BuildTestPod(name, 100, 0, nodeName, apply) +} + func TestPodAntiAffinity(t *testing.T) { - p1 := test.BuildTestPod("p1", 100, 0, nodeName1, nil) - p2 := test.BuildTestPod("p2", 100, 0, nodeName1, nil) - p3 := test.BuildTestPod("p3", 100, 0, nodeName1, nil) - p4 := test.BuildTestPod("p4", 100, 0, nodeName1, nil) - p5 := test.BuildTestPod("p5", 100, 0, nodeName1, nil) - p6 := test.BuildTestPod("p6", 100, 0, nodeName1, nil) - p7 := test.BuildTestPod("p7", 100, 0, nodeName1, nil) - p8 := test.BuildTestPod("p8", 100, 0, nodeName1, nil) - p9 := test.BuildTestPod("p9", 100, 0, nodeName1, nil) - p10 := test.BuildTestPod("p10", 100, 0, nodeName1, nil) - p11 := test.BuildTestPod("p11", 100, 0, nodeName5, nil) + p1 := buildTestPod("p1", nodeName1, nil) + p2 := buildTestPod("p2", nodeName1, nil) + p3 := buildTestPod("p3", nodeName1, nil) + p4 := buildTestPod("p4", nodeName1, nil) + p5 := buildTestPod("p5", nodeName1, nil) + p6 := buildTestPod("p6", nodeName1, nil) + p7 := buildTestPod("p7", nodeName1, nil) + p8 := buildTestPod("p8", nodeName1, nil) + p9 := buildTestPod("p9", nodeName1, nil) + p10 := buildTestPod("p10", nodeName1, nil) + p11 := buildTestPod("p11", nodeName5, nil) p9.DeletionTimestamp = &metav1.Time{} p10.DeletionTimestamp = &metav1.Time{} criticalPriority := utils.SystemCriticalPriority - nonEvictablePod := test.BuildTestPod("non-evict", 100, 0, nodeName1, func(pod *v1.Pod) { + nonEvictablePod := buildTestPod("non-evict", nodeName1, func(pod *v1.Pod) { pod.Spec.Priority = &criticalPriority }) p2.Labels = map[string]string{"foo": "bar"} From 18f847bbe8d32dbcf20f45ae2bc80604a11d765e Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:54:42 +0100 Subject: [PATCH 07/39] refactor(TestPodAntiAffinity): create buildTestPodForNode1 to deduplicate nodeName1 --- .../pod_antiaffinity_test.go | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index c1a95fac6..14a360370 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -59,24 +59,28 @@ func buildTestPod(name, nodeName string, apply func(*v1.Pod)) *v1.Pod { return test.BuildTestPod(name, 100, 0, nodeName, apply) } +func buildTestPodForNode1(name string, apply func(*v1.Pod)) *v1.Pod { + return buildTestPod(name, nodeName1, apply) +} + func TestPodAntiAffinity(t *testing.T) { - p1 := buildTestPod("p1", nodeName1, nil) - p2 := buildTestPod("p2", nodeName1, nil) - p3 := buildTestPod("p3", nodeName1, nil) - p4 := buildTestPod("p4", nodeName1, nil) - p5 := buildTestPod("p5", nodeName1, nil) - p6 := buildTestPod("p6", nodeName1, nil) - p7 := buildTestPod("p7", nodeName1, nil) - p8 := buildTestPod("p8", nodeName1, nil) - p9 := buildTestPod("p9", nodeName1, nil) - p10 := buildTestPod("p10", nodeName1, nil) + p1 := buildTestPodForNode1("p1", nil) + p2 := buildTestPodForNode1("p2", nil) + p3 := buildTestPodForNode1("p3", nil) + p4 := buildTestPodForNode1("p4", nil) + p5 := buildTestPodForNode1("p5", nil) + p6 := buildTestPodForNode1("p6", nil) + p7 := buildTestPodForNode1("p7", nil) + p8 := buildTestPodForNode1("p8", nil) + p9 := buildTestPodForNode1("p9", nil) + p10 := buildTestPodForNode1("p10", nil) p11 := buildTestPod("p11", nodeName5, nil) p9.DeletionTimestamp = &metav1.Time{} p10.DeletionTimestamp = &metav1.Time{} criticalPriority := utils.SystemCriticalPriority - nonEvictablePod := buildTestPod("non-evict", nodeName1, func(pod *v1.Pod) { + nonEvictablePod := buildTestPodForNode1("non-evict", func(pod *v1.Pod) { pod.Spec.Priority = &criticalPriority }) p2.Labels = map[string]string{"foo": "bar"} From c5b9debe56dc6576cbf453690ce8a588f295cfc9 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:57:19 +0100 Subject: [PATCH 08/39] refactor(TestPodAntiAffinity): ensure p1 is created only through apply argument --- .../pod_antiaffinity_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 14a360370..c270ff703 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -65,7 +65,10 @@ func buildTestPodForNode1(name string, apply func(*v1.Pod)) *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p1 := buildTestPodForNode1("p1", nil) + p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + test.SetPodAntiAffinity(pod, "foo", "bar") + }) p2 := buildTestPodForNode1("p2", nil) p3 := buildTestPodForNode1("p3", nil) p4 := buildTestPodForNode1("p4", nil) @@ -89,7 +92,6 @@ func TestPodAntiAffinity(t *testing.T) { p7.Labels = map[string]string{"foo1": "bar1"} p11.Labels = map[string]string{"foo": "bar"} nonEvictablePod.Labels = map[string]string{"foo": "bar"} - test.SetNormalOwnerRef(p1) test.SetNormalOwnerRef(p2) test.SetNormalOwnerRef(p3) test.SetNormalOwnerRef(p4) @@ -101,7 +103,6 @@ func TestPodAntiAffinity(t *testing.T) { test.SetNormalOwnerRef(p11) // set pod anti affinity - test.SetPodAntiAffinity(p1, "foo", "bar") test.SetPodAntiAffinity(p3, "foo", "bar") test.SetPodAntiAffinity(p4, "foo", "bar") test.SetPodAntiAffinity(p5, "foo1", "bar1") From da55c779f2f23b8bee33ecd3c6a663c0855f67be Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:18:50 +0100 Subject: [PATCH 09/39] refactor(TestPodAntiAffinity): ensure p2 is created only through apply argument --- .../pod_antiaffinity_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index c270ff703..12c5f24a9 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -69,7 +69,10 @@ func TestPodAntiAffinity(t *testing.T) { test.SetNormalOwnerRef(pod) test.SetPodAntiAffinity(pod, "foo", "bar") }) - p2 := buildTestPodForNode1("p2", nil) + p2 := buildTestPodForNode1("p2", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + pod.Labels = map[string]string{"foo": "bar"} + }) p3 := buildTestPodForNode1("p3", nil) p4 := buildTestPodForNode1("p4", nil) p5 := buildTestPodForNode1("p5", nil) @@ -86,13 +89,11 @@ func TestPodAntiAffinity(t *testing.T) { nonEvictablePod := buildTestPodForNode1("non-evict", func(pod *v1.Pod) { pod.Spec.Priority = &criticalPriority }) - p2.Labels = map[string]string{"foo": "bar"} p5.Labels = map[string]string{"foo": "bar"} p6.Labels = map[string]string{"foo": "bar"} p7.Labels = map[string]string{"foo1": "bar1"} p11.Labels = map[string]string{"foo": "bar"} nonEvictablePod.Labels = map[string]string{"foo": "bar"} - test.SetNormalOwnerRef(p2) test.SetNormalOwnerRef(p3) test.SetNormalOwnerRef(p4) test.SetNormalOwnerRef(p5) From cf79af6fbafc2986d4bbb0c3e8a93938c826e0d8 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:19:38 +0100 Subject: [PATCH 10/39] refactor(TestPodAntiAffinity): ensure p3 is created only through apply argument --- .../pod_antiaffinity_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 12c5f24a9..041fa2577 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -73,7 +73,10 @@ func TestPodAntiAffinity(t *testing.T) { test.SetNormalOwnerRef(pod) pod.Labels = map[string]string{"foo": "bar"} }) - p3 := buildTestPodForNode1("p3", nil) + p3 := buildTestPodForNode1("p3", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + test.SetPodAntiAffinity(pod, "foo", "bar") + }) p4 := buildTestPodForNode1("p4", nil) p5 := buildTestPodForNode1("p5", nil) p6 := buildTestPodForNode1("p6", nil) @@ -94,7 +97,6 @@ func TestPodAntiAffinity(t *testing.T) { p7.Labels = map[string]string{"foo1": "bar1"} p11.Labels = map[string]string{"foo": "bar"} nonEvictablePod.Labels = map[string]string{"foo": "bar"} - test.SetNormalOwnerRef(p3) test.SetNormalOwnerRef(p4) test.SetNormalOwnerRef(p5) test.SetNormalOwnerRef(p6) @@ -104,7 +106,6 @@ func TestPodAntiAffinity(t *testing.T) { test.SetNormalOwnerRef(p11) // set pod anti affinity - test.SetPodAntiAffinity(p3, "foo", "bar") test.SetPodAntiAffinity(p4, "foo", "bar") test.SetPodAntiAffinity(p5, "foo1", "bar1") test.SetPodAntiAffinity(p6, "foo1", "bar1") From 99527292e0f9887951be30f2ab50be2991294a1a Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:20:06 +0100 Subject: [PATCH 11/39] refactor(TestPodAntiAffinity): ensure p4 is created only through apply argument --- .../pod_antiaffinity_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 041fa2577..e8baa9f86 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -77,7 +77,10 @@ func TestPodAntiAffinity(t *testing.T) { test.SetNormalOwnerRef(pod) test.SetPodAntiAffinity(pod, "foo", "bar") }) - p4 := buildTestPodForNode1("p4", nil) + p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + test.SetPodAntiAffinity(pod, "foo", "bar") + }) p5 := buildTestPodForNode1("p5", nil) p6 := buildTestPodForNode1("p6", nil) p7 := buildTestPodForNode1("p7", nil) @@ -97,7 +100,6 @@ func TestPodAntiAffinity(t *testing.T) { p7.Labels = map[string]string{"foo1": "bar1"} p11.Labels = map[string]string{"foo": "bar"} nonEvictablePod.Labels = map[string]string{"foo": "bar"} - test.SetNormalOwnerRef(p4) test.SetNormalOwnerRef(p5) test.SetNormalOwnerRef(p6) test.SetNormalOwnerRef(p7) @@ -106,7 +108,6 @@ func TestPodAntiAffinity(t *testing.T) { test.SetNormalOwnerRef(p11) // set pod anti affinity - test.SetPodAntiAffinity(p4, "foo", "bar") test.SetPodAntiAffinity(p5, "foo1", "bar1") test.SetPodAntiAffinity(p6, "foo1", "bar1") test.SetPodAntiAffinity(p7, "foo", "bar") From 4b86cdd31a35f4195e52c1eb80202797755b2317 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:20:53 +0100 Subject: [PATCH 12/39] refactor(TestPodAntiAffinity): ensure p5 is created only through apply argument --- .../pod_antiaffinity_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index e8baa9f86..459d75e1b 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -81,7 +81,12 @@ func TestPodAntiAffinity(t *testing.T) { test.SetNormalOwnerRef(pod) test.SetPodAntiAffinity(pod, "foo", "bar") }) - p5 := buildTestPodForNode1("p5", nil) + p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + pod.Labels = map[string]string{"foo": "bar"} + test.SetPodAntiAffinity(pod, "foo1", "bar1") + test.SetPodPriority(pod, 100) + }) p6 := buildTestPodForNode1("p6", nil) p7 := buildTestPodForNode1("p7", nil) p8 := buildTestPodForNode1("p8", nil) @@ -95,12 +100,10 @@ func TestPodAntiAffinity(t *testing.T) { nonEvictablePod := buildTestPodForNode1("non-evict", func(pod *v1.Pod) { pod.Spec.Priority = &criticalPriority }) - p5.Labels = map[string]string{"foo": "bar"} p6.Labels = map[string]string{"foo": "bar"} p7.Labels = map[string]string{"foo1": "bar1"} p11.Labels = map[string]string{"foo": "bar"} nonEvictablePod.Labels = map[string]string{"foo": "bar"} - test.SetNormalOwnerRef(p5) test.SetNormalOwnerRef(p6) test.SetNormalOwnerRef(p7) test.SetNormalOwnerRef(p9) @@ -108,14 +111,12 @@ func TestPodAntiAffinity(t *testing.T) { test.SetNormalOwnerRef(p11) // set pod anti affinity - test.SetPodAntiAffinity(p5, "foo1", "bar1") test.SetPodAntiAffinity(p6, "foo1", "bar1") test.SetPodAntiAffinity(p7, "foo", "bar") test.SetPodAntiAffinity(p9, "foo", "bar") test.SetPodAntiAffinity(p10, "foo", "bar") // set pod priority - test.SetPodPriority(p5, 100) test.SetPodPriority(p6, 50) test.SetPodPriority(p7, 0) From d5e0ec597fe1991ea2ce7c17a590b0df5a740e2e Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:21:32 +0100 Subject: [PATCH 13/39] refactor(TestPodAntiAffinity): ensure p6 is created only through apply argument --- .../pod_antiaffinity_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 459d75e1b..94f4b2b01 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -87,7 +87,12 @@ func TestPodAntiAffinity(t *testing.T) { test.SetPodAntiAffinity(pod, "foo1", "bar1") test.SetPodPriority(pod, 100) }) - p6 := buildTestPodForNode1("p6", nil) + p6 := buildTestPodForNode1("p6", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + pod.Labels = map[string]string{"foo": "bar"} + test.SetPodAntiAffinity(pod, "foo1", "bar1") + test.SetPodPriority(pod, 50) + }) p7 := buildTestPodForNode1("p7", nil) p8 := buildTestPodForNode1("p8", nil) p9 := buildTestPodForNode1("p9", nil) @@ -100,24 +105,20 @@ func TestPodAntiAffinity(t *testing.T) { nonEvictablePod := buildTestPodForNode1("non-evict", func(pod *v1.Pod) { pod.Spec.Priority = &criticalPriority }) - p6.Labels = map[string]string{"foo": "bar"} p7.Labels = map[string]string{"foo1": "bar1"} p11.Labels = map[string]string{"foo": "bar"} nonEvictablePod.Labels = map[string]string{"foo": "bar"} - test.SetNormalOwnerRef(p6) test.SetNormalOwnerRef(p7) test.SetNormalOwnerRef(p9) test.SetNormalOwnerRef(p10) test.SetNormalOwnerRef(p11) // set pod anti affinity - test.SetPodAntiAffinity(p6, "foo1", "bar1") test.SetPodAntiAffinity(p7, "foo", "bar") test.SetPodAntiAffinity(p9, "foo", "bar") test.SetPodAntiAffinity(p10, "foo", "bar") // set pod priority - test.SetPodPriority(p6, 50) test.SetPodPriority(p7, 0) // Set pod node selectors From 5ad695166adb629880cfba58a417693c4602af35 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:22:12 +0100 Subject: [PATCH 14/39] refactor(TestPodAntiAffinity): ensure p7 is created only through apply argument --- .../pod_antiaffinity_test.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 94f4b2b01..23c86c790 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -93,7 +93,12 @@ func TestPodAntiAffinity(t *testing.T) { test.SetPodAntiAffinity(pod, "foo1", "bar1") test.SetPodPriority(pod, 50) }) - p7 := buildTestPodForNode1("p7", nil) + p7 := buildTestPodForNode1("p7", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + pod.Labels = map[string]string{"foo1": "bar1"} + test.SetPodAntiAffinity(pod, "foo", "bar") + test.SetPodPriority(pod, 0) + }) p8 := buildTestPodForNode1("p8", nil) p9 := buildTestPodForNode1("p9", nil) p10 := buildTestPodForNode1("p10", nil) @@ -105,22 +110,16 @@ func TestPodAntiAffinity(t *testing.T) { nonEvictablePod := buildTestPodForNode1("non-evict", func(pod *v1.Pod) { pod.Spec.Priority = &criticalPriority }) - p7.Labels = map[string]string{"foo1": "bar1"} p11.Labels = map[string]string{"foo": "bar"} nonEvictablePod.Labels = map[string]string{"foo": "bar"} - test.SetNormalOwnerRef(p7) test.SetNormalOwnerRef(p9) test.SetNormalOwnerRef(p10) test.SetNormalOwnerRef(p11) // set pod anti affinity - test.SetPodAntiAffinity(p7, "foo", "bar") test.SetPodAntiAffinity(p9, "foo", "bar") test.SetPodAntiAffinity(p10, "foo", "bar") - // set pod priority - test.SetPodPriority(p7, 0) - // Set pod node selectors p8.Spec.NodeSelector = map[string]string{ "datacenter": "west", From 116385718f87a522b7fbbbba37cd990521959f8b Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:22:35 +0100 Subject: [PATCH 15/39] refactor(TestPodAntiAffinity): ensure p8 is created only through apply argument --- .../pod_antiaffinity_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 23c86c790..5b911d9bb 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -99,7 +99,11 @@ func TestPodAntiAffinity(t *testing.T) { test.SetPodAntiAffinity(pod, "foo", "bar") test.SetPodPriority(pod, 0) }) - p8 := buildTestPodForNode1("p8", nil) + p8 := buildTestPodForNode1("p8", func(pod *v1.Pod) { + pod.Spec.NodeSelector = map[string]string{ + "datacenter": "west", + } + }) p9 := buildTestPodForNode1("p9", nil) p10 := buildTestPodForNode1("p10", nil) p11 := buildTestPod("p11", nodeName5, nil) @@ -120,11 +124,6 @@ func TestPodAntiAffinity(t *testing.T) { test.SetPodAntiAffinity(p9, "foo", "bar") test.SetPodAntiAffinity(p10, "foo", "bar") - // Set pod node selectors - p8.Spec.NodeSelector = map[string]string{ - "datacenter": "west", - } - var uint1 uint = 1 var uint3 uint = 3 From 6638b976ad3aae7da114c49b741be6f381750641 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:23:10 +0100 Subject: [PATCH 16/39] refactor(TestPodAntiAffinity): ensure p9 is created only through apply argument --- .../pod_antiaffinity_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 5b911d9bb..9cab9b4af 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -104,10 +104,13 @@ func TestPodAntiAffinity(t *testing.T) { "datacenter": "west", } }) - p9 := buildTestPodForNode1("p9", nil) + p9 := buildTestPodForNode1("p9", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + test.SetPodAntiAffinity(pod, "foo", "bar") + pod.DeletionTimestamp = &metav1.Time{} + }) p10 := buildTestPodForNode1("p10", nil) p11 := buildTestPod("p11", nodeName5, nil) - p9.DeletionTimestamp = &metav1.Time{} p10.DeletionTimestamp = &metav1.Time{} criticalPriority := utils.SystemCriticalPriority @@ -116,12 +119,10 @@ func TestPodAntiAffinity(t *testing.T) { }) p11.Labels = map[string]string{"foo": "bar"} nonEvictablePod.Labels = map[string]string{"foo": "bar"} - test.SetNormalOwnerRef(p9) test.SetNormalOwnerRef(p10) test.SetNormalOwnerRef(p11) // set pod anti affinity - test.SetPodAntiAffinity(p9, "foo", "bar") test.SetPodAntiAffinity(p10, "foo", "bar") var uint1 uint = 1 From ea80f7d3075384ba756a42ac735b8e27c92f7296 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:23:46 +0100 Subject: [PATCH 17/39] refactor(TestPodAntiAffinity): ensure p10 is created only through apply argument --- .../pod_antiaffinity_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 9cab9b4af..ed373090c 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -109,9 +109,12 @@ func TestPodAntiAffinity(t *testing.T) { test.SetPodAntiAffinity(pod, "foo", "bar") pod.DeletionTimestamp = &metav1.Time{} }) - p10 := buildTestPodForNode1("p10", nil) + p10 := buildTestPodForNode1("p10", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + test.SetPodAntiAffinity(pod, "foo", "bar") + pod.DeletionTimestamp = &metav1.Time{} + }) p11 := buildTestPod("p11", nodeName5, nil) - p10.DeletionTimestamp = &metav1.Time{} criticalPriority := utils.SystemCriticalPriority nonEvictablePod := buildTestPodForNode1("non-evict", func(pod *v1.Pod) { @@ -119,12 +122,8 @@ func TestPodAntiAffinity(t *testing.T) { }) p11.Labels = map[string]string{"foo": "bar"} nonEvictablePod.Labels = map[string]string{"foo": "bar"} - test.SetNormalOwnerRef(p10) test.SetNormalOwnerRef(p11) - // set pod anti affinity - test.SetPodAntiAffinity(p10, "foo", "bar") - var uint1 uint = 1 var uint3 uint = 3 From 0e568238657b660ccb4fbe02e389578bb1853495 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:24:09 +0100 Subject: [PATCH 18/39] refactor(TestPodAntiAffinity): ensure p11 is created only through apply argument --- .../pod_antiaffinity_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index ed373090c..b0e9a4c9a 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -114,15 +114,16 @@ func TestPodAntiAffinity(t *testing.T) { test.SetPodAntiAffinity(pod, "foo", "bar") pod.DeletionTimestamp = &metav1.Time{} }) - p11 := buildTestPod("p11", nodeName5, nil) + p11 := buildTestPod("p11", nodeName5, func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + pod.Labels = map[string]string{"foo": "bar"} + }) criticalPriority := utils.SystemCriticalPriority nonEvictablePod := buildTestPodForNode1("non-evict", func(pod *v1.Pod) { pod.Spec.Priority = &criticalPriority }) - p11.Labels = map[string]string{"foo": "bar"} nonEvictablePod.Labels = map[string]string{"foo": "bar"} - test.SetNormalOwnerRef(p11) var uint1 uint = 1 var uint3 uint = 3 From 3072a59ea07e48fb8764b88433cf8ff79dc4048f Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:24:50 +0100 Subject: [PATCH 19/39] refactor(TestPodAntiAffinity): ensure nonEvictablePod is created only through apply argument --- .../pod_antiaffinity_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index b0e9a4c9a..0b1d1ba55 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -119,11 +119,11 @@ func TestPodAntiAffinity(t *testing.T) { pod.Labels = map[string]string{"foo": "bar"} }) - criticalPriority := utils.SystemCriticalPriority nonEvictablePod := buildTestPodForNode1("non-evict", func(pod *v1.Pod) { + criticalPriority := utils.SystemCriticalPriority pod.Spec.Priority = &criticalPriority + pod.Labels = map[string]string{"foo": "bar"} }) - nonEvictablePod.Labels = map[string]string{"foo": "bar"} var uint1 uint = 1 var uint3 uint = 3 From 9413b0c65477089053f00ab9424bb018fc0cd609 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:34:05 +0100 Subject: [PATCH 20/39] refactor(TestPodAntiAffinity): deduplicate setPodAntiAffinity for foo-bar --- .../pod_antiaffinity_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 0b1d1ba55..aee4e28dd 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -63,11 +63,15 @@ func buildTestPodForNode1(name string, apply func(*v1.Pod)) *v1.Pod { return buildTestPod(name, nodeName1, apply) } +func setPodAntiAffinityFooBar(pod *v1.Pod) { + test.SetPodAntiAffinity(pod, "foo", "bar") +} + func TestPodAntiAffinity(t *testing.T) { p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) - test.SetPodAntiAffinity(pod, "foo", "bar") + setPodAntiAffinityFooBar(pod) }) p2 := buildTestPodForNode1("p2", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) @@ -75,11 +79,11 @@ func TestPodAntiAffinity(t *testing.T) { }) p3 := buildTestPodForNode1("p3", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) - test.SetPodAntiAffinity(pod, "foo", "bar") + setPodAntiAffinityFooBar(pod) }) p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) - test.SetPodAntiAffinity(pod, "foo", "bar") + setPodAntiAffinityFooBar(pod) }) p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) @@ -96,7 +100,7 @@ func TestPodAntiAffinity(t *testing.T) { p7 := buildTestPodForNode1("p7", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) pod.Labels = map[string]string{"foo1": "bar1"} - test.SetPodAntiAffinity(pod, "foo", "bar") + setPodAntiAffinityFooBar(pod) test.SetPodPriority(pod, 0) }) p8 := buildTestPodForNode1("p8", func(pod *v1.Pod) { @@ -106,12 +110,12 @@ func TestPodAntiAffinity(t *testing.T) { }) p9 := buildTestPodForNode1("p9", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) - test.SetPodAntiAffinity(pod, "foo", "bar") + setPodAntiAffinityFooBar(pod) pod.DeletionTimestamp = &metav1.Time{} }) p10 := buildTestPodForNode1("p10", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) - test.SetPodAntiAffinity(pod, "foo", "bar") + setPodAntiAffinityFooBar(pod) pod.DeletionTimestamp = &metav1.Time{} }) p11 := buildTestPod("p11", nodeName5, func(pod *v1.Pod) { From 6a002144576cee020634231f77e92572d4305543 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:36:27 +0100 Subject: [PATCH 21/39] refactor(TestPodAntiAffinity): deduplicate setPodAntiAffinity for foo1-bar1 --- .../pod_antiaffinity_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index aee4e28dd..cb7d351f4 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -67,6 +67,10 @@ func setPodAntiAffinityFooBar(pod *v1.Pod) { test.SetPodAntiAffinity(pod, "foo", "bar") } +func setPodAntiAffinityFoo1Bar1(pod *v1.Pod) { + test.SetPodAntiAffinity(pod, "foo1", "bar1") +} + func TestPodAntiAffinity(t *testing.T) { p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { @@ -88,13 +92,13 @@ func TestPodAntiAffinity(t *testing.T) { p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) pod.Labels = map[string]string{"foo": "bar"} - test.SetPodAntiAffinity(pod, "foo1", "bar1") + setPodAntiAffinityFoo1Bar1(pod) test.SetPodPriority(pod, 100) }) p6 := buildTestPodForNode1("p6", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) pod.Labels = map[string]string{"foo": "bar"} - test.SetPodAntiAffinity(pod, "foo1", "bar1") + setPodAntiAffinityFoo1Bar1(pod) test.SetPodPriority(pod, 50) }) p7 := buildTestPodForNode1("p7", func(pod *v1.Pod) { From 90672630dadcca6e686b74ee857b08be6c093e0e Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:37:55 +0100 Subject: [PATCH 22/39] refactor(TestPodAntiAffinity): deduplicate setting Labels for foo-bar --- .../pod_antiaffinity_test.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index cb7d351f4..9edace273 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -71,6 +71,10 @@ func setPodAntiAffinityFoo1Bar1(pod *v1.Pod) { test.SetPodAntiAffinity(pod, "foo1", "bar1") } +func setLabelsFooBar(pod *v1.Pod) { + pod.Labels = map[string]string{"foo": "bar"} +} + func TestPodAntiAffinity(t *testing.T) { p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { @@ -79,7 +83,7 @@ func TestPodAntiAffinity(t *testing.T) { }) p2 := buildTestPodForNode1("p2", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) - pod.Labels = map[string]string{"foo": "bar"} + setLabelsFooBar(pod) }) p3 := buildTestPodForNode1("p3", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) @@ -91,13 +95,13 @@ func TestPodAntiAffinity(t *testing.T) { }) p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) - pod.Labels = map[string]string{"foo": "bar"} + setLabelsFooBar(pod) setPodAntiAffinityFoo1Bar1(pod) test.SetPodPriority(pod, 100) }) p6 := buildTestPodForNode1("p6", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) - pod.Labels = map[string]string{"foo": "bar"} + setLabelsFooBar(pod) setPodAntiAffinityFoo1Bar1(pod) test.SetPodPriority(pod, 50) }) @@ -124,13 +128,13 @@ func TestPodAntiAffinity(t *testing.T) { }) p11 := buildTestPod("p11", nodeName5, func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) - pod.Labels = map[string]string{"foo": "bar"} + setLabelsFooBar(pod) }) nonEvictablePod := buildTestPodForNode1("non-evict", func(pod *v1.Pod) { criticalPriority := utils.SystemCriticalPriority pod.Spec.Priority = &criticalPriority - pod.Labels = map[string]string{"foo": "bar"} + setLabelsFooBar(pod) }) var uint1 uint = 1 From fa427a2b376797acca44db59a5d100091ce3c1dd Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:38:58 +0100 Subject: [PATCH 23/39] refactor(TestPodAntiAffinity): deduplicate setting Labels for foo1-bar1 --- .../pod_antiaffinity_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 9edace273..8c3070b47 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -75,6 +75,10 @@ func setLabelsFooBar(pod *v1.Pod) { pod.Labels = map[string]string{"foo": "bar"} } +func setLabelsFoo1Bar1(pod *v1.Pod) { + pod.Labels = map[string]string{"foo1": "bar1"} +} + func TestPodAntiAffinity(t *testing.T) { p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { @@ -107,7 +111,7 @@ func TestPodAntiAffinity(t *testing.T) { }) p7 := buildTestPodForNode1("p7", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) - pod.Labels = map[string]string{"foo1": "bar1"} + setLabelsFoo1Bar1(pod) setPodAntiAffinityFooBar(pod) test.SetPodPriority(pod, 0) }) From a400a66d519df642890627c7eb7c11e07e2df76f Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:43:11 +0100 Subject: [PATCH 24/39] refactor(TestPodAntiAffinity): create dedicated builders for p1-p4 and nonEvictablePod --- .../pod_antiaffinity_test.go | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 8c3070b47..fcdb18093 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -79,24 +79,48 @@ func setLabelsFoo1Bar1(pod *v1.Pod) { pod.Labels = map[string]string{"foo1": "bar1"} } -func TestPodAntiAffinity(t *testing.T) { - - p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { +func buildTestPodP1ForNode1() *v1.Pod { + return buildTestPodForNode1("p1", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setPodAntiAffinityFooBar(pod) }) - p2 := buildTestPodForNode1("p2", func(pod *v1.Pod) { +} + +func buildTestPodP2ForNode1() *v1.Pod { + return buildTestPodForNode1("p2", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setLabelsFooBar(pod) }) - p3 := buildTestPodForNode1("p3", func(pod *v1.Pod) { +} + +func buildTestPodP3ForNode1() *v1.Pod { + return buildTestPodForNode1("p3", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setPodAntiAffinityFooBar(pod) }) - p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { +} + +func buildTestPodP4ForNode1() *v1.Pod { + return buildTestPodForNode1("p4", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setPodAntiAffinityFooBar(pod) }) +} + +func buildTestPodNonEvictableForNode1() *v1.Pod { + criticalPriority := utils.SystemCriticalPriority + return buildTestPodForNode1("non-evict", func(pod *v1.Pod) { + pod.Spec.Priority = &criticalPriority + setLabelsFooBar(pod) + }) +} + +func TestPodAntiAffinity(t *testing.T) { + + p1 := buildTestPodP1ForNode1() + p2 := buildTestPodP2ForNode1() + p3 := buildTestPodP3ForNode1() + p4 := buildTestPodP4ForNode1() p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setLabelsFooBar(pod) @@ -135,11 +159,7 @@ func TestPodAntiAffinity(t *testing.T) { setLabelsFooBar(pod) }) - nonEvictablePod := buildTestPodForNode1("non-evict", func(pod *v1.Pod) { - criticalPriority := utils.SystemCriticalPriority - pod.Spec.Priority = &criticalPriority - setLabelsFooBar(pod) - }) + nonEvictablePod := buildTestPodNonEvictableForNode1() var uint1 uint = 1 var uint3 uint = 3 From 87f675a2cdf827657a9fa52431532179e0a87add Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:48:01 +0100 Subject: [PATCH 25/39] refactor(TestPodAntiAffinity): inline p1 --- .../pod_antiaffinity_test.go | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index fcdb18093..f51c01457 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,7 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p1 := buildTestPodP1ForNode1() p2 := buildTestPodP2ForNode1() p3 := buildTestPodP3ForNode1() p4 := buildTestPodP4ForNode1() @@ -176,7 +175,9 @@ func TestPodAntiAffinity(t *testing.T) { }{ { description: "Maximum pods to evict - 0", - pods: []*v1.Pod{p1, p2, p3, p4}, + pods: []*v1.Pod{ + buildTestPodP1ForNode1(), + p2, p3, p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -185,7 +186,9 @@ func TestPodAntiAffinity(t *testing.T) { { description: "Maximum pods to evict - 3", maxPodsToEvictPerNode: &uint3, - pods: []*v1.Pod{p1, p2, p3, p4}, + pods: []*v1.Pod{ + buildTestPodP1ForNode1(), + p2, p3, p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -194,7 +197,9 @@ func TestPodAntiAffinity(t *testing.T) { { description: "Maximum pods to evict (maxPodsToEvictPerNamespace=3) - 3", maxNoOfPodsToEvictPerNamespace: &uint3, - pods: []*v1.Pod{p1, p2, p3, p4}, + pods: []*v1.Pod{ + buildTestPodP1ForNode1(), + p2, p3, p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -204,7 +209,9 @@ func TestPodAntiAffinity(t *testing.T) { description: "Maximum pods to evict (maxNoOfPodsToEvictTotal)", maxNoOfPodsToEvictPerNamespace: &uint3, maxNoOfPodsToEvictTotal: &uint1, - pods: []*v1.Pod{p1, p2, p3, p4}, + pods: []*v1.Pod{ + buildTestPodP1ForNode1(), + p2, p3, p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -221,7 +228,9 @@ func TestPodAntiAffinity(t *testing.T) { { description: "Evicts pod that conflicts with critical pod (but does not evict critical pod)", maxPodsToEvictPerNode: &uint1, - pods: []*v1.Pod{p1, nonEvictablePod}, + pods: []*v1.Pod{ + buildTestPodP1ForNode1(), + nonEvictablePod}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -230,7 +239,9 @@ func TestPodAntiAffinity(t *testing.T) { { description: "Evicts pod that conflicts with critical pod (but does not evict critical pod)", maxPodsToEvictPerNode: &uint1, - pods: []*v1.Pod{p1, nonEvictablePod}, + pods: []*v1.Pod{ + buildTestPodP1ForNode1(), + nonEvictablePod}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -277,7 +288,9 @@ func TestPodAntiAffinity(t *testing.T) { { description: "Won't evict pods because only other node doesn't have enough resources", maxPodsToEvictPerNode: &uint3, - pods: []*v1.Pod{p1, p2, p3, p4}, + pods: []*v1.Pod{ + buildTestPodP1ForNode1(), + p2, p3, p4}, nodes: []*v1.Node{ buildTestNode1(), test.BuildTestNode(nodeName4, 2, 2, 1, nil), @@ -287,7 +300,9 @@ func TestPodAntiAffinity(t *testing.T) { }, { description: "Evict pod violating anti-affinity among different node (all pods have anti-affinity)", - pods: []*v1.Pod{p1, p11}, + pods: []*v1.Pod{ + buildTestPodP1ForNode1(), + p11}, nodes: []*v1.Node{ buildTestNode1(), test.BuildTestNode(nodeName5, 200, 3000, 10, setNodeMainRegionLabel), From 2765e310482662b5bbf947eeee7980279df7bc84 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:51:00 +0100 Subject: [PATCH 26/39] refactor(TestPodAntiAffinity): inline p2 --- .../pod_antiaffinity_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index f51c01457..d5ea677b1 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,7 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p2 := buildTestPodP2ForNode1() p3 := buildTestPodP3ForNode1() p4 := buildTestPodP4ForNode1() p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { @@ -177,7 +176,8 @@ func TestPodAntiAffinity(t *testing.T) { description: "Maximum pods to evict - 0", pods: []*v1.Pod{ buildTestPodP1ForNode1(), - p2, p3, p4}, + buildTestPodP2ForNode1(), + p3, p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -188,7 +188,8 @@ func TestPodAntiAffinity(t *testing.T) { maxPodsToEvictPerNode: &uint3, pods: []*v1.Pod{ buildTestPodP1ForNode1(), - p2, p3, p4}, + buildTestPodP2ForNode1(), + p3, p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -199,7 +200,8 @@ func TestPodAntiAffinity(t *testing.T) { maxNoOfPodsToEvictPerNamespace: &uint3, pods: []*v1.Pod{ buildTestPodP1ForNode1(), - p2, p3, p4}, + buildTestPodP2ForNode1(), + p3, p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -211,7 +213,8 @@ func TestPodAntiAffinity(t *testing.T) { maxNoOfPodsToEvictTotal: &uint1, pods: []*v1.Pod{ buildTestPodP1ForNode1(), - p2, p3, p4}, + buildTestPodP2ForNode1(), + p3, p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -290,7 +293,8 @@ func TestPodAntiAffinity(t *testing.T) { maxPodsToEvictPerNode: &uint3, pods: []*v1.Pod{ buildTestPodP1ForNode1(), - p2, p3, p4}, + buildTestPodP2ForNode1(), + p3, p4}, nodes: []*v1.Node{ buildTestNode1(), test.BuildTestNode(nodeName4, 2, 2, 1, nil), From 87182c5e8ff64faafbbda7cdb2af2cb105009dfe Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:51:58 +0100 Subject: [PATCH 27/39] refactor(TestPodAntiAffinity): inline p3 --- .../pod_antiaffinity_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index d5ea677b1..7e7b3278d 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,7 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p3 := buildTestPodP3ForNode1() p4 := buildTestPodP4ForNode1() p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) @@ -177,7 +176,8 @@ func TestPodAntiAffinity(t *testing.T) { pods: []*v1.Pod{ buildTestPodP1ForNode1(), buildTestPodP2ForNode1(), - p3, p4}, + buildTestPodP3ForNode1(), + p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -189,7 +189,8 @@ func TestPodAntiAffinity(t *testing.T) { pods: []*v1.Pod{ buildTestPodP1ForNode1(), buildTestPodP2ForNode1(), - p3, p4}, + buildTestPodP3ForNode1(), + p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -201,7 +202,8 @@ func TestPodAntiAffinity(t *testing.T) { pods: []*v1.Pod{ buildTestPodP1ForNode1(), buildTestPodP2ForNode1(), - p3, p4}, + buildTestPodP3ForNode1(), + p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -214,7 +216,8 @@ func TestPodAntiAffinity(t *testing.T) { pods: []*v1.Pod{ buildTestPodP1ForNode1(), buildTestPodP2ForNode1(), - p3, p4}, + buildTestPodP3ForNode1(), + p4}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -294,7 +297,8 @@ func TestPodAntiAffinity(t *testing.T) { pods: []*v1.Pod{ buildTestPodP1ForNode1(), buildTestPodP2ForNode1(), - p3, p4}, + buildTestPodP3ForNode1(), + p4}, nodes: []*v1.Node{ buildTestNode1(), test.BuildTestNode(nodeName4, 2, 2, 1, nil), From cbe1c1e559bf93e4f62cc716afa3894edd35d051 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:52:21 +0100 Subject: [PATCH 28/39] refactor(TestPodAntiAffinity): inline p4 --- .../pod_antiaffinity_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 7e7b3278d..40f702360 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,7 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p4 := buildTestPodP4ForNode1() p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setLabelsFooBar(pod) @@ -177,7 +176,7 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPodP1ForNode1(), buildTestPodP2ForNode1(), buildTestPodP3ForNode1(), - p4}, + buildTestPodP4ForNode1()}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -190,7 +189,7 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPodP1ForNode1(), buildTestPodP2ForNode1(), buildTestPodP3ForNode1(), - p4}, + buildTestPodP4ForNode1()}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -203,7 +202,7 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPodP1ForNode1(), buildTestPodP2ForNode1(), buildTestPodP3ForNode1(), - p4}, + buildTestPodP4ForNode1()}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -217,7 +216,7 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPodP1ForNode1(), buildTestPodP2ForNode1(), buildTestPodP3ForNode1(), - p4}, + buildTestPodP4ForNode1()}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -298,7 +297,7 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPodP1ForNode1(), buildTestPodP2ForNode1(), buildTestPodP3ForNode1(), - p4}, + buildTestPodP4ForNode1()}, nodes: []*v1.Node{ buildTestNode1(), test.BuildTestNode(nodeName4, 2, 2, 1, nil), From 9f2d22c1f7d03e1a0c122b36de93ae7d63a91cdf Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:53:19 +0100 Subject: [PATCH 29/39] refactor(TestPodAntiAffinity): inline p5 --- .../pod_antiaffinity_test.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 40f702360..64b3c4f5f 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,12 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { - test.SetNormalOwnerRef(pod) - setLabelsFooBar(pod) - setPodAntiAffinityFoo1Bar1(pod) - test.SetPodPriority(pod, 100) - }) p6 := buildTestPodForNode1("p6", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setLabelsFooBar(pod) @@ -224,7 +218,14 @@ func TestPodAntiAffinity(t *testing.T) { }, { description: "Evict only 1 pod after sorting", - pods: []*v1.Pod{p5, p6, p7}, + pods: []*v1.Pod{ + buildTestPodForNode1("p5", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + setLabelsFooBar(pod) + setPodAntiAffinityFoo1Bar1(pod) + test.SetPodPriority(pod, 100) + }), + p6, p7}, nodes: []*v1.Node{ buildTestNode1(), }, From 03b5a9a967d6d971985cc6e7837abe02c2fdb461 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:53:43 +0100 Subject: [PATCH 30/39] refactor(TestPodAntiAffinity): inline p6 --- .../pod_antiaffinity_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 64b3c4f5f..5b316e0bb 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,12 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p6 := buildTestPodForNode1("p6", func(pod *v1.Pod) { - test.SetNormalOwnerRef(pod) - setLabelsFooBar(pod) - setPodAntiAffinityFoo1Bar1(pod) - test.SetPodPriority(pod, 50) - }) p7 := buildTestPodForNode1("p7", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setLabelsFoo1Bar1(pod) @@ -225,7 +219,13 @@ func TestPodAntiAffinity(t *testing.T) { setPodAntiAffinityFoo1Bar1(pod) test.SetPodPriority(pod, 100) }), - p6, p7}, + buildTestPodForNode1("p6", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + setLabelsFooBar(pod) + setPodAntiAffinityFoo1Bar1(pod) + test.SetPodPriority(pod, 50) + }), + p7}, nodes: []*v1.Node{ buildTestNode1(), }, From a0654df27077d31029ebc62078b81a29369c5866 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:54:07 +0100 Subject: [PATCH 31/39] refactor(TestPodAntiAffinity): inline p7 --- .../pod_antiaffinity_test.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 5b316e0bb..cde80394c 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,12 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p7 := buildTestPodForNode1("p7", func(pod *v1.Pod) { - test.SetNormalOwnerRef(pod) - setLabelsFoo1Bar1(pod) - setPodAntiAffinityFooBar(pod) - test.SetPodPriority(pod, 0) - }) p8 := buildTestPodForNode1("p8", func(pod *v1.Pod) { pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", @@ -225,7 +219,12 @@ func TestPodAntiAffinity(t *testing.T) { setPodAntiAffinityFoo1Bar1(pod) test.SetPodPriority(pod, 50) }), - p7}, + buildTestPodForNode1("p7", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + setLabelsFoo1Bar1(pod) + setPodAntiAffinityFooBar(pod) + test.SetPodPriority(pod, 0) + })}, nodes: []*v1.Node{ buildTestNode1(), }, From ad872f8b771ba4fbb2a3c82d7f9044f3ba0d17a7 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:54:40 +0100 Subject: [PATCH 32/39] refactor(TestPodAntiAffinity): inline p8 --- .../pod_antiaffinity_test.go | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index cde80394c..42059cf19 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,11 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p8 := buildTestPodForNode1("p8", func(pod *v1.Pod) { - pod.Spec.NodeSelector = map[string]string{ - "datacenter": "west", - } - }) p9 := buildTestPodForNode1("p9", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setPodAntiAffinityFooBar(pod) @@ -255,7 +250,13 @@ func TestPodAntiAffinity(t *testing.T) { { description: "Won't evict pods because node selectors don't match available nodes", maxPodsToEvictPerNode: &uint1, - pods: []*v1.Pod{p8, nonEvictablePod}, + pods: []*v1.Pod{ + buildTestPodForNode1("p8", func(pod *v1.Pod) { + pod.Spec.NodeSelector = map[string]string{ + "datacenter": "west", + } + }), + nonEvictablePod}, nodes: []*v1.Node{ buildTestNode1(), buildTestNode(nodeName2, func(node *v1.Node) { @@ -270,7 +271,13 @@ func TestPodAntiAffinity(t *testing.T) { { description: "Won't evict pods because only other node is not schedulable", maxPodsToEvictPerNode: &uint1, - pods: []*v1.Pod{p8, nonEvictablePod}, + pods: []*v1.Pod{ + buildTestPodForNode1("p8", func(pod *v1.Pod) { + pod.Spec.NodeSelector = map[string]string{ + "datacenter": "west", + } + }), + nonEvictablePod}, nodes: []*v1.Node{ buildTestNode1(), buildTestNode(nodeName3, func(node *v1.Node) { From a4930ebc830200cc2c4d9f8fd59df5905044fa42 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:55:11 +0100 Subject: [PATCH 33/39] refactor(TestPodAntiAffinity): inline p9 --- .../pod_antiaffinity_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 42059cf19..2164a433b 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,11 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p9 := buildTestPodForNode1("p9", func(pod *v1.Pod) { - test.SetNormalOwnerRef(pod) - setPodAntiAffinityFooBar(pod) - pod.DeletionTimestamp = &metav1.Time{} - }) p10 := buildTestPodForNode1("p10", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setPodAntiAffinityFooBar(pod) @@ -291,7 +286,13 @@ func TestPodAntiAffinity(t *testing.T) { }, { description: "No pod to evicted since all pod terminating", - pods: []*v1.Pod{p9, p10}, + pods: []*v1.Pod{ + buildTestPodForNode1("p9", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + setPodAntiAffinityFooBar(pod) + pod.DeletionTimestamp = &metav1.Time{} + }), + p10}, nodes: []*v1.Node{ buildTestNode1(), }, From a96451030c1de4457c2fd18c1c9a13d0b8b34e26 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:55:36 +0100 Subject: [PATCH 34/39] refactor(TestPodAntiAffinity): inline p10 --- .../pod_antiaffinity_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 2164a433b..c58654d3d 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,11 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p10 := buildTestPodForNode1("p10", func(pod *v1.Pod) { - test.SetNormalOwnerRef(pod) - setPodAntiAffinityFooBar(pod) - pod.DeletionTimestamp = &metav1.Time{} - }) p11 := buildTestPod("p11", nodeName5, func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setLabelsFooBar(pod) @@ -292,7 +287,11 @@ func TestPodAntiAffinity(t *testing.T) { setPodAntiAffinityFooBar(pod) pod.DeletionTimestamp = &metav1.Time{} }), - p10}, + buildTestPodForNode1("p10", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + setPodAntiAffinityFooBar(pod) + pod.DeletionTimestamp = &metav1.Time{} + })}, nodes: []*v1.Node{ buildTestNode1(), }, From 688b45011a54d1a7049a0b9f4d03f190854afe4c Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:56:07 +0100 Subject: [PATCH 35/39] refactor(TestPodAntiAffinity): inline p11 --- .../pod_antiaffinity_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index c58654d3d..a12dac604 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,11 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - p11 := buildTestPod("p11", nodeName5, func(pod *v1.Pod) { - test.SetNormalOwnerRef(pod) - setLabelsFooBar(pod) - }) - nonEvictablePod := buildTestPodNonEvictableForNode1() var uint1 uint = 1 @@ -316,7 +311,10 @@ func TestPodAntiAffinity(t *testing.T) { description: "Evict pod violating anti-affinity among different node (all pods have anti-affinity)", pods: []*v1.Pod{ buildTestPodP1ForNode1(), - p11}, + buildTestPod("p11", nodeName5, func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + setLabelsFooBar(pod) + })}, nodes: []*v1.Node{ buildTestNode1(), test.BuildTestNode(nodeName5, 200, 3000, 10, setNodeMainRegionLabel), From 7cec27d467b1ddc5a2eeccb5094afe546e6af825 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 13:56:37 +0100 Subject: [PATCH 36/39] refactor(TestPodAntiAffinity): inline nonEvictablePod --- .../pod_antiaffinity_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index a12dac604..b96acf141 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -117,8 +117,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { func TestPodAntiAffinity(t *testing.T) { - nonEvictablePod := buildTestPodNonEvictableForNode1() - var uint1 uint = 1 var uint3 uint = 3 @@ -215,7 +213,7 @@ func TestPodAntiAffinity(t *testing.T) { maxPodsToEvictPerNode: &uint1, pods: []*v1.Pod{ buildTestPodP1ForNode1(), - nonEvictablePod}, + buildTestPodNonEvictableForNode1()}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -226,7 +224,7 @@ func TestPodAntiAffinity(t *testing.T) { maxPodsToEvictPerNode: &uint1, pods: []*v1.Pod{ buildTestPodP1ForNode1(), - nonEvictablePod}, + buildTestPodNonEvictableForNode1()}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -241,7 +239,7 @@ func TestPodAntiAffinity(t *testing.T) { "datacenter": "west", } }), - nonEvictablePod}, + buildTestPodNonEvictableForNode1()}, nodes: []*v1.Node{ buildTestNode1(), buildTestNode(nodeName2, func(node *v1.Node) { @@ -262,7 +260,7 @@ func TestPodAntiAffinity(t *testing.T) { "datacenter": "west", } }), - nonEvictablePod}, + buildTestPodNonEvictableForNode1()}, nodes: []*v1.Node{ buildTestNode1(), buildTestNode(nodeName3, func(node *v1.Node) { From 57a3e610a716ed35daab7e18a5d756790b97cd15 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 14:06:05 +0100 Subject: [PATCH 37/39] refactor(TestPodAntiAffinity): deduplicate p1, p3, p4 builders --- .../pod_antiaffinity_test.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index b96acf141..7ad9f4d19 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -79,13 +79,17 @@ func setLabelsFoo1Bar1(pod *v1.Pod) { pod.Labels = map[string]string{"foo1": "bar1"} } -func buildTestPodP1ForNode1() *v1.Pod { - return buildTestPodForNode1("p1", func(pod *v1.Pod) { +func buildTestPodWithAntiAffinityForNode1(name string) *v1.Pod { + return buildTestPodForNode1(name, func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setPodAntiAffinityFooBar(pod) }) } +func buildTestPodP1ForNode1() *v1.Pod { + return buildTestPodWithAntiAffinityForNode1("p1") +} + func buildTestPodP2ForNode1() *v1.Pod { return buildTestPodForNode1("p2", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) @@ -94,17 +98,11 @@ func buildTestPodP2ForNode1() *v1.Pod { } func buildTestPodP3ForNode1() *v1.Pod { - return buildTestPodForNode1("p3", func(pod *v1.Pod) { - test.SetNormalOwnerRef(pod) - setPodAntiAffinityFooBar(pod) - }) + return buildTestPodWithAntiAffinityForNode1("p3") } func buildTestPodP4ForNode1() *v1.Pod { - return buildTestPodForNode1("p4", func(pod *v1.Pod) { - test.SetNormalOwnerRef(pod) - setPodAntiAffinityFooBar(pod) - }) + return buildTestPodWithAntiAffinityForNode1("p4") } func buildTestPodNonEvictableForNode1() *v1.Pod { From 3c02d9029caac4366e2535d0f01097b3680b1e25 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 14:08:30 +0100 Subject: [PATCH 38/39] refactor(TestPodAntiAffinity): inline p1, p2, p4 builders --- .../pod_antiaffinity_test.go | 48 +++++++------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 7ad9f4d19..859f953d4 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -86,10 +86,6 @@ func buildTestPodWithAntiAffinityForNode1(name string) *v1.Pod { }) } -func buildTestPodP1ForNode1() *v1.Pod { - return buildTestPodWithAntiAffinityForNode1("p1") -} - func buildTestPodP2ForNode1() *v1.Pod { return buildTestPodForNode1("p2", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) @@ -97,14 +93,6 @@ func buildTestPodP2ForNode1() *v1.Pod { }) } -func buildTestPodP3ForNode1() *v1.Pod { - return buildTestPodWithAntiAffinityForNode1("p3") -} - -func buildTestPodP4ForNode1() *v1.Pod { - return buildTestPodWithAntiAffinityForNode1("p4") -} - func buildTestPodNonEvictableForNode1() *v1.Pod { criticalPriority := utils.SystemCriticalPriority return buildTestPodForNode1("non-evict", func(pod *v1.Pod) { @@ -131,10 +119,10 @@ func TestPodAntiAffinity(t *testing.T) { { description: "Maximum pods to evict - 0", pods: []*v1.Pod{ - buildTestPodP1ForNode1(), + buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodP2ForNode1(), - buildTestPodP3ForNode1(), - buildTestPodP4ForNode1()}, + buildTestPodWithAntiAffinityForNode1("p3"), + buildTestPodWithAntiAffinityForNode1("p4")}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -144,10 +132,10 @@ func TestPodAntiAffinity(t *testing.T) { description: "Maximum pods to evict - 3", maxPodsToEvictPerNode: &uint3, pods: []*v1.Pod{ - buildTestPodP1ForNode1(), + buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodP2ForNode1(), - buildTestPodP3ForNode1(), - buildTestPodP4ForNode1()}, + buildTestPodWithAntiAffinityForNode1("p3"), + buildTestPodWithAntiAffinityForNode1("p4")}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -157,10 +145,10 @@ func TestPodAntiAffinity(t *testing.T) { description: "Maximum pods to evict (maxPodsToEvictPerNamespace=3) - 3", maxNoOfPodsToEvictPerNamespace: &uint3, pods: []*v1.Pod{ - buildTestPodP1ForNode1(), + buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodP2ForNode1(), - buildTestPodP3ForNode1(), - buildTestPodP4ForNode1()}, + buildTestPodWithAntiAffinityForNode1("p3"), + buildTestPodWithAntiAffinityForNode1("p4")}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -171,10 +159,10 @@ func TestPodAntiAffinity(t *testing.T) { maxNoOfPodsToEvictPerNamespace: &uint3, maxNoOfPodsToEvictTotal: &uint1, pods: []*v1.Pod{ - buildTestPodP1ForNode1(), + buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodP2ForNode1(), - buildTestPodP3ForNode1(), - buildTestPodP4ForNode1()}, + buildTestPodWithAntiAffinityForNode1("p3"), + buildTestPodWithAntiAffinityForNode1("p4")}, nodes: []*v1.Node{ buildTestNode1(), }, @@ -210,7 +198,7 @@ func TestPodAntiAffinity(t *testing.T) { description: "Evicts pod that conflicts with critical pod (but does not evict critical pod)", maxPodsToEvictPerNode: &uint1, pods: []*v1.Pod{ - buildTestPodP1ForNode1(), + buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodNonEvictableForNode1()}, nodes: []*v1.Node{ buildTestNode1(), @@ -221,7 +209,7 @@ func TestPodAntiAffinity(t *testing.T) { description: "Evicts pod that conflicts with critical pod (but does not evict critical pod)", maxPodsToEvictPerNode: &uint1, pods: []*v1.Pod{ - buildTestPodP1ForNode1(), + buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodNonEvictableForNode1()}, nodes: []*v1.Node{ buildTestNode1(), @@ -292,10 +280,10 @@ func TestPodAntiAffinity(t *testing.T) { description: "Won't evict pods because only other node doesn't have enough resources", maxPodsToEvictPerNode: &uint3, pods: []*v1.Pod{ - buildTestPodP1ForNode1(), + buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodP2ForNode1(), - buildTestPodP3ForNode1(), - buildTestPodP4ForNode1()}, + buildTestPodWithAntiAffinityForNode1("p3"), + buildTestPodWithAntiAffinityForNode1("p4")}, nodes: []*v1.Node{ buildTestNode1(), test.BuildTestNode(nodeName4, 2, 2, 1, nil), @@ -306,7 +294,7 @@ func TestPodAntiAffinity(t *testing.T) { { description: "Evict pod violating anti-affinity among different node (all pods have anti-affinity)", pods: []*v1.Pod{ - buildTestPodP1ForNode1(), + buildTestPodWithAntiAffinityForNode1("p1"), buildTestPod("p11", nodeName5, func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setLabelsFooBar(pod) From 3d1e15bb822b254418ba434c1592c82acc09c83f Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 14:21:32 +0100 Subject: [PATCH 39/39] refactor(TestPodAntiAffinity): apply gofumpt formatting --- .../pod_antiaffinity_test.go | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go index 859f953d4..2dbc0a7d4 100644 --- a/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go +++ b/pkg/framework/plugins/removepodsviolatinginterpodantiaffinity/pod_antiaffinity_test.go @@ -102,7 +102,6 @@ func buildTestPodNonEvictableForNode1() *v1.Pod { } func TestPodAntiAffinity(t *testing.T) { - var uint1 uint = 1 var uint3 uint = 3 @@ -122,7 +121,8 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodP2ForNode1(), buildTestPodWithAntiAffinityForNode1("p3"), - buildTestPodWithAntiAffinityForNode1("p4")}, + buildTestPodWithAntiAffinityForNode1("p4"), + }, nodes: []*v1.Node{ buildTestNode1(), }, @@ -135,7 +135,8 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodP2ForNode1(), buildTestPodWithAntiAffinityForNode1("p3"), - buildTestPodWithAntiAffinityForNode1("p4")}, + buildTestPodWithAntiAffinityForNode1("p4"), + }, nodes: []*v1.Node{ buildTestNode1(), }, @@ -148,7 +149,8 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodP2ForNode1(), buildTestPodWithAntiAffinityForNode1("p3"), - buildTestPodWithAntiAffinityForNode1("p4")}, + buildTestPodWithAntiAffinityForNode1("p4"), + }, nodes: []*v1.Node{ buildTestNode1(), }, @@ -162,7 +164,8 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodP2ForNode1(), buildTestPodWithAntiAffinityForNode1("p3"), - buildTestPodWithAntiAffinityForNode1("p4")}, + buildTestPodWithAntiAffinityForNode1("p4"), + }, nodes: []*v1.Node{ buildTestNode1(), }, @@ -188,7 +191,8 @@ func TestPodAntiAffinity(t *testing.T) { setLabelsFoo1Bar1(pod) setPodAntiAffinityFooBar(pod) test.SetPodPriority(pod, 0) - })}, + }), + }, nodes: []*v1.Node{ buildTestNode1(), }, @@ -199,7 +203,8 @@ func TestPodAntiAffinity(t *testing.T) { maxPodsToEvictPerNode: &uint1, pods: []*v1.Pod{ buildTestPodWithAntiAffinityForNode1("p1"), - buildTestPodNonEvictableForNode1()}, + buildTestPodNonEvictableForNode1(), + }, nodes: []*v1.Node{ buildTestNode1(), }, @@ -210,7 +215,8 @@ func TestPodAntiAffinity(t *testing.T) { maxPodsToEvictPerNode: &uint1, pods: []*v1.Pod{ buildTestPodWithAntiAffinityForNode1("p1"), - buildTestPodNonEvictableForNode1()}, + buildTestPodNonEvictableForNode1(), + }, nodes: []*v1.Node{ buildTestNode1(), }, @@ -225,7 +231,8 @@ func TestPodAntiAffinity(t *testing.T) { "datacenter": "west", } }), - buildTestPodNonEvictableForNode1()}, + buildTestPodNonEvictableForNode1(), + }, nodes: []*v1.Node{ buildTestNode1(), buildTestNode(nodeName2, func(node *v1.Node) { @@ -246,7 +253,8 @@ func TestPodAntiAffinity(t *testing.T) { "datacenter": "west", } }), - buildTestPodNonEvictableForNode1()}, + buildTestPodNonEvictableForNode1(), + }, nodes: []*v1.Node{ buildTestNode1(), buildTestNode(nodeName3, func(node *v1.Node) { @@ -270,7 +278,8 @@ func TestPodAntiAffinity(t *testing.T) { test.SetNormalOwnerRef(pod) setPodAntiAffinityFooBar(pod) pod.DeletionTimestamp = &metav1.Time{} - })}, + }), + }, nodes: []*v1.Node{ buildTestNode1(), }, @@ -283,7 +292,8 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPodWithAntiAffinityForNode1("p1"), buildTestPodP2ForNode1(), buildTestPodWithAntiAffinityForNode1("p3"), - buildTestPodWithAntiAffinityForNode1("p4")}, + buildTestPodWithAntiAffinityForNode1("p4"), + }, nodes: []*v1.Node{ buildTestNode1(), test.BuildTestNode(nodeName4, 2, 2, 1, nil), @@ -298,7 +308,8 @@ func TestPodAntiAffinity(t *testing.T) { buildTestPod("p11", nodeName5, func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) setLabelsFooBar(pod) - })}, + }), + }, nodes: []*v1.Node{ buildTestNode1(), test.BuildTestNode(nodeName5, 200, 3000, 10, setNodeMainRegionLabel),