From 08c2fc7621118b5f803b31e808c30460ed6370d0 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:22:28 +0100 Subject: [PATCH 01/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../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 4b3eeb545..9e4ec06bf 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -67,8 +67,12 @@ func TestFindDuplicatePods(t *testing.T) { }) node6 := test.BuildTestNode("n6", 200, 200, 10, nil) - p1 := test.BuildTestPod("p1", 100, 0, node1.Name, nil) - p1.Namespace = "dev" + // 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) { + pod.Namespace = "dev" + pod.ObjectMeta.OwnerReferences = ownerRef1 + }) p2 := test.BuildTestPod("p2", 100, 0, node1.Name, nil) p2.Namespace = "dev" p3 := test.BuildTestPod("p3", 100, 0, node1.Name, nil) @@ -112,8 +116,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Evictable Pods ### // Three Pods in the "default" Namespace, bound to same ReplicaSet. 2 should be evicted. - ownerRef1 := test.GetReplicaSetOwnerRefList() - p1.ObjectMeta.OwnerReferences = ownerRef1 p2.ObjectMeta.OwnerReferences = ownerRef1 p3.ObjectMeta.OwnerReferences = ownerRef1 From 5578211253d8b963fff14ca41d1933d00e03b3d6 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:24:22 +0100 Subject: [PATCH 02/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../plugins/removeduplicates/removeduplicates_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 9e4ec06bf..28db8a66a 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -73,8 +73,10 @@ func TestFindDuplicatePods(t *testing.T) { pod.Namespace = "dev" pod.ObjectMeta.OwnerReferences = ownerRef1 }) - p2 := test.BuildTestPod("p2", 100, 0, node1.Name, nil) - p2.Namespace = "dev" + p2 := test.BuildTestPod("p2", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.Namespace = "dev" + pod.ObjectMeta.OwnerReferences = ownerRef1 + }) p3 := test.BuildTestPod("p3", 100, 0, node1.Name, nil) p3.Namespace = "dev" p4 := test.BuildTestPod("p4", 100, 0, node1.Name, nil) @@ -116,7 +118,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Evictable Pods ### // Three Pods in the "default" Namespace, bound to same ReplicaSet. 2 should be evicted. - p2.ObjectMeta.OwnerReferences = ownerRef1 p3.ObjectMeta.OwnerReferences = ownerRef1 // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. From 96171413ba8679b0a51b87b3d1c67719a0df3fa5 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:26:08 +0100 Subject: [PATCH 03/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../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 28db8a66a..5f9186e38 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -77,8 +77,10 @@ func TestFindDuplicatePods(t *testing.T) { pod.Namespace = "dev" pod.ObjectMeta.OwnerReferences = ownerRef1 }) - p3 := test.BuildTestPod("p3", 100, 0, node1.Name, nil) - p3.Namespace = "dev" + p3 := test.BuildTestPod("p3", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.Namespace = "dev" + pod.ObjectMeta.OwnerReferences = ownerRef1 + }) 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) @@ -117,9 +119,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Evictable Pods ### - // Three Pods in the "default" Namespace, bound to same ReplicaSet. 2 should be evicted. - p3.ObjectMeta.OwnerReferences = ownerRef1 - // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. ownerRef2 := test.GetReplicaSetOwnerRefList() p8.ObjectMeta.OwnerReferences = ownerRef2 From 3d4263bf5ee3f643de2e432f78a672af3ce1d712 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:26:53 +0100 Subject: [PATCH 04/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../plugins/removeduplicates/removeduplicates_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 5f9186e38..e57e4941a 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -81,7 +81,10 @@ func TestFindDuplicatePods(t *testing.T) { pod.Namespace = "dev" pod.ObjectMeta.OwnerReferences = ownerRef1 }) - p4 := test.BuildTestPod("p4", 100, 0, node1.Name, nil) + // A DaemonSet. + p4 := test.BuildTestPod("p4", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.ObjectMeta.OwnerReferences = test.GetDaemonSetOwnerRefList() + }) 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) @@ -127,9 +130,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - // A DaemonSet. - p4.ObjectMeta.OwnerReferences = test.GetDaemonSetOwnerRefList() - // A Pod with local storage. p5.ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList() p5.Spec.Volumes = []v1.Volume{ From 511ed214b0e5d731f25a96596841cf654cbf312c Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:27:41 +0100 Subject: [PATCH 05/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../removeduplicates/removeduplicates_test.go | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index e57e4941a..72251f699 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -85,7 +85,21 @@ func TestFindDuplicatePods(t *testing.T) { p4 := test.BuildTestPod("p4", 100, 0, node1.Name, func(pod *v1.Pod) { pod.ObjectMeta.OwnerReferences = test.GetDaemonSetOwnerRefList() }) - p5 := test.BuildTestPod("p5", 100, 0, node1.Name, nil) + // A Pod with local storage. + p5 := test.BuildTestPod("p5", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList() + 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 := test.BuildTestPod("p6", 100, 0, node1.Name, nil) p7 := test.BuildTestPod("p7", 100, 0, node1.Name, nil) p7.Namespace = "kube-system" @@ -130,20 +144,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - // A Pod with local storage. - p5.ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList() - p5.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.Annotations = test.GetMirrorPodAnnotation() From 0c33be962d4ff53ccbbe100bc0f7a12289fd5330 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:28:20 +0100 Subject: [PATCH 06/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../plugins/removeduplicates/removeduplicates_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 72251f699..9291bc825 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -100,7 +100,10 @@ func TestFindDuplicatePods(t *testing.T) { }, } }) - p6 := test.BuildTestPod("p6", 100, 0, node1.Name, nil) + // A Mirror Pod. + p6 := test.BuildTestPod("p6", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.Annotations = test.GetMirrorPodAnnotation() + }) p7 := test.BuildTestPod("p7", 100, 0, node1.Name, nil) p7.Namespace = "kube-system" p8 := test.BuildTestPod("p8", 100, 0, node1.Name, nil) @@ -144,9 +147,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - // A Mirror Pod. - p6.Annotations = test.GetMirrorPodAnnotation() - // A Critical Pod. priority := utils.SystemCriticalPriority p7.Spec.Priority = &priority From 4a4ec4afb785276f296d3d6eb9a1060645e11669 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:29:00 +0100 Subject: [PATCH 07/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../removeduplicates/removeduplicates_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 9291bc825..a3490624b 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -104,8 +104,12 @@ func TestFindDuplicatePods(t *testing.T) { p6 := test.BuildTestPod("p6", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Annotations = test.GetMirrorPodAnnotation() }) - p7 := test.BuildTestPod("p7", 100, 0, node1.Name, nil) - p7.Namespace = "kube-system" + // A Critical Pod. + p7 := test.BuildTestPod("p7", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.Namespace = "kube-system" + priority := utils.SystemCriticalPriority + pod.Spec.Priority = &priority + }) p8 := test.BuildTestPod("p8", 100, 0, node1.Name, nil) p8.Namespace = "test" p9 := test.BuildTestPod("p9", 100, 0, node1.Name, nil) @@ -147,10 +151,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - // A Critical Pod. - priority := utils.SystemCriticalPriority - p7.Spec.Priority = &priority - // Same owners, but different images p11.Spec.Containers[0].Image = "foo" p11.ObjectMeta.OwnerReferences = ownerRef1 From b5f177efa0abc43ae12333d47f346bcfaef0b89e Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:29:45 +0100 Subject: [PATCH 08/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../plugins/removeduplicates/removeduplicates_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index a3490624b..8e86c6303 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -110,8 +110,12 @@ func TestFindDuplicatePods(t *testing.T) { priority := utils.SystemCriticalPriority pod.Spec.Priority = &priority }) - p8 := test.BuildTestPod("p8", 100, 0, node1.Name, nil) - p8.Namespace = "test" + // 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) { + pod.Namespace = "test" + pod.ObjectMeta.OwnerReferences = ownerRef2 + }) p9 := test.BuildTestPod("p9", 100, 0, node1.Name, nil) p9.Namespace = "test" p10 := test.BuildTestPod("p10", 100, 0, node1.Name, nil) @@ -143,9 +147,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Evictable Pods ### - // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. - ownerRef2 := test.GetReplicaSetOwnerRefList() - p8.ObjectMeta.OwnerReferences = ownerRef2 p9.ObjectMeta.OwnerReferences = ownerRef2 p10.ObjectMeta.OwnerReferences = ownerRef2 From 7435b5d47479b470af45a070ea1b04f8c219d1d9 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:30:20 +0100 Subject: [PATCH 09/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../plugins/removeduplicates/removeduplicates_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 8e86c6303..793ac6174 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -116,8 +116,10 @@ func TestFindDuplicatePods(t *testing.T) { pod.Namespace = "test" pod.ObjectMeta.OwnerReferences = ownerRef2 }) - p9 := test.BuildTestPod("p9", 100, 0, node1.Name, nil) - p9.Namespace = "test" + p9 := test.BuildTestPod("p9", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.Namespace = "test" + pod.ObjectMeta.OwnerReferences = ownerRef2 + }) p10 := test.BuildTestPod("p10", 100, 0, node1.Name, nil) p10.Namespace = "test" p11 := test.BuildTestPod("p11", 100, 0, node1.Name, nil) @@ -147,7 +149,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Evictable Pods ### - p9.ObjectMeta.OwnerReferences = ownerRef2 p10.ObjectMeta.OwnerReferences = ownerRef2 // ### Non-evictable Pods ### From f2031ddcb0e93c0562f3042ae7278a63e45f2faf Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:30:58 +0100 Subject: [PATCH 10/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../plugins/removeduplicates/removeduplicates_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 793ac6174..6222e4537 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -120,8 +120,10 @@ func TestFindDuplicatePods(t *testing.T) { pod.Namespace = "test" pod.ObjectMeta.OwnerReferences = ownerRef2 }) - p10 := test.BuildTestPod("p10", 100, 0, node1.Name, nil) - p10.Namespace = "test" + p10 := test.BuildTestPod("p10", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.Namespace = "test" + pod.ObjectMeta.OwnerReferences = ownerRef2 + }) p11 := test.BuildTestPod("p11", 100, 0, node1.Name, nil) p11.Namespace = "different-images" p12 := test.BuildTestPod("p12", 100, 0, node1.Name, nil) @@ -149,8 +151,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Evictable Pods ### - p10.ObjectMeta.OwnerReferences = ownerRef2 - // ### Non-evictable Pods ### // Same owners, but different images From 294ce3923181c229ca7b47c05abd9ec55c5dc75b Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:31:37 +0100 Subject: [PATCH 11/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../plugins/removeduplicates/removeduplicates_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 6222e4537..f835f0251 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -124,8 +124,12 @@ func TestFindDuplicatePods(t *testing.T) { pod.Namespace = "test" pod.ObjectMeta.OwnerReferences = ownerRef2 }) - p11 := test.BuildTestPod("p11", 100, 0, node1.Name, nil) - p11.Namespace = "different-images" + // Same owners, but different images + p11 := test.BuildTestPod("p11", 100, 0, node1.Name, 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, nil) p12.Namespace = "different-images" p13 := test.BuildTestPod("p13", 100, 0, node1.Name, nil) @@ -153,9 +157,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - // Same owners, but different images - p11.Spec.Containers[0].Image = "foo" - p11.ObjectMeta.OwnerReferences = ownerRef1 p12.Spec.Containers[0].Image = "bar" p12.ObjectMeta.OwnerReferences = ownerRef1 From 660e2dba4019cd9c0324438ac4f6be6c0ddf520c Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:32:16 +0100 Subject: [PATCH 12/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../plugins/removeduplicates/removeduplicates_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index f835f0251..e66da0009 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -130,8 +130,11 @@ func TestFindDuplicatePods(t *testing.T) { pod.Spec.Containers[0].Image = "foo" pod.ObjectMeta.OwnerReferences = ownerRef1 }) - p12 := test.BuildTestPod("p12", 100, 0, node1.Name, nil) - p12.Namespace = "different-images" + p12 := test.BuildTestPod("p12", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.Namespace = "different-images" + pod.Spec.Containers[0].Image = "bar" + pod.ObjectMeta.OwnerReferences = ownerRef1 + }) p13 := test.BuildTestPod("p13", 100, 0, node1.Name, nil) p13.Namespace = "different-images" p14 := test.BuildTestPod("p14", 100, 0, node1.Name, nil) @@ -157,9 +160,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - p12.Spec.Containers[0].Image = "bar" - p12.ObjectMeta.OwnerReferences = ownerRef1 - // Multiple containers p13.ObjectMeta.OwnerReferences = ownerRef1 p13.Spec.Containers = append(p13.Spec.Containers, v1.Container{ From 8dada7959375ce6444dfae2ef26f6ccfe8ff4f37 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:33:00 +0100 Subject: [PATCH 13/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../removeduplicates/removeduplicates_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index e66da0009..aeb3198ff 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -135,8 +135,15 @@ func TestFindDuplicatePods(t *testing.T) { pod.Spec.Containers[0].Image = "bar" pod.ObjectMeta.OwnerReferences = ownerRef1 }) - p13 := test.BuildTestPod("p13", 100, 0, node1.Name, nil) - p13.Namespace = "different-images" + // Multiple containers + p13 := test.BuildTestPod("p13", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.Namespace = "different-images" + pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ + Name: "foo", + Image: "foo", + }) + }) p14 := test.BuildTestPod("p14", 100, 0, node1.Name, nil) p14.Namespace = "different-images" p15 := test.BuildTestPod("p15", 100, 0, node1.Name, nil) @@ -160,13 +167,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - // Multiple containers - p13.ObjectMeta.OwnerReferences = ownerRef1 - p13.Spec.Containers = append(p13.Spec.Containers, v1.Container{ - Name: "foo", - Image: "foo", - }) - // ### Pods Evictable Based On Node Fit ### ownerRef3 := test.GetReplicaSetOwnerRefList() From 800dd280cd09cbc7a39dd729b0887dc3672110ae Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:33:56 +0100 Subject: [PATCH 14/20] refactor(TestFindDuplicatePods): drop unused variable --- pkg/framework/plugins/removeduplicates/removeduplicates_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index aeb3198ff..15e9bb927 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -144,8 +144,6 @@ func TestFindDuplicatePods(t *testing.T) { Image: "foo", }) }) - p14 := test.BuildTestPod("p14", 100, 0, node1.Name, nil) - p14.Namespace = "different-images" p15 := test.BuildTestPod("p15", 100, 0, node1.Name, nil) p15.Namespace = "node-fit" p16 := test.BuildTestPod("NOT1", 100, 0, node1.Name, nil) From 56f49bc78f463a24c176a9466c3926ceac7b3d6e Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:34:40 +0100 Subject: [PATCH 15/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../removeduplicates/removeduplicates_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 15e9bb927..775611e64 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -144,8 +144,15 @@ func TestFindDuplicatePods(t *testing.T) { Image: "foo", }) }) - p15 := test.BuildTestPod("p15", 100, 0, node1.Name, nil) - p15.Namespace = "node-fit" + // ### Pods Evictable Based On Node Fit ### + ownerRef3 := test.GetReplicaSetOwnerRefList() + p15 := test.BuildTestPod("p15", 100, 0, node1.Name, 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, nil) p16.Namespace = "node-fit" p17 := test.BuildTestPod("NOT2", 100, 0, node1.Name, nil) @@ -165,17 +172,10 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - // ### Pods Evictable Based On Node Fit ### - - ownerRef3 := test.GetReplicaSetOwnerRefList() - p15.ObjectMeta.OwnerReferences = ownerRef3 p16.ObjectMeta.OwnerReferences = ownerRef3 p17.ObjectMeta.OwnerReferences = ownerRef3 p18.ObjectMeta.OwnerReferences = ownerRef3 - p15.Spec.NodeSelector = map[string]string{ - "datacenter": "west", - } p16.Spec.NodeSelector = map[string]string{ "datacenter": "west", } From 3bb99512d8b2a93f56211470be49e1fdb59732f3 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:35:17 +0100 Subject: [PATCH 16/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../removeduplicates/removeduplicates_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 775611e64..9d17d320f 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -153,8 +153,13 @@ func TestFindDuplicatePods(t *testing.T) { "datacenter": "west", } }) - p16 := test.BuildTestPod("NOT1", 100, 0, node1.Name, nil) - p16.Namespace = "node-fit" + p16 := test.BuildTestPod("NOT1", 100, 0, node1.Name, 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, nil) p17.Namespace = "node-fit" p18 := test.BuildTestPod("TARGET", 100, 0, node1.Name, nil) @@ -172,13 +177,9 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - p16.ObjectMeta.OwnerReferences = ownerRef3 p17.ObjectMeta.OwnerReferences = ownerRef3 p18.ObjectMeta.OwnerReferences = ownerRef3 - p16.Spec.NodeSelector = map[string]string{ - "datacenter": "west", - } p17.Spec.NodeSelector = map[string]string{ "datacenter": "west", } From 6f94e193858ebb4c9061b41a9de3665f3077e9d0 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:35:54 +0100 Subject: [PATCH 17/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../removeduplicates/removeduplicates_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 9d17d320f..3da353e0c 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -160,8 +160,13 @@ func TestFindDuplicatePods(t *testing.T) { "datacenter": "west", } }) - p17 := test.BuildTestPod("NOT2", 100, 0, node1.Name, nil) - p17.Namespace = "node-fit" + p17 := test.BuildTestPod("NOT2", 100, 0, node1.Name, func(pod *v1.Pod) { + pod.Namespace = "node-fit" + pod.ObjectMeta.OwnerReferences = ownerRef3 + pod.Spec.NodeSelector = map[string]string{ + "datacenter": "west", + } + }) p18 := test.BuildTestPod("TARGET", 100, 0, node1.Name, nil) p18.Namespace = "node-fit" @@ -177,13 +182,8 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - p17.ObjectMeta.OwnerReferences = ownerRef3 p18.ObjectMeta.OwnerReferences = ownerRef3 - p17.Spec.NodeSelector = map[string]string{ - "datacenter": "west", - } - testCases := []struct { description string pods []*v1.Pod From 8f3c5f4978d4aae7b00bbd25c2f3518759ebc180 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:36:53 +0100 Subject: [PATCH 18/20] refactor(TestFindDuplicatePods): drop unused variable --- .../plugins/removeduplicates/removeduplicates_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 3da353e0c..237a9bfa1 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -167,8 +167,6 @@ func TestFindDuplicatePods(t *testing.T) { "datacenter": "west", } }) - p18 := test.BuildTestPod("TARGET", 100, 0, node1.Name, nil) - p18.Namespace = "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, nil) @@ -182,8 +180,6 @@ func TestFindDuplicatePods(t *testing.T) { // ### Non-evictable Pods ### - p18.ObjectMeta.OwnerReferences = ownerRef3 - testCases := []struct { description string pods []*v1.Pod From b21fb4a655625e8136ac2d1317e126863be04ebe Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:37:22 +0100 Subject: [PATCH 19/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../plugins/removeduplicates/removeduplicates_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 237a9bfa1..98b471685 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -169,8 +169,9 @@ func TestFindDuplicatePods(t *testing.T) { }) // 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, nil) - p19.Namespace = "test" + 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, nil) From e46b5db6d5a06a9817ac016c27ff841228742b6d Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Sun, 14 Dec 2025 12:37:58 +0100 Subject: [PATCH 20/20] refactor(TestFindDuplicatePods): have a pod fully created through BuildTestPod without any edits --- .../plugins/removeduplicates/removeduplicates_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go index 98b471685..787a4b566 100644 --- a/pkg/framework/plugins/removeduplicates/removeduplicates_test.go +++ b/pkg/framework/plugins/removeduplicates/removeduplicates_test.go @@ -174,8 +174,9 @@ func TestFindDuplicatePods(t *testing.T) { }) // Dummy pod for node6 used to do the opposite of p19 - p20 := test.BuildTestPod("CPU-saver", 100, 150, node6.Name, nil) - p20.Namespace = "test" + p20 := test.BuildTestPod("CPU-saver", 100, 150, node6.Name, func(pod *v1.Pod) { + pod.Namespace = "test" + }) // ### Evictable Pods ###