From 61190b805b89d28dde36e957ddaab47c3428e911 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:06:51 +0100 Subject: [PATCH 01/32] refactor(TestFindDuplicatePods): buildTestPodForNode1 for default testing configuration --- .../removeduplicates/removeduplicates_test.go | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 787a4b566..e18f57493 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -33,8 +33,14 @@ import ( "sigs.k8s.io/descheduler/test" ) -func buildTestPodWithImage(podName, node, image string) *v1.Pod { - pod := test.BuildTestPod(podName, 100, 0, node, test.SetRSOwnerRef) +const nodeName1 = "n1" + +func buildTestPodForNode1(name string, apply func(*v1.Pod)) *v1.Pod { + return test.BuildTestPod(name, 100, 0, nodeName1, apply) +} + +func buildTestPodWithImage(podName, image string) *v1.Pod { + pod := buildTestPodForNode1(podName, test.SetRSOwnerRef) pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ Name: image, Image: image, @@ -69,24 +75,24 @@ func TestFindDuplicatePods(t *testing.T) { // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. ownerRef1 := test.GetReplicaSetOwnerRefList() - p1 := test.BuildTestPod("p1", 100, 0, node1.Name, func(pod *v1.Pod) { + p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.OwnerReferences = ownerRef1 }) - p2 := test.BuildTestPod("p2", 100, 0, node1.Name, func(pod *v1.Pod) { + p2 := buildTestPodForNode1("p2", func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.OwnerReferences = ownerRef1 }) - p3 := test.BuildTestPod("p3", 100, 0, node1.Name, func(pod *v1.Pod) { + p3 := buildTestPodForNode1("p3", func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.OwnerReferences = ownerRef1 }) // A DaemonSet. - p4 := test.BuildTestPod("p4", 100, 0, node1.Name, func(pod *v1.Pod) { + p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { pod.ObjectMeta.OwnerReferences = test.GetDaemonSetOwnerRefList() }) // A Pod with local storage. - p5 := test.BuildTestPod("p5", 100, 0, node1.Name, func(pod *v1.Pod) { + p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { pod.ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList() pod.Spec.Volumes = []v1.Volume{ { @@ -101,42 +107,42 @@ func TestFindDuplicatePods(t *testing.T) { } }) // A Mirror Pod. - p6 := test.BuildTestPod("p6", 100, 0, node1.Name, func(pod *v1.Pod) { + p6 := buildTestPodForNode1("p6", func(pod *v1.Pod) { pod.Annotations = test.GetMirrorPodAnnotation() }) // A Critical Pod. - p7 := test.BuildTestPod("p7", 100, 0, node1.Name, func(pod *v1.Pod) { + p7 := buildTestPodForNode1("p7", func(pod *v1.Pod) { pod.Namespace = "kube-system" priority := utils.SystemCriticalPriority pod.Spec.Priority = &priority }) // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. ownerRef2 := test.GetReplicaSetOwnerRefList() - p8 := test.BuildTestPod("p8", 100, 0, node1.Name, func(pod *v1.Pod) { + p8 := buildTestPodForNode1("p8", func(pod *v1.Pod) { pod.Namespace = "test" pod.ObjectMeta.OwnerReferences = ownerRef2 }) - p9 := test.BuildTestPod("p9", 100, 0, node1.Name, func(pod *v1.Pod) { + p9 := buildTestPodForNode1("p9", func(pod *v1.Pod) { pod.Namespace = "test" pod.ObjectMeta.OwnerReferences = ownerRef2 }) - p10 := test.BuildTestPod("p10", 100, 0, node1.Name, func(pod *v1.Pod) { + p10 := buildTestPodForNode1("p10", func(pod *v1.Pod) { pod.Namespace = "test" pod.ObjectMeta.OwnerReferences = ownerRef2 }) // Same owners, but different images - p11 := test.BuildTestPod("p11", 100, 0, node1.Name, func(pod *v1.Pod) { + p11 := buildTestPodForNode1("p11", func(pod *v1.Pod) { pod.Namespace = "different-images" pod.Spec.Containers[0].Image = "foo" pod.ObjectMeta.OwnerReferences = ownerRef1 }) - p12 := test.BuildTestPod("p12", 100, 0, node1.Name, func(pod *v1.Pod) { + p12 := buildTestPodForNode1("p12", func(pod *v1.Pod) { pod.Namespace = "different-images" pod.Spec.Containers[0].Image = "bar" pod.ObjectMeta.OwnerReferences = ownerRef1 }) // Multiple containers - p13 := test.BuildTestPod("p13", 100, 0, node1.Name, func(pod *v1.Pod) { + p13 := buildTestPodForNode1("p13", func(pod *v1.Pod) { pod.Namespace = "different-images" pod.ObjectMeta.OwnerReferences = ownerRef1 pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ @@ -146,21 +152,21 @@ func TestFindDuplicatePods(t *testing.T) { }) // ### Pods Evictable Based On Node Fit ### ownerRef3 := test.GetReplicaSetOwnerRefList() - p15 := test.BuildTestPod("p15", 100, 0, node1.Name, func(pod *v1.Pod) { + p15 := buildTestPodForNode1("p15", func(pod *v1.Pod) { pod.Namespace = "node-fit" pod.ObjectMeta.OwnerReferences = ownerRef3 pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } }) - p16 := test.BuildTestPod("NOT1", 100, 0, node1.Name, func(pod *v1.Pod) { + p16 := buildTestPodForNode1("NOT1", func(pod *v1.Pod) { pod.Namespace = "node-fit" pod.ObjectMeta.OwnerReferences = ownerRef3 pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } }) - p17 := test.BuildTestPod("NOT2", 100, 0, node1.Name, func(pod *v1.Pod) { + p17 := buildTestPodForNode1("NOT2", func(pod *v1.Pod) { pod.Namespace = "node-fit" pod.ObjectMeta.OwnerReferences = ownerRef3 pod.Spec.NodeSelector = map[string]string{ @@ -562,10 +568,10 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { // (1, 0, 0) for "bar","baz" images -> no eviction, even with a matching ownerKey // (2, 0, 0) for "foo" image -> (1,1,0) - 1 eviction // In this case the only "real" duplicates are p1 and p4, so one of those should be evicted - buildTestPodWithImage("p1", "n1", "foo"), - buildTestPodWithImage("p2", "n1", "bar"), - buildTestPodWithImage("p3", "n1", "baz"), - buildTestPodWithImage("p4", "n1", "foo"), + buildTestPodWithImage("p1", "foo"), + buildTestPodWithImage("p2", "bar"), + buildTestPodWithImage("p3", "baz"), + buildTestPodWithImage("p4", "foo"), }, expectedEvictedPodCount: 1, nodes: []*v1.Node{ From 008265db9b2e6b0305f946ca75e6df92b29dd07f Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:10:34 +0100 Subject: [PATCH 02/32] refactor(TestFindDuplicatePods): consolidate ownerRef as all the cases produce the same owner reference --- .../removeduplicates/removeduplicates_test.go | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index e18f57493..18f1cf2be 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -73,19 +73,19 @@ func TestFindDuplicatePods(t *testing.T) { }) node6 := test.BuildTestNode("n6", 200, 200, 10, nil) + ownerRef := test.GetReplicaSetOwnerRefList() // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. - ownerRef1 := test.GetReplicaSetOwnerRefList() p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { pod.Namespace = "dev" - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) p2 := buildTestPodForNode1("p2", func(pod *v1.Pod) { pod.Namespace = "dev" - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) p3 := buildTestPodForNode1("p3", func(pod *v1.Pod) { pod.Namespace = "dev" - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) // A DaemonSet. p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { @@ -117,58 +117,56 @@ func TestFindDuplicatePods(t *testing.T) { pod.Spec.Priority = &priority }) // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. - ownerRef2 := test.GetReplicaSetOwnerRefList() p8 := buildTestPodForNode1("p8", func(pod *v1.Pod) { pod.Namespace = "test" - pod.ObjectMeta.OwnerReferences = ownerRef2 + pod.ObjectMeta.OwnerReferences = ownerRef }) p9 := buildTestPodForNode1("p9", func(pod *v1.Pod) { pod.Namespace = "test" - pod.ObjectMeta.OwnerReferences = ownerRef2 + pod.ObjectMeta.OwnerReferences = ownerRef }) p10 := buildTestPodForNode1("p10", func(pod *v1.Pod) { pod.Namespace = "test" - pod.ObjectMeta.OwnerReferences = ownerRef2 + pod.ObjectMeta.OwnerReferences = ownerRef }) // Same owners, but different images p11 := buildTestPodForNode1("p11", func(pod *v1.Pod) { pod.Namespace = "different-images" pod.Spec.Containers[0].Image = "foo" - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) p12 := buildTestPodForNode1("p12", func(pod *v1.Pod) { pod.Namespace = "different-images" pod.Spec.Containers[0].Image = "bar" - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) // Multiple containers p13 := buildTestPodForNode1("p13", func(pod *v1.Pod) { pod.Namespace = "different-images" - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ Name: "foo", Image: "foo", }) }) // ### Pods Evictable Based On Node Fit ### - ownerRef3 := test.GetReplicaSetOwnerRefList() p15 := buildTestPodForNode1("p15", func(pod *v1.Pod) { pod.Namespace = "node-fit" - pod.ObjectMeta.OwnerReferences = ownerRef3 + pod.ObjectMeta.OwnerReferences = ownerRef pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } }) p16 := buildTestPodForNode1("NOT1", func(pod *v1.Pod) { pod.Namespace = "node-fit" - pod.ObjectMeta.OwnerReferences = ownerRef3 + pod.ObjectMeta.OwnerReferences = ownerRef pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } }) p17 := buildTestPodForNode1("NOT2", func(pod *v1.Pod) { pod.Namespace = "node-fit" - pod.ObjectMeta.OwnerReferences = ownerRef3 + pod.ObjectMeta.OwnerReferences = ownerRef pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } From 59f499e2cdfba57e63d13bbd71ac4c11a35b212a Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:14:01 +0100 Subject: [PATCH 03/32] refactor(TestFindDuplicatePods): replace direct ownerRef assignment with test.SetRSOwnerRef --- .../removeduplicates/removeduplicates_test.go | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 18f1cf2be..09a599f44 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -73,19 +73,18 @@ func TestFindDuplicatePods(t *testing.T) { }) node6 := test.BuildTestNode("n6", 200, 200, 10, nil) - ownerRef := test.GetReplicaSetOwnerRefList() // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { pod.Namespace = "dev" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p2 := buildTestPodForNode1("p2", func(pod *v1.Pod) { pod.Namespace = "dev" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p3 := buildTestPodForNode1("p3", func(pod *v1.Pod) { pod.Namespace = "dev" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) // A DaemonSet. p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { @@ -119,31 +118,31 @@ func TestFindDuplicatePods(t *testing.T) { // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. p8 := buildTestPodForNode1("p8", func(pod *v1.Pod) { pod.Namespace = "test" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p9 := buildTestPodForNode1("p9", func(pod *v1.Pod) { pod.Namespace = "test" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p10 := buildTestPodForNode1("p10", func(pod *v1.Pod) { pod.Namespace = "test" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) // Same owners, but different images p11 := buildTestPodForNode1("p11", func(pod *v1.Pod) { pod.Namespace = "different-images" pod.Spec.Containers[0].Image = "foo" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p12 := buildTestPodForNode1("p12", func(pod *v1.Pod) { pod.Namespace = "different-images" pod.Spec.Containers[0].Image = "bar" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) // Multiple containers p13 := buildTestPodForNode1("p13", func(pod *v1.Pod) { pod.Namespace = "different-images" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ Name: "foo", Image: "foo", @@ -152,21 +151,21 @@ func TestFindDuplicatePods(t *testing.T) { // ### Pods Evictable Based On Node Fit ### p15 := buildTestPodForNode1("p15", func(pod *v1.Pod) { pod.Namespace = "node-fit" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } }) p16 := buildTestPodForNode1("NOT1", func(pod *v1.Pod) { pod.Namespace = "node-fit" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } }) p17 := buildTestPodForNode1("NOT2", func(pod *v1.Pod) { pod.Namespace = "node-fit" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } From f5253faeb0976828fb574ece7edb466ccf718f2d Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:17:22 +0100 Subject: [PATCH 04/32] refactor(TestFindDuplicatePods): set owner refs through a dedicated function --- .../plugins/removeduplicates/removeduplicates_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 09a599f44..daebfcc84 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -88,11 +88,11 @@ func TestFindDuplicatePods(t *testing.T) { }) // A DaemonSet. p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { - pod.ObjectMeta.OwnerReferences = test.GetDaemonSetOwnerRefList() + test.SetDSOwnerRef(pod) }) // A Pod with local storage. p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { - pod.ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList() + test.SetNormalOwnerRef(pod) pod.Spec.Volumes = []v1.Volume{ { Name: "sample", From 7a0257a682a6e80c91c8e121bb1f1a0cc7419d34 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:21:08 +0100 Subject: [PATCH 05/32] refactor(TestFindDuplicatePods): introduce buildTestPodWithRSOwnerRefForNode1 helper --- .../removeduplicates/removeduplicates_test.go | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index daebfcc84..d01a26fcb 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -48,6 +48,15 @@ func buildTestPodWithImage(podName, image string) *v1.Pod { return pod } +func buildTestPodWithRSOwnerRefForNode1(name string, apply func(*v1.Pod)) *v1.Pod { + return buildTestPodForNode1(name, func(pod *v1.Pod) { + test.SetRSOwnerRef(pod) + if apply != nil { + apply(pod) + } + }) +} + func TestFindDuplicatePods(t *testing.T) { // first setup pods node1 := test.BuildTestNode("n1", 2000, 3000, 10, nil) @@ -74,17 +83,14 @@ func TestFindDuplicatePods(t *testing.T) { node6 := test.BuildTestNode("n6", 200, 200, 10, nil) // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. - p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { + p1 := buildTestPodWithRSOwnerRefForNode1("p1", func(pod *v1.Pod) { pod.Namespace = "dev" - test.SetRSOwnerRef(pod) }) - p2 := buildTestPodForNode1("p2", func(pod *v1.Pod) { + p2 := buildTestPodWithRSOwnerRefForNode1("p2", func(pod *v1.Pod) { pod.Namespace = "dev" - test.SetRSOwnerRef(pod) }) - p3 := buildTestPodForNode1("p3", func(pod *v1.Pod) { + p3 := buildTestPodWithRSOwnerRefForNode1("p3", func(pod *v1.Pod) { pod.Namespace = "dev" - test.SetRSOwnerRef(pod) }) // A DaemonSet. p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { @@ -116,56 +122,47 @@ func TestFindDuplicatePods(t *testing.T) { pod.Spec.Priority = &priority }) // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. - p8 := buildTestPodForNode1("p8", func(pod *v1.Pod) { + p8 := buildTestPodWithRSOwnerRefForNode1("p8", func(pod *v1.Pod) { pod.Namespace = "test" - test.SetRSOwnerRef(pod) }) - p9 := buildTestPodForNode1("p9", func(pod *v1.Pod) { + p9 := buildTestPodWithRSOwnerRefForNode1("p9", func(pod *v1.Pod) { pod.Namespace = "test" - test.SetRSOwnerRef(pod) }) - p10 := buildTestPodForNode1("p10", func(pod *v1.Pod) { + p10 := buildTestPodWithRSOwnerRefForNode1("p10", func(pod *v1.Pod) { pod.Namespace = "test" - test.SetRSOwnerRef(pod) }) // Same owners, but different images - p11 := buildTestPodForNode1("p11", func(pod *v1.Pod) { + p11 := buildTestPodWithRSOwnerRefForNode1("p11", func(pod *v1.Pod) { pod.Namespace = "different-images" pod.Spec.Containers[0].Image = "foo" - test.SetRSOwnerRef(pod) }) - p12 := buildTestPodForNode1("p12", func(pod *v1.Pod) { + p12 := buildTestPodWithRSOwnerRefForNode1("p12", func(pod *v1.Pod) { pod.Namespace = "different-images" pod.Spec.Containers[0].Image = "bar" - test.SetRSOwnerRef(pod) }) // Multiple containers - p13 := buildTestPodForNode1("p13", func(pod *v1.Pod) { + p13 := buildTestPodWithRSOwnerRefForNode1("p13", func(pod *v1.Pod) { pod.Namespace = "different-images" - test.SetRSOwnerRef(pod) pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ Name: "foo", Image: "foo", }) }) // ### Pods Evictable Based On Node Fit ### - p15 := buildTestPodForNode1("p15", func(pod *v1.Pod) { + p15 := buildTestPodWithRSOwnerRefForNode1("p15", func(pod *v1.Pod) { pod.Namespace = "node-fit" - test.SetRSOwnerRef(pod) pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } }) - p16 := buildTestPodForNode1("NOT1", func(pod *v1.Pod) { + p16 := buildTestPodWithRSOwnerRefForNode1("NOT1", func(pod *v1.Pod) { pod.Namespace = "node-fit" - test.SetRSOwnerRef(pod) pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } }) - p17 := buildTestPodForNode1("NOT2", func(pod *v1.Pod) { + p17 := buildTestPodWithRSOwnerRefForNode1("NOT2", func(pod *v1.Pod) { pod.Namespace = "node-fit" - test.SetRSOwnerRef(pod) pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } From 0aee6cff485eab192f9179873273811c0739e051 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:33:56 +0100 Subject: [PATCH 06/32] refactor(TestFindDuplicatePods): introduce buildTestPodWithRSOwnerRefWithNamespaceForNode1 helper --- .../removeduplicates/removeduplicates_test.go | 51 ++++++++----------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index d01a26fcb..64045f7e7 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -57,6 +57,15 @@ func buildTestPodWithRSOwnerRefForNode1(name string, apply func(*v1.Pod)) *v1.Po }) } +func buildTestPodWithRSOwnerRefWithNamespaceForNode1(name, namespace string, apply func(*v1.Pod)) *v1.Pod { + return buildTestPodWithRSOwnerRefForNode1(name, func(pod *v1.Pod) { + pod.Namespace = namespace + if apply != nil { + apply(pod) + } + }) +} + func TestFindDuplicatePods(t *testing.T) { // first setup pods node1 := test.BuildTestNode("n1", 2000, 3000, 10, nil) @@ -83,15 +92,9 @@ func TestFindDuplicatePods(t *testing.T) { node6 := test.BuildTestNode("n6", 200, 200, 10, nil) // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. - p1 := buildTestPodWithRSOwnerRefForNode1("p1", func(pod *v1.Pod) { - pod.Namespace = "dev" - }) - p2 := buildTestPodWithRSOwnerRefForNode1("p2", func(pod *v1.Pod) { - pod.Namespace = "dev" - }) - p3 := buildTestPodWithRSOwnerRefForNode1("p3", func(pod *v1.Pod) { - pod.Namespace = "dev" - }) + p1 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil) + p2 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil) + p3 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil) // A DaemonSet. p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { test.SetDSOwnerRef(pod) @@ -122,47 +125,35 @@ func TestFindDuplicatePods(t *testing.T) { pod.Spec.Priority = &priority }) // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. - p8 := buildTestPodWithRSOwnerRefForNode1("p8", func(pod *v1.Pod) { - pod.Namespace = "test" - }) - p9 := buildTestPodWithRSOwnerRefForNode1("p9", func(pod *v1.Pod) { - pod.Namespace = "test" - }) - p10 := buildTestPodWithRSOwnerRefForNode1("p10", func(pod *v1.Pod) { - pod.Namespace = "test" - }) + p8 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil) + p9 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil) + p10 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p10", "test", nil) // Same owners, but different images - p11 := buildTestPodWithRSOwnerRefForNode1("p11", func(pod *v1.Pod) { - pod.Namespace = "different-images" + p11 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p11", "different-images", func(pod *v1.Pod) { pod.Spec.Containers[0].Image = "foo" }) - p12 := buildTestPodWithRSOwnerRefForNode1("p12", func(pod *v1.Pod) { - pod.Namespace = "different-images" + p12 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p12", "different-images", func(pod *v1.Pod) { pod.Spec.Containers[0].Image = "bar" }) // Multiple containers - p13 := buildTestPodWithRSOwnerRefForNode1("p13", func(pod *v1.Pod) { - pod.Namespace = "different-images" + p13 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p13", "different-images", func(pod *v1.Pod) { pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ Name: "foo", Image: "foo", }) }) // ### Pods Evictable Based On Node Fit ### - p15 := buildTestPodWithRSOwnerRefForNode1("p15", func(pod *v1.Pod) { - pod.Namespace = "node-fit" + p15 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p15", "node-fit", func(pod *v1.Pod) { pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } }) - p16 := buildTestPodWithRSOwnerRefForNode1("NOT1", func(pod *v1.Pod) { - pod.Namespace = "node-fit" + p16 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("NOT1", "node-fit", func(pod *v1.Pod) { pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } }) - p17 := buildTestPodWithRSOwnerRefForNode1("NOT2", func(pod *v1.Pod) { - pod.Namespace = "node-fit" + p17 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("NOT2", "node-fit", func(pod *v1.Pod) { pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", } From 180548cc1a015f167ac9fe53d7451b2e8fbfea26 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:37:23 +0100 Subject: [PATCH 07/32] refactor(TestFindDuplicatePods): inline p1 pod creation --- .../removeduplicates/removeduplicates_test.go | 57 +++++++++++++------ 1 file changed, 40 insertions(+), 17 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 64045f7e7..fdaa0ef1c 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -92,7 +92,6 @@ func TestFindDuplicatePods(t *testing.T) { node6 := test.BuildTestNode("n6", 200, 200, 10, nil) // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. - p1 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil) p2 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil) p3 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil) // A DaemonSet. @@ -182,14 +181,20 @@ func TestFindDuplicatePods(t *testing.T) { nodefit bool }{ { - description: "Three pods in the `dev` Namespace, bound to same ReplicaSet. 1 should be evicted.", - pods: []*v1.Pod{p1, p2, p3}, + description: "Three pods in the `dev` Namespace, bound to same ReplicaSet. 1 should be evicted.", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), + p2, p3, + }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 1, }, { - description: "Three pods in the `dev` Namespace, bound to same ReplicaSet, but ReplicaSet kind is excluded. 0 should be evicted.", - pods: []*v1.Pod{p1, p2, p3}, + description: "Three pods in the `dev` Namespace, bound to same ReplicaSet, but ReplicaSet kind is excluded. 0 should be evicted.", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), + p2, p3, + }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, excludeOwnerKinds: []string{"ReplicaSet"}, @@ -201,8 +206,11 @@ func TestFindDuplicatePods(t *testing.T) { expectedEvictedPodCount: 1, }, { - description: "Three Pods in the `dev` Namespace, three Pods in the `test` Namespace. Bound to ReplicaSet with same name. 4 should be evicted.", - pods: []*v1.Pod{p1, p2, p3, p8, p9, p10}, + description: "Three Pods in the `dev` Namespace, three Pods in the `test` Namespace. Bound to ReplicaSet with same name. 4 should be evicted.", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), + p2, p3, p8, p9, p10, + }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, }, @@ -213,8 +221,11 @@ func TestFindDuplicatePods(t *testing.T) { expectedEvictedPodCount: 0, }, { - description: "Test all Pods: 4 should be evicted.", - pods: []*v1.Pod{p1, p2, p3, p4, p5, p6, p7, p8, p9, p10}, + description: "Test all Pods: 4 should be evicted.", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), + p2, p3, p4, p5, p6, p7, p8, p9, p10, + }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, }, @@ -237,8 +248,11 @@ func TestFindDuplicatePods(t *testing.T) { expectedEvictedPodCount: 0, }, { - description: "Three pods in the `dev` Namespace, bound to same ReplicaSet. Only node available has a taint, and nodeFit set to true. 0 should be evicted.", - pods: []*v1.Pod{p1, p2, p3}, + description: "Three pods in the `dev` Namespace, bound to same ReplicaSet. Only node available has a taint, and nodeFit set to true. 0 should be evicted.", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), + p2, p3, + }, nodes: []*v1.Node{node1, node3}, expectedEvictedPodCount: 0, nodefit: true, @@ -251,22 +265,31 @@ func TestFindDuplicatePods(t *testing.T) { nodefit: true, }, { - description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet. Only node available is not schedulable, and nodeFit set to true. 0 should be evicted.", - pods: []*v1.Pod{p1, p2, p3}, + description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet. Only node available is not schedulable, and nodeFit set to true. 0 should be evicted.", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), + p2, p3, + }, nodes: []*v1.Node{node1, node5}, expectedEvictedPodCount: 0, nodefit: true, }, { - description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet. Only node available does not have enough CPU, and nodeFit set to true. 0 should be evicted.", - pods: []*v1.Pod{p1, p2, p3, p19}, + description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet. Only node available does not have enough CPU, and nodeFit set to true. 0 should be evicted.", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), + p2, p3, p19, + }, nodes: []*v1.Node{node1, node6}, expectedEvictedPodCount: 0, nodefit: true, }, { - description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet. Only node available has enough CPU, and nodeFit set to true. 1 should be evicted.", - pods: []*v1.Pod{p1, p2, p3, p20}, + description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet. Only node available has enough CPU, and nodeFit set to true. 1 should be evicted.", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), + p2, p3, p20, + }, nodes: []*v1.Node{node1, node6}, expectedEvictedPodCount: 1, nodefit: true, From df064428301accff27726b8e52ea074a2e96129a Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:39:56 +0100 Subject: [PATCH 08/32] refactor(TestFindDuplicatePods): inline p2 pod creation --- .../removeduplicates/removeduplicates_test.go | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index fdaa0ef1c..e72a0d70b 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -92,7 +92,6 @@ func TestFindDuplicatePods(t *testing.T) { node6 := test.BuildTestNode("n6", 200, 200, 10, nil) // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. - p2 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil) p3 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil) // A DaemonSet. p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { @@ -184,7 +183,8 @@ func TestFindDuplicatePods(t *testing.T) { description: "Three pods in the `dev` Namespace, bound to same ReplicaSet. 1 should be evicted.", pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), - p2, p3, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), + p3, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 1, @@ -193,7 +193,8 @@ func TestFindDuplicatePods(t *testing.T) { description: "Three pods in the `dev` Namespace, bound to same ReplicaSet, but ReplicaSet kind is excluded. 0 should be evicted.", pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), - p2, p3, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), + p3, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, @@ -209,7 +210,8 @@ func TestFindDuplicatePods(t *testing.T) { description: "Three Pods in the `dev` Namespace, three Pods in the `test` Namespace. Bound to ReplicaSet with same name. 4 should be evicted.", pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), - p2, p3, p8, p9, p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), + p3, p8, p9, p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, @@ -224,7 +226,8 @@ func TestFindDuplicatePods(t *testing.T) { description: "Test all Pods: 4 should be evicted.", pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), - p2, p3, p4, p5, p6, p7, p8, p9, p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), + p3, p4, p5, p6, p7, p8, p9, p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, @@ -251,7 +254,8 @@ func TestFindDuplicatePods(t *testing.T) { description: "Three pods in the `dev` Namespace, bound to same ReplicaSet. Only node available has a taint, and nodeFit set to true. 0 should be evicted.", pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), - p2, p3, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), + p3, }, nodes: []*v1.Node{node1, node3}, expectedEvictedPodCount: 0, @@ -268,7 +272,8 @@ func TestFindDuplicatePods(t *testing.T) { description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet. Only node available is not schedulable, and nodeFit set to true. 0 should be evicted.", pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), - p2, p3, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), + p3, }, nodes: []*v1.Node{node1, node5}, expectedEvictedPodCount: 0, @@ -278,7 +283,8 @@ func TestFindDuplicatePods(t *testing.T) { description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet. Only node available does not have enough CPU, and nodeFit set to true. 0 should be evicted.", pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), - p2, p3, p19, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), + p3, p19, }, nodes: []*v1.Node{node1, node6}, expectedEvictedPodCount: 0, @@ -288,7 +294,8 @@ func TestFindDuplicatePods(t *testing.T) { description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet. Only node available has enough CPU, and nodeFit set to true. 1 should be evicted.", pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), - p2, p3, p20, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), + p3, p20, }, nodes: []*v1.Node{node1, node6}, expectedEvictedPodCount: 1, From 7a5bf8c2f06265267349edc318eee6bc853ee137 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:43:34 +0100 Subject: [PATCH 09/32] refactor(TestFindDuplicatePods): inline p3 pod creation --- .../removeduplicates/removeduplicates_test.go | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index e72a0d70b..d52941bad 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -92,7 +92,6 @@ func TestFindDuplicatePods(t *testing.T) { node6 := test.BuildTestNode("n6", 200, 200, 10, nil) // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. - p3 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil) // A DaemonSet. p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { test.SetDSOwnerRef(pod) @@ -184,7 +183,7 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), - p3, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 1, @@ -194,7 +193,7 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), - p3, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, @@ -211,7 +210,8 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), - p3, p8, p9, p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), + p8, p9, p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, @@ -227,7 +227,8 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), - p3, p4, p5, p6, p7, p8, p9, p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), + p4, p5, p6, p7, p8, p9, p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, @@ -255,7 +256,7 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), - p3, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), }, nodes: []*v1.Node{node1, node3}, expectedEvictedPodCount: 0, @@ -273,7 +274,7 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), - p3, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), }, nodes: []*v1.Node{node1, node5}, expectedEvictedPodCount: 0, @@ -284,7 +285,8 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), - p3, p19, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), + p19, }, nodes: []*v1.Node{node1, node6}, expectedEvictedPodCount: 0, @@ -295,7 +297,8 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), - p3, p20, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), + p20, }, nodes: []*v1.Node{node1, node6}, expectedEvictedPodCount: 1, From 9b50aa91f8de1fabb32fbcf352b4b2a204874f94 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:44:24 +0100 Subject: [PATCH 10/32] refactor(TestFindDuplicatePods): inline p4 pod creation --- .../removeduplicates/removeduplicates_test.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index d52941bad..bcf836d80 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -93,9 +93,6 @@ func TestFindDuplicatePods(t *testing.T) { // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. // A DaemonSet. - p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { - test.SetDSOwnerRef(pod) - }) // A Pod with local storage. p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { test.SetNormalOwnerRef(pod) @@ -217,8 +214,13 @@ func TestFindDuplicatePods(t *testing.T) { expectedEvictedPodCount: 2, }, { - description: "Pods are: part of DaemonSet, with local storage, mirror pod annotation, critical pod annotation - none should be evicted.", - pods: []*v1.Pod{p4, p5, p6, p7}, + description: "Pods are: part of DaemonSet, with local storage, mirror pod annotation, critical pod annotation - none should be evicted.", + pods: []*v1.Pod{ + buildTestPodForNode1("p4", func(pod *v1.Pod) { + test.SetDSOwnerRef(pod) + }), + p5, p6, p7, + }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, }, @@ -228,7 +230,10 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), - p4, p5, p6, p7, p8, p9, p10, + buildTestPodForNode1("p4", func(pod *v1.Pod) { + test.SetDSOwnerRef(pod) + }), + p5, p6, p7, p8, p9, p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, From 01fb826bd38d68bf08e4efd9c3826419d65dec6e Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:46:05 +0100 Subject: [PATCH 11/32] refactor(TestFindDuplicatePods): inline p5 pod creation --- .../removeduplicates/removeduplicates_test.go | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index bcf836d80..f4c15d138 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -94,20 +94,6 @@ func TestFindDuplicatePods(t *testing.T) { // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. // A DaemonSet. // A Pod with local storage. - p5 := buildTestPodForNode1("p5", func(pod *v1.Pod) { - test.SetNormalOwnerRef(pod) - pod.Spec.Volumes = []v1.Volume{ - { - Name: "sample", - VolumeSource: v1.VolumeSource{ - HostPath: &v1.HostPathVolumeSource{Path: "somePath"}, - EmptyDir: &v1.EmptyDirVolumeSource{ - SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI), - }, - }, - }, - } - }) // A Mirror Pod. p6 := buildTestPodForNode1("p6", func(pod *v1.Pod) { pod.Annotations = test.GetMirrorPodAnnotation() @@ -219,7 +205,20 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodForNode1("p4", func(pod *v1.Pod) { test.SetDSOwnerRef(pod) }), - p5, p6, p7, + buildTestPodForNode1("p5", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + pod.Spec.Volumes = []v1.Volume{ + { + Name: "sample", + VolumeSource: v1.VolumeSource{ + HostPath: &v1.HostPathVolumeSource{Path: "somePath"}, + EmptyDir: &v1.EmptyDirVolumeSource{ + SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI), + }, + }, + }, + } + }), p6, p7, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, @@ -233,7 +232,20 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodForNode1("p4", func(pod *v1.Pod) { test.SetDSOwnerRef(pod) }), - p5, p6, p7, p8, p9, p10, + buildTestPodForNode1("p5", func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + pod.Spec.Volumes = []v1.Volume{ + { + Name: "sample", + VolumeSource: v1.VolumeSource{ + HostPath: &v1.HostPathVolumeSource{Path: "somePath"}, + EmptyDir: &v1.EmptyDirVolumeSource{ + SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI), + }, + }, + }, + } + }), p6, p7, p8, p9, p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, From 8490ed9c8ff5242114913abd231a1dfc6fdf6f3c Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:47:01 +0100 Subject: [PATCH 12/32] refactor(TestFindDuplicatePods): inline p6 pod creation --- .../removeduplicates/removeduplicates_test.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index f4c15d138..9422d20af 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -95,9 +95,6 @@ func TestFindDuplicatePods(t *testing.T) { // A DaemonSet. // A Pod with local storage. // A Mirror Pod. - p6 := buildTestPodForNode1("p6", func(pod *v1.Pod) { - pod.Annotations = test.GetMirrorPodAnnotation() - }) // A Critical Pod. p7 := buildTestPodForNode1("p7", func(pod *v1.Pod) { pod.Namespace = "kube-system" @@ -218,7 +215,10 @@ func TestFindDuplicatePods(t *testing.T) { }, }, } - }), p6, p7, + }), + buildTestPodForNode1("p6", func(pod *v1.Pod) { + pod.Annotations = test.GetMirrorPodAnnotation() + }), p7, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, @@ -245,7 +245,10 @@ func TestFindDuplicatePods(t *testing.T) { }, }, } - }), p6, p7, p8, p9, p10, + }), + buildTestPodForNode1("p6", func(pod *v1.Pod) { + pod.Annotations = test.GetMirrorPodAnnotation() + }), p7, p8, p9, p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, From e9dcd4e54d71837b5078988d8673cb6c6af6c727 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:48:13 +0100 Subject: [PATCH 13/32] refactor(TestFindDuplicatePods): inline p7 pod creation --- .../removeduplicates/removeduplicates_test.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 9422d20af..caf914ee2 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -96,11 +96,6 @@ func TestFindDuplicatePods(t *testing.T) { // A Pod with local storage. // A Mirror Pod. // A Critical Pod. - p7 := buildTestPodForNode1("p7", func(pod *v1.Pod) { - pod.Namespace = "kube-system" - priority := utils.SystemCriticalPriority - pod.Spec.Priority = &priority - }) // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. p8 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil) p9 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil) @@ -218,7 +213,12 @@ func TestFindDuplicatePods(t *testing.T) { }), buildTestPodForNode1("p6", func(pod *v1.Pod) { pod.Annotations = test.GetMirrorPodAnnotation() - }), p7, + }), + buildTestPodForNode1("p7", func(pod *v1.Pod) { + pod.Namespace = "kube-system" + priority := utils.SystemCriticalPriority + pod.Spec.Priority = &priority + }), }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, @@ -248,7 +248,12 @@ func TestFindDuplicatePods(t *testing.T) { }), buildTestPodForNode1("p6", func(pod *v1.Pod) { pod.Annotations = test.GetMirrorPodAnnotation() - }), p7, p8, p9, p10, + }), + buildTestPodForNode1("p7", func(pod *v1.Pod) { + pod.Namespace = "kube-system" + priority := utils.SystemCriticalPriority + pod.Spec.Priority = &priority + }), p8, p9, p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, From f3d91fc69fdb2ce3ab6ac526407d93240f00ca00 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 13:48:46 +0100 Subject: [PATCH 14/32] refactor(TestFindDuplicatePods): inline p8 pod creation --- .../removeduplicates/removeduplicates_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index caf914ee2..3195ed4f1 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -97,7 +97,6 @@ func TestFindDuplicatePods(t *testing.T) { // A Mirror Pod. // A Critical Pod. // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. - p8 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil) p9 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil) p10 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p10", "test", nil) // Same owners, but different images @@ -175,8 +174,11 @@ func TestFindDuplicatePods(t *testing.T) { excludeOwnerKinds: []string{"ReplicaSet"}, }, { - description: "Three Pods in the `test` Namespace, bound to same ReplicaSet. 1 should be evicted.", - pods: []*v1.Pod{p8, p9, p10}, + description: "Three Pods in the `test` Namespace, bound to same ReplicaSet. 1 should be evicted.", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil), + p9, p10, + }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 1, }, @@ -186,7 +188,8 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), - p8, p9, p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil), + p9, p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, @@ -253,7 +256,9 @@ func TestFindDuplicatePods(t *testing.T) { pod.Namespace = "kube-system" priority := utils.SystemCriticalPriority pod.Spec.Priority = &priority - }), p8, p9, p10, + }), + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil), + p9, p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, From eeb459d6d4e15ab8ef6f1cf2056a07014d493b24 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 14:10:18 +0100 Subject: [PATCH 15/32] refactor(TestFindDuplicatePods): inline p9 pod creation --- .../plugins/removeduplicates/removeduplicates_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 3195ed4f1..050896476 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -97,7 +97,6 @@ func TestFindDuplicatePods(t *testing.T) { // A Mirror Pod. // A Critical Pod. // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. - p9 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil) p10 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p10", "test", nil) // Same owners, but different images p11 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p11", "different-images", func(pod *v1.Pod) { @@ -177,7 +176,8 @@ func TestFindDuplicatePods(t *testing.T) { description: "Three Pods in the `test` Namespace, bound to same ReplicaSet. 1 should be evicted.", pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil), - p9, p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil), + p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 1, @@ -189,7 +189,8 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil), - p9, p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil), + p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, @@ -258,7 +259,8 @@ func TestFindDuplicatePods(t *testing.T) { pod.Spec.Priority = &priority }), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil), - p9, p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil), + p10, }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, From 45dfe3011c589ce80f8add6eccd0bb6e867b5389 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 14:11:13 +0100 Subject: [PATCH 16/32] refactor(TestFindDuplicatePods): inline p10 pod creation --- .../plugins/removeduplicates/removeduplicates_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 050896476..2923c7454 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -97,7 +97,6 @@ func TestFindDuplicatePods(t *testing.T) { // A Mirror Pod. // A Critical Pod. // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. - p10 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p10", "test", nil) // Same owners, but different images p11 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p11", "different-images", func(pod *v1.Pod) { pod.Spec.Containers[0].Image = "foo" @@ -177,7 +176,7 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil), - p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p10", "test", nil), }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 1, @@ -190,7 +189,7 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil), - p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p10", "test", nil), }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, @@ -260,7 +259,7 @@ func TestFindDuplicatePods(t *testing.T) { }), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p8", "test", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil), - p10, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p10", "test", nil), }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 2, From 1c494f9c4486f2cf3662e770b37d8ebdb2f1a8b8 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 14:13:14 +0100 Subject: [PATCH 17/32] refactor(TestFindDuplicatePods): inline p11 pod creation --- .../removeduplicates/removeduplicates_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 2923c7454..976aac27d 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -98,9 +98,6 @@ func TestFindDuplicatePods(t *testing.T) { // A Critical Pod. // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. // Same owners, but different images - p11 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p11", "different-images", func(pod *v1.Pod) { - pod.Spec.Containers[0].Image = "foo" - }) p12 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p12", "different-images", func(pod *v1.Pod) { pod.Spec.Containers[0].Image = "bar" }) @@ -265,8 +262,11 @@ func TestFindDuplicatePods(t *testing.T) { expectedEvictedPodCount: 2, }, { - description: "Pods with the same owner but different images should not be evicted", - pods: []*v1.Pod{p11, p12}, + description: "Pods with the same owner but different images should not be evicted", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p11", "different-images", func(pod *v1.Pod) { + pod.Spec.Containers[0].Image = "foo" + }), p12}, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, }, @@ -277,8 +277,11 @@ func TestFindDuplicatePods(t *testing.T) { expectedEvictedPodCount: 0, }, { - description: "Pods with matching ownerrefs and at not all matching image should not trigger an eviction", - pods: []*v1.Pod{p11, p13}, + description: "Pods with matching ownerrefs and at not all matching image should not trigger an eviction", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p11", "different-images", func(pod *v1.Pod) { + pod.Spec.Containers[0].Image = "foo" + }), p13}, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, }, From 4e758c18e8279e98c2292fc3410e62b793810b8b Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 14:19:19 +0100 Subject: [PATCH 18/32] refactor(TestFindDuplicatePods): inline p12 pod creation --- .../plugins/removeduplicates/removeduplicates_test.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 976aac27d..e29b4de32 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -98,9 +98,6 @@ func TestFindDuplicatePods(t *testing.T) { // A Critical Pod. // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. // Same owners, but different images - p12 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p12", "different-images", func(pod *v1.Pod) { - pod.Spec.Containers[0].Image = "bar" - }) // Multiple containers p13 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p13", "different-images", func(pod *v1.Pod) { pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ @@ -266,7 +263,11 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p11", "different-images", func(pod *v1.Pod) { pod.Spec.Containers[0].Image = "foo" - }), p12}, + }), + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p12", "different-images", func(pod *v1.Pod) { + pod.Spec.Containers[0].Image = "bar" + }), + }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, }, From 3ebffe5a86ac038dd7ec055ec9776cf5038574b2 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 14:20:48 +0100 Subject: [PATCH 19/32] refactor(TestFindDuplicatePods): inline p13 pod creation --- .../removeduplicates/removeduplicates_test.go | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index e29b4de32..c126314b2 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -99,12 +99,6 @@ func TestFindDuplicatePods(t *testing.T) { // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. // Same owners, but different images // Multiple containers - p13 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p13", "different-images", func(pod *v1.Pod) { - pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ - Name: "foo", - Image: "foo", - }) - }) // ### Pods Evictable Based On Node Fit ### p15 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p15", "node-fit", func(pod *v1.Pod) { pod.Spec.NodeSelector = map[string]string{ @@ -272,8 +266,15 @@ func TestFindDuplicatePods(t *testing.T) { expectedEvictedPodCount: 0, }, { - description: "Pods with multiple containers should not match themselves", - pods: []*v1.Pod{p13}, + description: "Pods with multiple containers should not match themselves", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p13", "different-images", func(pod *v1.Pod) { + pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ + Name: "foo", + Image: "foo", + }) + }), + }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, }, @@ -282,7 +283,14 @@ func TestFindDuplicatePods(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithNamespaceForNode1("p11", "different-images", func(pod *v1.Pod) { pod.Spec.Containers[0].Image = "foo" - }), p13}, + }), + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p13", "different-images", func(pod *v1.Pod) { + pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ + Name: "foo", + Image: "foo", + }) + }), + }, nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, }, From d7766cccfd5c6a4b4cc898b1055f523171b2729d Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 14:22:22 +0100 Subject: [PATCH 20/32] refactor(TestFindDuplicatePods): inline p15 pod creation --- .../removeduplicates/removeduplicates_test.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index c126314b2..2a1d08afc 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -100,11 +100,6 @@ func TestFindDuplicatePods(t *testing.T) { // Same owners, but different images // Multiple containers // ### Pods Evictable Based On Node Fit ### - p15 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("p15", "node-fit", func(pod *v1.Pod) { - pod.Spec.NodeSelector = map[string]string{ - "datacenter": "west", - } - }) p16 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("NOT1", "node-fit", func(pod *v1.Pod) { pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", @@ -306,8 +301,16 @@ func TestFindDuplicatePods(t *testing.T) { nodefit: true, }, { - description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet, all with a nodeSelector. Only node available has an incorrect node label, and nodeFit set to true. 0 should be evicted.", - pods: []*v1.Pod{p15, p16, p17}, + description: "Three pods in the `node-fit` Namespace, bound to same ReplicaSet, all with a nodeSelector. Only node available has an incorrect node label, and nodeFit set to true. 0 should be evicted.", + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithNamespaceForNode1("p15", "node-fit", func(pod *v1.Pod) { + pod.Spec.NodeSelector = map[string]string{ + "datacenter": "west", + } + }), + p16, + p17, + }, nodes: []*v1.Node{node1, node4}, expectedEvictedPodCount: 0, nodefit: true, From e8cf01591ea05a5a261e5a02cfd0898b89601c90 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 14:24:36 +0100 Subject: [PATCH 21/32] refactor(TestFindDuplicatePods): inline p16 pod creation --- .../plugins/removeduplicates/removeduplicates_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 2a1d08afc..83951568c 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -100,11 +100,6 @@ func TestFindDuplicatePods(t *testing.T) { // Same owners, but different images // Multiple containers // ### Pods Evictable Based On Node Fit ### - p16 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("NOT1", "node-fit", func(pod *v1.Pod) { - pod.Spec.NodeSelector = map[string]string{ - "datacenter": "west", - } - }) p17 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("NOT2", "node-fit", func(pod *v1.Pod) { pod.Spec.NodeSelector = map[string]string{ "datacenter": "west", @@ -308,7 +303,11 @@ func TestFindDuplicatePods(t *testing.T) { "datacenter": "west", } }), - p16, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("NOT1", "node-fit", func(pod *v1.Pod) { + pod.Spec.NodeSelector = map[string]string{ + "datacenter": "west", + } + }), p17, }, nodes: []*v1.Node{node1, node4}, From e27864717d7022b799aad01608489e29052f5875 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 14:25:26 +0100 Subject: [PATCH 22/32] refactor(TestFindDuplicatePods): inline p17 pod creation --- .../plugins/removeduplicates/removeduplicates_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 83951568c..b8ec243e8 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -100,11 +100,6 @@ func TestFindDuplicatePods(t *testing.T) { // Same owners, but different images // Multiple containers // ### Pods Evictable Based On Node Fit ### - p17 := buildTestPodWithRSOwnerRefWithNamespaceForNode1("NOT2", "node-fit", func(pod *v1.Pod) { - pod.Spec.NodeSelector = map[string]string{ - "datacenter": "west", - } - }) // This pod sits on node6 and is used to take up CPU requests on the node p19 := test.BuildTestPod("CPU-eater", 150, 150, node6.Name, func(pod *v1.Pod) { @@ -308,7 +303,11 @@ func TestFindDuplicatePods(t *testing.T) { "datacenter": "west", } }), - p17, + buildTestPodWithRSOwnerRefWithNamespaceForNode1("NOT2", "node-fit", func(pod *v1.Pod) { + pod.Spec.NodeSelector = map[string]string{ + "datacenter": "west", + } + }), }, nodes: []*v1.Node{node1, node4}, expectedEvictedPodCount: 0, From daaa5896a901da1a73ccd0f1a72bd7c81c330b36 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 14:26:23 +0100 Subject: [PATCH 23/32] refactor(TestFindDuplicatePods): inline p19 pod creation --- .../plugins/removeduplicates/removeduplicates_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index b8ec243e8..9e312434b 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -102,9 +102,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Pods Evictable Based On Node Fit ### // This pod sits on node6 and is used to take up CPU requests on the node - p19 := test.BuildTestPod("CPU-eater", 150, 150, node6.Name, func(pod *v1.Pod) { - pod.Namespace = "test" - }) // Dummy pod for node6 used to do the opposite of p19 p20 := test.BuildTestPod("CPU-saver", 100, 150, node6.Name, func(pod *v1.Pod) { @@ -330,7 +327,9 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), - p19, + test.BuildTestPod("CPU-eater", 150, 150, node6.Name, func(pod *v1.Pod) { + pod.Namespace = "test" + }), }, nodes: []*v1.Node{node1, node6}, expectedEvictedPodCount: 0, From b8b0fa0565af46ebab7d9d6fc8358c34c16fadea Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 14:27:05 +0100 Subject: [PATCH 24/32] refactor(TestFindDuplicatePods): inline p20 pod creation --- .../plugins/removeduplicates/removeduplicates_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 9e312434b..a145548c0 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -104,9 +104,6 @@ func TestFindDuplicatePods(t *testing.T) { // This pod sits on node6 and is used to take up CPU requests on the node // Dummy pod for node6 used to do the opposite of p19 - p20 := test.BuildTestPod("CPU-saver", 100, 150, node6.Name, func(pod *v1.Pod) { - pod.Namespace = "test" - }) // ### Evictable Pods ### @@ -341,7 +338,9 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), - p20, + test.BuildTestPod("CPU-saver", 100, 150, node6.Name, func(pod *v1.Pod) { + pod.Namespace = "test" + }), }, nodes: []*v1.Node{node1, node6}, expectedEvictedPodCount: 1, From 47275831abf5298f2b4ee160d8311c5358bc0592 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 15:54:08 +0100 Subject: [PATCH 25/32] refactor(TestFindDuplicatePods): apply buildTestNode helper to node variables refactor(TestRemoveDuplicatesUniformly): apply buildTestNode helper --- .../removeduplicates/removeduplicates_test.go | 113 ++++++++++-------- 1 file changed, 62 insertions(+), 51 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index a145548c0..ab8552682 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -33,7 +33,18 @@ import ( "sigs.k8s.io/descheduler/test" ) -const nodeName1 = "n1" +const ( + nodeName1 = "n1" + nodeName2 = "n2" + nodeName3 = "n3" + nodeName4 = "n4" + nodeName5 = "n5" + nodeName6 = "n6" +) + +func buildTestNode(nodeName string, apply func(*v1.Node)) *v1.Node { + return test.BuildTestNode(nodeName, 2000, 3000, 10, apply) +} func buildTestPodForNode1(name string, apply func(*v1.Pod)) *v1.Pod { return test.BuildTestPod(name, 100, 0, nodeName1, apply) @@ -68,9 +79,9 @@ func buildTestPodWithRSOwnerRefWithNamespaceForNode1(name, namespace string, app func TestFindDuplicatePods(t *testing.T) { // first setup pods - node1 := test.BuildTestNode("n1", 2000, 3000, 10, nil) - node2 := test.BuildTestNode("n2", 2000, 3000, 10, nil) - node3 := test.BuildTestNode("n3", 2000, 3000, 10, func(node *v1.Node) { + node1 := buildTestNode(nodeName1, nil) + node2 := buildTestNode(nodeName2, nil) + node3 := buildTestNode(nodeName3, func(node *v1.Node) { node.Spec.Taints = []v1.Taint{ { Key: "hardware", @@ -79,17 +90,17 @@ func TestFindDuplicatePods(t *testing.T) { }, } }) - node4 := test.BuildTestNode("n4", 2000, 3000, 10, func(node *v1.Node) { + node4 := buildTestNode(nodeName4, func(node *v1.Node) { node.ObjectMeta.Labels = map[string]string{ "datacenter": "east", } }) - node5 := test.BuildTestNode("n5", 2000, 3000, 10, func(node *v1.Node) { + node5 := buildTestNode(nodeName5, func(node *v1.Node) { node.Spec = v1.NodeSpec{ Unschedulable: true, } }) - node6 := test.BuildTestNode("n6", 200, 200, 10, nil) + node6 := test.BuildTestNode(nodeName6, 200, 200, 10, nil) // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. // A DaemonSet. @@ -531,9 +542,9 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 2, nodes: []*v1.Node{ - test.BuildTestNode("n1", 2000, 3000, 10, nil), - test.BuildTestNode("n2", 2000, 3000, 10, nil), - test.BuildTestNode("n3", 2000, 3000, 10, nil), + buildTestNode(nodeName1, nil), + buildTestNode(nodeName2, nil), + buildTestNode(nodeName3, nil), }, }, { @@ -552,8 +563,8 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 1, nodes: []*v1.Node{ - test.BuildTestNode("n1", 2000, 3000, 10, nil), - test.BuildTestNode("n2", 2000, 3000, 10, nil), + buildTestNode(nodeName1, nil), + buildTestNode(nodeName2, nil), }, }, { @@ -572,9 +583,9 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 4, nodes: []*v1.Node{ - test.BuildTestNode("n1", 2000, 3000, 10, nil), - test.BuildTestNode("n2", 2000, 3000, 10, nil), - test.BuildTestNode("n3", 2000, 3000, 10, nil), + buildTestNode(nodeName1, nil), + buildTestNode(nodeName2, nil), + buildTestNode(nodeName3, nil), }, }, { @@ -603,9 +614,9 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 4, nodes: []*v1.Node{ - test.BuildTestNode("n1", 2000, 3000, 10, nil), - test.BuildTestNode("n2", 2000, 3000, 10, nil), - test.BuildTestNode("n3", 2000, 3000, 10, nil), + buildTestNode(nodeName1, nil), + buildTestNode(nodeName2, nil), + buildTestNode(nodeName3, nil), }, }, { @@ -617,9 +628,9 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 1, nodes: []*v1.Node{ - test.BuildTestNode("n1", 2000, 3000, 10, nil), - test.BuildTestNode("n2", 2000, 3000, 10, nil), - test.BuildTestNode("n3", 2000, 3000, 10, nil), + buildTestNode(nodeName1, nil), + buildTestNode(nodeName2, nil), + buildTestNode(nodeName3, nil), }, }, { @@ -635,9 +646,9 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 1, nodes: []*v1.Node{ - test.BuildTestNode("n1", 2000, 3000, 10, nil), - test.BuildTestNode("n2", 2000, 3000, 10, nil), - test.BuildTestNode("n3", 2000, 3000, 10, nil), + buildTestNode(nodeName1, nil), + buildTestNode(nodeName2, nil), + buildTestNode(nodeName3, nil), }, }, { @@ -648,9 +659,9 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 0, nodes: []*v1.Node{ - test.BuildTestNode("n1", 2000, 3000, 10, nil), - test.BuildTestNode("n2", 2000, 3000, 10, nil), - test.BuildTestNode("n3", 2000, 3000, 10, nil), + buildTestNode(nodeName1, nil), + buildTestNode(nodeName2, nil), + buildTestNode(nodeName3, nil), }, }, { @@ -669,12 +680,12 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 2, nodes: []*v1.Node{ - test.BuildTestNode("worker1", 2000, 3000, 10, nil), - test.BuildTestNode("worker2", 2000, 3000, 10, nil), - test.BuildTestNode("worker3", 2000, 3000, 10, nil), - test.BuildTestNode("master1", 2000, 3000, 10, setMasterNoScheduleTaint), - test.BuildTestNode("master2", 2000, 3000, 10, setMasterNoScheduleTaint), - test.BuildTestNode("master3", 2000, 3000, 10, setMasterNoScheduleTaint), + buildTestNode("worker1", nil), + buildTestNode("worker2", nil), + buildTestNode("worker3", nil), + buildTestNode("master1", setMasterNoScheduleTaint), + buildTestNode("master2", setMasterNoScheduleTaint), + buildTestNode("master3", setMasterNoScheduleTaint), }, }, { @@ -693,12 +704,12 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 2, nodes: []*v1.Node{ - test.BuildTestNode("worker1", 2000, 3000, 10, nil), - test.BuildTestNode("worker2", 2000, 3000, 10, nil), - test.BuildTestNode("worker3", 2000, 3000, 10, nil), - test.BuildTestNode("master1", 2000, 3000, 10, setMasterNoScheduleLabel), - test.BuildTestNode("master2", 2000, 3000, 10, setMasterNoScheduleLabel), - test.BuildTestNode("master3", 2000, 3000, 10, setMasterNoScheduleLabel), + buildTestNode("worker1", nil), + buildTestNode("worker2", nil), + buildTestNode("worker3", nil), + buildTestNode("master1", setMasterNoScheduleLabel), + buildTestNode("master2", setMasterNoScheduleLabel), + buildTestNode("master3", setMasterNoScheduleLabel), }, }, { @@ -717,12 +728,12 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 2, nodes: []*v1.Node{ - test.BuildTestNode("worker1", 2000, 3000, 10, setWorkerLabel), - test.BuildTestNode("worker2", 2000, 3000, 10, setWorkerLabel), - test.BuildTestNode("worker3", 2000, 3000, 10, setWorkerLabel), - test.BuildTestNode("master1", 2000, 3000, 10, nil), - test.BuildTestNode("master2", 2000, 3000, 10, nil), - test.BuildTestNode("master3", 2000, 3000, 10, nil), + buildTestNode("worker1", setWorkerLabel), + buildTestNode("worker2", setWorkerLabel), + buildTestNode("worker3", setWorkerLabel), + buildTestNode("master1", nil), + buildTestNode("master2", nil), + buildTestNode("master3", nil), }, }, { @@ -741,12 +752,12 @@ func TestRemoveDuplicatesUniformly(t *testing.T) { }, expectedEvictedPodCount: 0, nodes: []*v1.Node{ - test.BuildTestNode("worker1", 2000, 3000, 10, nil), - test.BuildTestNode("worker2", 2000, 3000, 10, nil), - test.BuildTestNode("worker3", 2000, 3000, 10, nil), - test.BuildTestNode("master1", 2000, 3000, 10, nil), - test.BuildTestNode("master2", 2000, 3000, 10, nil), - test.BuildTestNode("master3", 2000, 3000, 10, nil), + buildTestNode("worker1", nil), + buildTestNode("worker2", nil), + buildTestNode("worker3", nil), + buildTestNode("master1", nil), + buildTestNode("master2", nil), + buildTestNode("master3", nil), }, }, } From fd524f217201e60dc49cc4bce5f7ac4bfe89689a Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 16:07:27 +0100 Subject: [PATCH 26/32] refactor(TestFindDuplicatePods): inline node1 creation --- .../removeduplicates/removeduplicates_test.go | 71 +++++++++++++++---- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index ab8552682..2428e5f0f 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -79,7 +79,6 @@ func buildTestPodWithRSOwnerRefWithNamespaceForNode1(name, namespace string, app func TestFindDuplicatePods(t *testing.T) { // first setup pods - node1 := buildTestNode(nodeName1, nil) node2 := buildTestNode(nodeName2, nil) node3 := buildTestNode(nodeName3, func(node *v1.Node) { node.Spec.Taints = []v1.Taint{ @@ -135,7 +134,10 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), }, - nodes: []*v1.Node{node1, node2}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node2, + }, expectedEvictedPodCount: 1, }, { @@ -145,7 +147,10 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), }, - nodes: []*v1.Node{node1, node2}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node2, + }, expectedEvictedPodCount: 0, excludeOwnerKinds: []string{"ReplicaSet"}, }, @@ -156,7 +161,10 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p10", "test", nil), }, - nodes: []*v1.Node{node1, node2}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node2, + }, expectedEvictedPodCount: 1, }, { @@ -169,7 +177,10 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p10", "test", nil), }, - nodes: []*v1.Node{node1, node2}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node2, + }, expectedEvictedPodCount: 2, }, { @@ -201,7 +212,10 @@ func TestFindDuplicatePods(t *testing.T) { pod.Spec.Priority = &priority }), }, - nodes: []*v1.Node{node1, node2}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node2, + }, expectedEvictedPodCount: 0, }, { @@ -239,7 +253,10 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p9", "test", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p10", "test", nil), }, - nodes: []*v1.Node{node1, node2}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node2, + }, expectedEvictedPodCount: 2, }, { @@ -252,7 +269,10 @@ func TestFindDuplicatePods(t *testing.T) { pod.Spec.Containers[0].Image = "bar" }), }, - nodes: []*v1.Node{node1, node2}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node2, + }, expectedEvictedPodCount: 0, }, { @@ -265,7 +285,10 @@ func TestFindDuplicatePods(t *testing.T) { }) }), }, - nodes: []*v1.Node{node1, node2}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node2, + }, expectedEvictedPodCount: 0, }, { @@ -281,7 +304,10 @@ func TestFindDuplicatePods(t *testing.T) { }) }), }, - nodes: []*v1.Node{node1, node2}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node2, + }, expectedEvictedPodCount: 0, }, { @@ -291,7 +317,10 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), }, - nodes: []*v1.Node{node1, node3}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node3, + }, expectedEvictedPodCount: 0, nodefit: true, }, @@ -314,7 +343,10 @@ func TestFindDuplicatePods(t *testing.T) { } }), }, - nodes: []*v1.Node{node1, node4}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node4, + }, expectedEvictedPodCount: 0, nodefit: true, }, @@ -325,7 +357,10 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), }, - nodes: []*v1.Node{node1, node5}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node5, + }, expectedEvictedPodCount: 0, nodefit: true, }, @@ -339,7 +374,10 @@ func TestFindDuplicatePods(t *testing.T) { pod.Namespace = "test" }), }, - nodes: []*v1.Node{node1, node6}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node6, + }, expectedEvictedPodCount: 0, nodefit: true, }, @@ -353,7 +391,10 @@ func TestFindDuplicatePods(t *testing.T) { pod.Namespace = "test" }), }, - nodes: []*v1.Node{node1, node6}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node6, + }, expectedEvictedPodCount: 1, nodefit: true, }, From fc033caf2109702cc3069c1d7df68a525913ebd8 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 16:09:30 +0100 Subject: [PATCH 27/32] refactor(TestFindDuplicatePods): inline node2 creation --- .../removeduplicates/removeduplicates_test.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 2428e5f0f..88239f735 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -79,7 +79,6 @@ func buildTestPodWithRSOwnerRefWithNamespaceForNode1(name, namespace string, app func TestFindDuplicatePods(t *testing.T) { // first setup pods - node2 := buildTestNode(nodeName2, nil) node3 := buildTestNode(nodeName3, func(node *v1.Node) { node.Spec.Taints = []v1.Taint{ { @@ -136,7 +135,7 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node2, + buildTestNode(nodeName2, nil), }, expectedEvictedPodCount: 1, }, @@ -149,7 +148,7 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node2, + buildTestNode(nodeName2, nil), }, expectedEvictedPodCount: 0, excludeOwnerKinds: []string{"ReplicaSet"}, @@ -163,7 +162,7 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node2, + buildTestNode(nodeName2, nil), }, expectedEvictedPodCount: 1, }, @@ -179,7 +178,7 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node2, + buildTestNode(nodeName2, nil), }, expectedEvictedPodCount: 2, }, @@ -214,7 +213,7 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node2, + buildTestNode(nodeName2, nil), }, expectedEvictedPodCount: 0, }, @@ -255,7 +254,7 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node2, + buildTestNode(nodeName2, nil), }, expectedEvictedPodCount: 2, }, @@ -271,7 +270,7 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node2, + buildTestNode(nodeName2, nil), }, expectedEvictedPodCount: 0, }, @@ -287,7 +286,7 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node2, + buildTestNode(nodeName2, nil), }, expectedEvictedPodCount: 0, }, @@ -306,7 +305,7 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node2, + buildTestNode(nodeName2, nil), }, expectedEvictedPodCount: 0, }, From babc4137a4ce4ba8c548ff1b5df566703e983ace Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 16:09:49 +0100 Subject: [PATCH 28/32] refactor(TestFindDuplicatePods): inline node3 creation --- .../removeduplicates/removeduplicates_test.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 88239f735..2d5069217 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -79,15 +79,6 @@ func buildTestPodWithRSOwnerRefWithNamespaceForNode1(name, namespace string, app func TestFindDuplicatePods(t *testing.T) { // first setup pods - node3 := buildTestNode(nodeName3, func(node *v1.Node) { - node.Spec.Taints = []v1.Taint{ - { - Key: "hardware", - Value: "gpu", - Effect: v1.TaintEffectNoSchedule, - }, - } - }) node4 := buildTestNode(nodeName4, func(node *v1.Node) { node.ObjectMeta.Labels = map[string]string{ "datacenter": "east", @@ -318,7 +309,15 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node3, + buildTestNode(nodeName3, func(node *v1.Node) { + node.Spec.Taints = []v1.Taint{ + { + Key: "hardware", + Value: "gpu", + Effect: v1.TaintEffectNoSchedule, + }, + } + }), }, expectedEvictedPodCount: 0, nodefit: true, From 2fac727be39a18848706de0d581b056e46e21bf6 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 16:10:09 +0100 Subject: [PATCH 29/32] refactor(TestFindDuplicatePods): inline node4 creation --- .../plugins/removeduplicates/removeduplicates_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 2d5069217..0e23ba2ee 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -79,11 +79,6 @@ func buildTestPodWithRSOwnerRefWithNamespaceForNode1(name, namespace string, app func TestFindDuplicatePods(t *testing.T) { // first setup pods - node4 := buildTestNode(nodeName4, func(node *v1.Node) { - node.ObjectMeta.Labels = map[string]string{ - "datacenter": "east", - } - }) node5 := buildTestNode(nodeName5, func(node *v1.Node) { node.Spec = v1.NodeSpec{ Unschedulable: true, @@ -343,7 +338,11 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node4, + buildTestNode(nodeName4, func(node *v1.Node) { + node.ObjectMeta.Labels = map[string]string{ + "datacenter": "east", + } + }), }, expectedEvictedPodCount: 0, nodefit: true, From 6e62af3dbf70b88d848fc72e83155f6c1522afe5 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 16:10:28 +0100 Subject: [PATCH 30/32] refactor(TestFindDuplicatePods): inline node5 creation --- .../plugins/removeduplicates/removeduplicates_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 0e23ba2ee..3eef2a124 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -79,11 +79,6 @@ func buildTestPodWithRSOwnerRefWithNamespaceForNode1(name, namespace string, app func TestFindDuplicatePods(t *testing.T) { // first setup pods - node5 := buildTestNode(nodeName5, func(node *v1.Node) { - node.Spec = v1.NodeSpec{ - Unschedulable: true, - } - }) node6 := test.BuildTestNode(nodeName6, 200, 200, 10, nil) // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. @@ -356,7 +351,11 @@ func TestFindDuplicatePods(t *testing.T) { }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node5, + buildTestNode(nodeName5, func(node *v1.Node) { + node.Spec = v1.NodeSpec{ + Unschedulable: true, + } + }), }, expectedEvictedPodCount: 0, nodefit: true, From 044f75dceca8bc21908e83972b6d750c9625841b Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 16:10:49 +0100 Subject: [PATCH 31/32] refactor(TestFindDuplicatePods): inline node6 creation --- .../plugins/removeduplicates/removeduplicates_test.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 3eef2a124..60ec327a0 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -79,7 +79,6 @@ func buildTestPodWithRSOwnerRefWithNamespaceForNode1(name, namespace string, app func TestFindDuplicatePods(t *testing.T) { // first setup pods - node6 := test.BuildTestNode(nodeName6, 200, 200, 10, nil) // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. // A DaemonSet. @@ -366,13 +365,13 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), - test.BuildTestPod("CPU-eater", 150, 150, node6.Name, func(pod *v1.Pod) { + test.BuildTestPod("CPU-eater", 150, 150, nodeName6, func(pod *v1.Pod) { pod.Namespace = "test" }), }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node6, + test.BuildTestNode(nodeName6, 200, 200, 10, nil), }, expectedEvictedPodCount: 0, nodefit: true, @@ -383,13 +382,13 @@ func TestFindDuplicatePods(t *testing.T) { buildTestPodWithRSOwnerRefWithNamespaceForNode1("p1", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p2", "dev", nil), buildTestPodWithRSOwnerRefWithNamespaceForNode1("p3", "dev", nil), - test.BuildTestPod("CPU-saver", 100, 150, node6.Name, func(pod *v1.Pod) { + test.BuildTestPod("CPU-saver", 100, 150, nodeName6, func(pod *v1.Pod) { pod.Namespace = "test" }), }, nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node6, + test.BuildTestNode(nodeName6, 200, 200, 10, nil), }, expectedEvictedPodCount: 1, nodefit: true, From 05b6d5e343eb1038c3b58b2c6eee421d436636cd Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 16:15:33 +0100 Subject: [PATCH 32/32] refactor(TestFindDuplicatePods): remove leftover comments --- .../removeduplicates/removeduplicates_test.go | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 60ec327a0..448ece784 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -78,26 +78,6 @@ func buildTestPodWithRSOwnerRefWithNamespaceForNode1(name, namespace string, app } func TestFindDuplicatePods(t *testing.T) { - // first setup pods - - // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. - // A DaemonSet. - // A Pod with local storage. - // A Mirror Pod. - // A Critical Pod. - // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. - // Same owners, but different images - // Multiple containers - // ### Pods Evictable Based On Node Fit ### - - // This pod sits on node6 and is used to take up CPU requests on the node - - // Dummy pod for node6 used to do the opposite of p19 - - // ### Evictable Pods ### - - // ### Non-evictable Pods ### - testCases := []struct { description string pods []*v1.Pod