From ff430020601009eaf5a6709e2bb10a8bd221d7a8 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:43:07 +0100 Subject: [PATCH 01/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- .../plugins/podlifetime/pod_lifetime_test.go | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index c0b117dd5..4c5d1e965 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -62,7 +62,6 @@ func TestPodLifeTime(t *testing.T) { } // Setup pods, one should be evicted - p1 := buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil) p2 := buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil) // Setup pods, zero should be evicted @@ -132,7 +131,10 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p1, p2}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), + p2, + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, @@ -267,7 +269,11 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p1, p2, p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), + p2, + p9, + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 2, maxPodsToEvictPerNode: nil, @@ -278,7 +284,11 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p1, p2, p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), + p2, + p9, + }, nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNamespace: utilptr.To[uint](1), expectedEvictedPodCount: 1, @@ -288,7 +298,11 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p1, p2, p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), + p2, + p9, + }, nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNamespace: utilptr.To[uint](2), maxPodsToEvictTotal: utilptr.To[uint](1), @@ -299,7 +313,11 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p1, p2, p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), + p2, + p9, + }, nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNode: utilptr.To[uint](1), expectedEvictedPodCount: 1, From 2648749eb89c433844e6c7dbc31ffbcf0ef7ecb3 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:45:10 +0100 Subject: [PATCH 02/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- .../plugins/podlifetime/pod_lifetime_test.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 4c5d1e965..99fa3a2c1 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -61,9 +61,6 @@ func TestPodLifeTime(t *testing.T) { }) } - // Setup pods, one should be evicted - p2 := buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil) - // Setup pods, zero should be evicted p3 := buildTestPodWithRSOwnerRefForNode1("p3", newerPodCreationTime, nil) p4 := buildTestPodWithRSOwnerRefForNode1("p4", newerPodCreationTime, nil) @@ -133,7 +130,7 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), - p2, + buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil), }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, @@ -271,7 +268,7 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), - p2, + buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil), p9, }, nodes: []*v1.Node{buildTestNode1()}, @@ -286,7 +283,7 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), - p2, + buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil), p9, }, nodes: []*v1.Node{buildTestNode1()}, @@ -300,7 +297,7 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), - p2, + buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil), p9, }, nodes: []*v1.Node{buildTestNode1()}, @@ -315,7 +312,7 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), - p2, + buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil), p9, }, nodes: []*v1.Node{buildTestNode1()}, From 3e764eb564b39f0e9a86f8f0be222ae63174b537 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:45:53 +0100 Subject: [PATCH 03/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 99fa3a2c1..7ca8fedfb 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -62,7 +62,6 @@ func TestPodLifeTime(t *testing.T) { } // Setup pods, zero should be evicted - p3 := buildTestPodWithRSOwnerRefForNode1("p3", newerPodCreationTime, nil) p4 := buildTestPodWithRSOwnerRefForNode1("p4", newerPodCreationTime, nil) // Setup pods, one should be evicted @@ -140,7 +139,10 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p3, p4}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p3", newerPodCreationTime, nil), + p4, + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, }, From b8578693712b20674ee67f3f1dc46544bd205fec Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:47:08 +0100 Subject: [PATCH 04/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 7ca8fedfb..266ff3803 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -61,9 +61,6 @@ func TestPodLifeTime(t *testing.T) { }) } - // Setup pods, zero should be evicted - p4 := buildTestPodWithRSOwnerRefForNode1("p4", newerPodCreationTime, nil) - // Setup pods, one should be evicted p5 := buildTestPodWithRSOwnerRefForNode1("p5", newerPodCreationTime, nil) p6 := buildTestPodWithRSOwnerRefForNode1("p6", metav1.NewTime(time.Now().Add(-time.Second*605)), nil) @@ -141,7 +138,7 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p3", newerPodCreationTime, nil), - p4, + buildTestPodWithRSOwnerRefForNode1("p4", newerPodCreationTime, nil), }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, From 5e6cd6057b644f44a3b2919f2f25def4c8d730fc Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:52:24 +0100 Subject: [PATCH 05/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 266ff3803..6ac355e04 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -62,7 +62,6 @@ func TestPodLifeTime(t *testing.T) { } // Setup pods, one should be evicted - p5 := buildTestPodWithRSOwnerRefForNode1("p5", newerPodCreationTime, nil) p6 := buildTestPodWithRSOwnerRefForNode1("p6", metav1.NewTime(time.Now().Add(-time.Second*605)), nil) // Setup pods, zero should be evicted @@ -148,7 +147,10 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p5, p6}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p5", newerPodCreationTime, nil), + p6, + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, From 8a0fd10315258d42a32319e356ed5a97066e66af Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:53:19 +0100 Subject: [PATCH 06/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 6ac355e04..def94dfdf 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -61,9 +61,6 @@ func TestPodLifeTime(t *testing.T) { }) } - // Setup pods, one should be evicted - p6 := buildTestPodWithRSOwnerRefForNode1("p6", metav1.NewTime(time.Now().Add(-time.Second*605)), nil) - // Setup pods, zero should be evicted p7 := buildTestPodForNode1("p7", newerPodCreationTime, nil) p8 := buildTestPodForNode1("p8", metav1.NewTime(time.Now().Add(-time.Second*595)), nil) @@ -149,7 +146,7 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p5", newerPodCreationTime, nil), - p6, + buildTestPodWithRSOwnerRefForNode1("p6", metav1.NewTime(time.Now().Add(-time.Second*605)), nil), }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, From bed39d70f08ffd43b8a79fbad247960e22fe9220 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:54:04 +0100 Subject: [PATCH 07/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index def94dfdf..20dc6c1e3 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -62,7 +62,6 @@ func TestPodLifeTime(t *testing.T) { } // Setup pods, zero should be evicted - p7 := buildTestPodForNode1("p7", newerPodCreationTime, nil) p8 := buildTestPodForNode1("p8", metav1.NewTime(time.Now().Add(-time.Second*595)), nil) // Setup two old pods with different status phases @@ -156,7 +155,10 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p7, p8}, + pods: []*v1.Pod{ + buildTestPodForNode1("p7", newerPodCreationTime, nil), + p8, + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, }, From 9be42e50cc563940bdd3cdc29b0b83eac9bb362a Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:55:12 +0100 Subject: [PATCH 08/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 20dc6c1e3..ba02dfe58 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -61,9 +61,6 @@ func TestPodLifeTime(t *testing.T) { }) } - // Setup pods, zero should be evicted - p8 := buildTestPodForNode1("p8", metav1.NewTime(time.Now().Add(-time.Second*595)), nil) - // Setup two old pods with different status phases p9 := buildTestPodWithRSOwnerRefForNode1("p9", olderPodCreationTime, func(pod *v1.Pod) { pod.Status.Phase = "Pending" @@ -157,7 +154,7 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ buildTestPodForNode1("p7", newerPodCreationTime, nil), - p8, + buildTestPodForNode1("p8", metav1.NewTime(time.Now().Add(-time.Second*595)), nil), }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, From c707f53cecc9e223e2621c0680551058b13de372 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 16:00:28 +0100 Subject: [PATCH 09/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- .../plugins/podlifetime/pod_lifetime_test.go | 89 +++++++++++++------ 1 file changed, 64 insertions(+), 25 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index ba02dfe58..8698bc4f8 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -61,10 +61,16 @@ func TestPodLifeTime(t *testing.T) { }) } + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1 := func(name string, creationTime metav1.Time, apply func(*v1.Pod)) *v1.Pod { + return buildTestPodWithRSOwnerRefForNode1(name, creationTime, func(pod *v1.Pod) { + pod.Status.Phase = "Pending" + if apply != nil { + apply(pod) + } + }) + } + // Setup two old pods with different status phases - p9 := buildTestPodWithRSOwnerRefForNode1("p9", olderPodCreationTime, func(pod *v1.Pod) { - pod.Status.Phase = "Pending" - }) p10 := buildTestPodWithRSOwnerRefForNode1("p10", olderPodCreationTime, func(pod *v1.Pod) { pod.Status.Phase = "Running" }) @@ -166,7 +172,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"ContainerCreating"}, }, pods: []*v1.Pod{ - p9, + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), test.BuildTestPod("container-creating-stuck", 0, 0, nodeName1, func(pod *v1.Pod) { pod.Status.ContainerStatuses = []v1.ContainerStatus{ { @@ -189,7 +195,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"PodInitializing"}, }, pods: []*v1.Pod{ - p9, + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), test.BuildTestPod("pod-initializing-stuck", 0, 0, nodeName1, func(pod *v1.Pod) { pod.Status.ContainerStatuses = []v1.ContainerStatus{ { @@ -211,7 +217,10 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"Pending"}, }, - pods: []*v1.Pod{p9, p10}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + p10, + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, @@ -266,7 +275,7 @@ func TestPodLifeTime(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil), - p9, + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 2, @@ -281,7 +290,7 @@ func TestPodLifeTime(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil), - p9, + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), }, nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNamespace: utilptr.To[uint](1), @@ -295,7 +304,7 @@ func TestPodLifeTime(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil), - p9, + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), }, nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNamespace: utilptr.To[uint](2), @@ -310,7 +319,7 @@ func TestPodLifeTime(t *testing.T) { pods: []*v1.Pod{ buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil), buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil), - p9, + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), }, nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNode: utilptr.To[uint](1), @@ -322,7 +331,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"ImagePullBackOff"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -341,7 +352,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"CrashLoopBackOff"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -360,7 +373,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"CreateContainerConfigError"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -379,7 +394,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"ErrImagePull"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -398,7 +415,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"CreateContainerError"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, applyPodsFunc: func(pods []*v1.Pod) { @@ -418,7 +437,9 @@ func TestPodLifeTime(t *testing.T) { States: []string{"CreateContainerError"}, IncludingInitContainers: true, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -437,7 +458,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"CreateContainerError"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, applyPodsFunc: func(pods []*v1.Pod) { @@ -457,7 +480,9 @@ func TestPodLifeTime(t *testing.T) { States: []string{"CreateContainerError"}, IncludingEphemeralContainers: true, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -476,7 +501,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"CreateContainerError"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -495,7 +522,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"InvalidImageName"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -514,7 +543,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"NodeLost"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -527,7 +558,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"NodeAffinity"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -540,7 +573,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"Shutdown"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -553,7 +588,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"UnexpectedAdmissionError"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -605,7 +642,9 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{"ContainerCreating"}, }, - pods: []*v1.Pod{p9}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, applyPodsFunc: func(pods []*v1.Pod) { From 41a0a9c994f613809d873f3c86de4d4a727fe183 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 16:02:14 +0100 Subject: [PATCH 10/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 8698bc4f8..fdb1e7870 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -70,11 +70,6 @@ func TestPodLifeTime(t *testing.T) { }) } - // Setup two old pods with different status phases - p10 := buildTestPodWithRSOwnerRefForNode1("p10", olderPodCreationTime, func(pod *v1.Pod) { - pod.Status.Phase = "Running" - }) - p11 := buildTestPodWithRSOwnerRefForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) { pod.Spec.Volumes = []v1.Volume{ { @@ -219,7 +214,9 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ buildTestPodWithRSOwnerRefWithPendingPhaseForNode1("p9", olderPodCreationTime, nil), - p10, + buildTestPodWithRSOwnerRefForNode1("p10", olderPodCreationTime, func(pod *v1.Pod) { + pod.Status.Phase = "Running" + }), }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, From 3ea0eadcb34d74016903707d2be0cb376838eb83 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 16:03:33 +0100 Subject: [PATCH 11/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- .../plugins/podlifetime/pod_lifetime_test.go | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index fdb1e7870..3e7434e81 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -70,16 +70,6 @@ func TestPodLifeTime(t *testing.T) { }) } - p11 := buildTestPodWithRSOwnerRefForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) { - pod.Spec.Volumes = []v1.Volume{ - { - Name: "pvc", VolumeSource: v1.VolumeSource{ - PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: "foo"}, - }, - }, - } - }) - // Setup two old pods with different labels p12 := buildTestPodWithRSOwnerRefForNode1("p12", olderPodCreationTime, func(pod *v1.Pod) { pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} @@ -226,7 +216,17 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p11}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) { + pod.Spec.Volumes = []v1.Volume{ + { + Name: "pvc", VolumeSource: v1.VolumeSource{ + PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: "foo"}, + }, + }, + } + }), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, ignorePvcPods: true, @@ -236,7 +236,17 @@ func TestPodLifeTime(t *testing.T) { args: &PodLifeTimeArgs{ MaxPodLifeTimeSeconds: &maxLifeTime, }, - pods: []*v1.Pod{p11}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) { + pod.Spec.Volumes = []v1.Volume{ + { + Name: "pvc", VolumeSource: v1.VolumeSource{ + PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: "foo"}, + }, + }, + } + }), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, From 70a71f54bc1277b07507ea6c9fa70a5498d93c37 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 16:04:03 +0100 Subject: [PATCH 12/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 3e7434e81..df0cd182d 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -71,9 +71,6 @@ func TestPodLifeTime(t *testing.T) { } // Setup two old pods with different labels - p12 := buildTestPodWithRSOwnerRefForNode1("p12", olderPodCreationTime, func(pod *v1.Pod) { - pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} - }) p13 := buildTestPodWithRSOwnerRefForNode1("p13", olderPodCreationTime, func(pod *v1.Pod) { pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} }) @@ -258,7 +255,12 @@ func TestPodLifeTime(t *testing.T) { MatchLabels: map[string]string{"foo": "bar"}, }, }, - pods: []*v1.Pod{p12, p13}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p12", olderPodCreationTime, func(pod *v1.Pod) { + pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} + }), + p13, + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, From 1d7368b58da6d7303a895a190cbb619557df344c Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 16:04:32 +0100 Subject: [PATCH 13/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index df0cd182d..b43ce56c1 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -70,11 +70,6 @@ func TestPodLifeTime(t *testing.T) { }) } - // Setup two old pods with different labels - p13 := buildTestPodWithRSOwnerRefForNode1("p13", olderPodCreationTime, func(pod *v1.Pod) { - pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} - }) - p14 := buildTestPodWithRSOwnerRefForNode1("p14", olderPodCreationTime, func(pod *v1.Pod) { pod.DeletionTimestamp = &metav1.Time{} }) @@ -259,7 +254,9 @@ func TestPodLifeTime(t *testing.T) { buildTestPodWithRSOwnerRefForNode1("p12", olderPodCreationTime, func(pod *v1.Pod) { pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} }), - p13, + buildTestPodWithRSOwnerRefForNode1("p13", olderPodCreationTime, func(pod *v1.Pod) { + pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} + }), }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, From 822a1d4c4034e77ea77bdde5cdcfcfd40c9659b2 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 16:05:01 +0100 Subject: [PATCH 14/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index b43ce56c1..65d70f811 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -70,9 +70,6 @@ func TestPodLifeTime(t *testing.T) { }) } - p14 := buildTestPodWithRSOwnerRefForNode1("p14", olderPodCreationTime, func(pod *v1.Pod) { - pod.DeletionTimestamp = &metav1.Time{} - }) p15 := buildTestPodWithRSOwnerRefForNode1("p15", olderPodCreationTime, func(pod *v1.Pod) { pod.DeletionTimestamp = &metav1.Time{} }) @@ -269,7 +266,12 @@ func TestPodLifeTime(t *testing.T) { MatchLabels: map[string]string{"foo": "bar"}, }, }, - pods: []*v1.Pod{p14, p15}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p14", olderPodCreationTime, func(pod *v1.Pod) { + pod.DeletionTimestamp = &metav1.Time{} + }), + p15, + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, }, From cab310e55c7cac53d20f052c69b6902cd043506a Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 16:05:30 +0100 Subject: [PATCH 15/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- pkg/framework/plugins/podlifetime/pod_lifetime_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 65d70f811..c13ec4cfe 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -70,10 +70,6 @@ func TestPodLifeTime(t *testing.T) { }) } - p15 := buildTestPodWithRSOwnerRefForNode1("p15", olderPodCreationTime, func(pod *v1.Pod) { - pod.DeletionTimestamp = &metav1.Time{} - }) - p16 := buildTestPodWithRSOwnerRefForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { pod.Status.Phase = v1.PodUnknown }) @@ -270,7 +266,9 @@ func TestPodLifeTime(t *testing.T) { buildTestPodWithRSOwnerRefForNode1("p14", olderPodCreationTime, func(pod *v1.Pod) { pod.DeletionTimestamp = &metav1.Time{} }), - p15, + buildTestPodWithRSOwnerRefForNode1("p15", olderPodCreationTime, func(pod *v1.Pod) { + pod.DeletionTimestamp = &metav1.Time{} + }), }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, From 07dc0c61c5656d130cf869ba137cbca2783fb0f6 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 16:06:01 +0100 Subject: [PATCH 16/16] refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates --- .../plugins/podlifetime/pod_lifetime_test.go | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index c13ec4cfe..20e75ab2e 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -70,10 +70,6 @@ func TestPodLifeTime(t *testing.T) { }) } - p16 := buildTestPodWithRSOwnerRefForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { - pod.Status.Phase = v1.PodUnknown - }) - var maxLifeTime uint = 600 testCases := []struct { description string @@ -609,7 +605,11 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{string(v1.PodSucceeded)}, }, - pods: []*v1.Pod{p16}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { + pod.Status.Phase = v1.PodUnknown + }), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -622,7 +622,11 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{string(v1.PodFailed)}, }, - pods: []*v1.Pod{p16}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { + pod.Status.Phase = v1.PodUnknown + }), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { @@ -635,7 +639,11 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, States: []string{string(v1.PodUnknown)}, }, - pods: []*v1.Pod{p16}, + pods: []*v1.Pod{ + buildTestPodWithRSOwnerRefForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { + pod.Status.Phase = v1.PodUnknown + }), + }, nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) {