From 3a3e72e9c25ef7dbb6417ac97f9b788266c1b46a Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 14:21:42 +0100 Subject: [PATCH 1/6] refactor(TestPodLifeTime): consolidate all owner references test.GetReplicaSetOwnerRefList produces the same value everything it's invoked. --- .../plugins/podlifetime/pod_lifetime_test.go | 38 +++++++++---------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 930918f5a..d47971491 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -39,46 +39,42 @@ func TestPodLifeTime(t *testing.T) { olderPodCreationTime := metav1.NewTime(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) newerPodCreationTime := metav1.NewTime(time.Now()) - ownerRef1 := test.GetReplicaSetOwnerRefList() + ownerRef := test.GetReplicaSetOwnerRefList() // Setup pods, one should be evicted p1 := test.BuildTestPod("p1", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) p2 := test.BuildTestPod("p2", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) - ownerRef2 := test.GetReplicaSetOwnerRefList() - // Setup pods, zero should be evicted p3 := test.BuildTestPod("p3", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef2 + pod.ObjectMeta.OwnerReferences = ownerRef }) p4 := test.BuildTestPod("p4", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef2 + pod.ObjectMeta.OwnerReferences = ownerRef }) - ownerRef3 := test.GetReplicaSetOwnerRefList() - // Setup pods, one should be evicted p5 := test.BuildTestPod("p5", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef3 + pod.ObjectMeta.OwnerReferences = ownerRef }) p6 := test.BuildTestPod("p6", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = metav1.NewTime(time.Now().Add(-time.Second * 605)) - pod.ObjectMeta.OwnerReferences = ownerRef3 + pod.ObjectMeta.OwnerReferences = ownerRef }) // Setup pods, zero should be evicted @@ -96,13 +92,13 @@ func TestPodLifeTime(t *testing.T) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = "Pending" - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) p10 := test.BuildTestPod("p10", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = "Running" - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) p11 := test.BuildTestPod("p11", 100, 0, node1.Name, func(pod *v1.Pod) { @@ -115,7 +111,7 @@ func TestPodLifeTime(t *testing.T) { } pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) // Setup two old pods with different labels @@ -123,25 +119,25 @@ func TestPodLifeTime(t *testing.T) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) p13 := test.BuildTestPod("p13", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) p14 := test.BuildTestPod("p14", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef pod.DeletionTimestamp = &metav1.Time{} }) p15 := test.BuildTestPod("p15", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef pod.DeletionTimestamp = &metav1.Time{} }) @@ -149,7 +145,7 @@ func TestPodLifeTime(t *testing.T) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = v1.PodUnknown - pod.ObjectMeta.OwnerReferences = ownerRef1 + pod.ObjectMeta.OwnerReferences = ownerRef }) var maxLifeTime uint = 600 @@ -217,7 +213,7 @@ func TestPodLifeTime(t *testing.T) { }, }, } - pod.OwnerReferences = ownerRef1 + pod.OwnerReferences = ownerRef pod.ObjectMeta.CreationTimestamp = olderPodCreationTime }), }, @@ -240,7 +236,7 @@ func TestPodLifeTime(t *testing.T) { }, }, } - pod.OwnerReferences = ownerRef1 + pod.OwnerReferences = ownerRef pod.ObjectMeta.CreationTimestamp = olderPodCreationTime }), }, From bbc3eef1c9f62998e50ea9a74daab3fe13a1c2f2 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 14:25:47 +0100 Subject: [PATCH 2/6] refactor(TestPodLifeTime): replace test.GetReplicaSetOwnerRefList with test.SetRSOwnerRef To make the assigment shorter and unified --- .../plugins/podlifetime/pod_lifetime_test.go | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index d47971491..1c94a619f 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -39,42 +39,40 @@ func TestPodLifeTime(t *testing.T) { olderPodCreationTime := metav1.NewTime(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) newerPodCreationTime := metav1.NewTime(time.Now()) - ownerRef := test.GetReplicaSetOwnerRefList() - // Setup pods, one should be evicted p1 := test.BuildTestPod("p1", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p2 := test.BuildTestPod("p2", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) // Setup pods, zero should be evicted p3 := test.BuildTestPod("p3", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p4 := test.BuildTestPod("p4", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) // Setup pods, one should be evicted p5 := test.BuildTestPod("p5", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p6 := test.BuildTestPod("p6", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = metav1.NewTime(time.Now().Add(-time.Second * 605)) - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) // Setup pods, zero should be evicted @@ -92,13 +90,13 @@ func TestPodLifeTime(t *testing.T) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = "Pending" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p10 := test.BuildTestPod("p10", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = "Running" - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p11 := test.BuildTestPod("p11", 100, 0, node1.Name, func(pod *v1.Pod) { @@ -111,7 +109,7 @@ func TestPodLifeTime(t *testing.T) { } pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) // Setup two old pods with different labels @@ -119,25 +117,25 @@ func TestPodLifeTime(t *testing.T) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p13 := test.BuildTestPod("p13", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) p14 := test.BuildTestPod("p14", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) pod.DeletionTimestamp = &metav1.Time{} }) p15 := test.BuildTestPod("p15", 100, 0, node1.Name, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) pod.DeletionTimestamp = &metav1.Time{} }) @@ -145,7 +143,7 @@ func TestPodLifeTime(t *testing.T) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = v1.PodUnknown - pod.ObjectMeta.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) }) var maxLifeTime uint = 600 @@ -213,7 +211,7 @@ func TestPodLifeTime(t *testing.T) { }, }, } - pod.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) pod.ObjectMeta.CreationTimestamp = olderPodCreationTime }), }, @@ -236,7 +234,7 @@ func TestPodLifeTime(t *testing.T) { }, }, } - pod.OwnerReferences = ownerRef + test.SetRSOwnerRef(pod) pod.ObjectMeta.CreationTimestamp = olderPodCreationTime }), }, From 94a0fbdcbbf3b26a164cffe8cf2ee07279e3b1c3 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 14:39:04 +0100 Subject: [PATCH 3/6] refactor(TestPodLifeTime): inline node creation in each unit test to avoid accidental node spec updates --- .../plugins/podlifetime/pod_lifetime_test.go | 108 +++++++++--------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 1c94a619f..cf95dbcfc 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -35,71 +35,75 @@ import ( ) func TestPodLifeTime(t *testing.T) { - node1 := test.BuildTestNode("n1", 2000, 3000, 10, nil) + const nodeName1 = "n1" + buildTestNode1 := func() *v1.Node { + return test.BuildTestNode(nodeName1, 2000, 3000, 10, nil) + } + olderPodCreationTime := metav1.NewTime(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) newerPodCreationTime := metav1.NewTime(time.Now()) // Setup pods, one should be evicted - p1 := test.BuildTestPod("p1", 100, 0, node1.Name, func(pod *v1.Pod) { + p1 := test.BuildTestPod("p1", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime test.SetRSOwnerRef(pod) }) - p2 := test.BuildTestPod("p2", 100, 0, node1.Name, func(pod *v1.Pod) { + p2 := test.BuildTestPod("p2", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime test.SetRSOwnerRef(pod) }) // Setup pods, zero should be evicted - p3 := test.BuildTestPod("p3", 100, 0, node1.Name, func(pod *v1.Pod) { + p3 := test.BuildTestPod("p3", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime test.SetRSOwnerRef(pod) }) - p4 := test.BuildTestPod("p4", 100, 0, node1.Name, func(pod *v1.Pod) { + p4 := test.BuildTestPod("p4", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime test.SetRSOwnerRef(pod) }) // Setup pods, one should be evicted - p5 := test.BuildTestPod("p5", 100, 0, node1.Name, func(pod *v1.Pod) { + p5 := test.BuildTestPod("p5", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime test.SetRSOwnerRef(pod) }) - p6 := test.BuildTestPod("p6", 100, 0, node1.Name, func(pod *v1.Pod) { + p6 := test.BuildTestPod("p6", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = metav1.NewTime(time.Now().Add(-time.Second * 605)) test.SetRSOwnerRef(pod) }) // Setup pods, zero should be evicted - p7 := test.BuildTestPod("p7", 100, 0, node1.Name, func(pod *v1.Pod) { + p7 := test.BuildTestPod("p7", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime }) - p8 := test.BuildTestPod("p8", 100, 0, node1.Name, func(pod *v1.Pod) { + p8 := test.BuildTestPod("p8", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = metav1.NewTime(time.Now().Add(-time.Second * 595)) }) // Setup two old pods with different status phases - p9 := test.BuildTestPod("p9", 100, 0, node1.Name, func(pod *v1.Pod) { + p9 := test.BuildTestPod("p9", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = "Pending" test.SetRSOwnerRef(pod) }) - p10 := test.BuildTestPod("p10", 100, 0, node1.Name, func(pod *v1.Pod) { + p10 := test.BuildTestPod("p10", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = "Running" test.SetRSOwnerRef(pod) }) - p11 := test.BuildTestPod("p11", 100, 0, node1.Name, func(pod *v1.Pod) { + p11 := test.BuildTestPod("p11", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Spec.Volumes = []v1.Volume{ { Name: "pvc", VolumeSource: v1.VolumeSource{ @@ -113,33 +117,33 @@ func TestPodLifeTime(t *testing.T) { }) // Setup two old pods with different labels - p12 := test.BuildTestPod("p12", 100, 0, node1.Name, func(pod *v1.Pod) { + p12 := test.BuildTestPod("p12", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} test.SetRSOwnerRef(pod) }) - p13 := test.BuildTestPod("p13", 100, 0, node1.Name, func(pod *v1.Pod) { + p13 := test.BuildTestPod("p13", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} test.SetRSOwnerRef(pod) }) - p14 := test.BuildTestPod("p14", 100, 0, node1.Name, func(pod *v1.Pod) { + p14 := test.BuildTestPod("p14", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime test.SetRSOwnerRef(pod) pod.DeletionTimestamp = &metav1.Time{} }) - p15 := test.BuildTestPod("p15", 100, 0, node1.Name, func(pod *v1.Pod) { + p15 := test.BuildTestPod("p15", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime test.SetRSOwnerRef(pod) pod.DeletionTimestamp = &metav1.Time{} }) - p16 := test.BuildTestPod("p16", 100, 0, node1.Name, func(pod *v1.Pod) { + p16 := test.BuildTestPod("p16", 100, 0, nodeName1, func(pod *v1.Pod) { pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = v1.PodUnknown @@ -165,7 +169,7 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, }, pods: []*v1.Pod{p1, p2}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, { @@ -174,7 +178,7 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, }, pods: []*v1.Pod{p3, p4}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, }, { @@ -183,7 +187,7 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, }, pods: []*v1.Pod{p5, p6}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, { @@ -192,7 +196,7 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, }, pods: []*v1.Pod{p7, p8}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, }, { @@ -203,7 +207,7 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ p9, - test.BuildTestPod("container-creating-stuck", 0, 0, node1.Name, func(pod *v1.Pod) { + test.BuildTestPod("container-creating-stuck", 0, 0, nodeName1, func(pod *v1.Pod) { pod.Status.ContainerStatuses = []v1.ContainerStatus{ { State: v1.ContainerState{ @@ -215,7 +219,7 @@ func TestPodLifeTime(t *testing.T) { pod.ObjectMeta.CreationTimestamp = olderPodCreationTime }), }, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, { @@ -226,7 +230,7 @@ func TestPodLifeTime(t *testing.T) { }, pods: []*v1.Pod{ p9, - test.BuildTestPod("pod-initializing-stuck", 0, 0, node1.Name, func(pod *v1.Pod) { + test.BuildTestPod("pod-initializing-stuck", 0, 0, nodeName1, func(pod *v1.Pod) { pod.Status.ContainerStatuses = []v1.ContainerStatus{ { State: v1.ContainerState{ @@ -238,7 +242,7 @@ func TestPodLifeTime(t *testing.T) { pod.ObjectMeta.CreationTimestamp = olderPodCreationTime }), }, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, { @@ -248,7 +252,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"Pending"}, }, pods: []*v1.Pod{p9, p10}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, { @@ -257,7 +261,7 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, }, pods: []*v1.Pod{p11}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, ignorePvcPods: true, }, @@ -267,7 +271,7 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, }, pods: []*v1.Pod{p11}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, { @@ -279,7 +283,7 @@ func TestPodLifeTime(t *testing.T) { }, }, pods: []*v1.Pod{p12, p13}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, }, { @@ -291,7 +295,7 @@ func TestPodLifeTime(t *testing.T) { }, }, pods: []*v1.Pod{p14, p15}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, }, { @@ -300,7 +304,7 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, }, pods: []*v1.Pod{p1, p2, p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 2, maxPodsToEvictPerNode: nil, maxPodsToEvictPerNamespace: nil, @@ -311,7 +315,7 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, }, pods: []*v1.Pod{p1, p2, p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNamespace: utilptr.To[uint](1), expectedEvictedPodCount: 1, }, @@ -321,7 +325,7 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, }, pods: []*v1.Pod{p1, p2, p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNamespace: utilptr.To[uint](2), maxPodsToEvictTotal: utilptr.To[uint](1), expectedEvictedPodCount: 1, @@ -332,7 +336,7 @@ func TestPodLifeTime(t *testing.T) { MaxPodLifeTimeSeconds: &maxLifeTime, }, pods: []*v1.Pod{p1, p2, p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, maxPodsToEvictPerNode: utilptr.To[uint](1), expectedEvictedPodCount: 1, }, @@ -343,7 +347,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"ImagePullBackOff"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.ContainerStatuses = []v1.ContainerStatus{ @@ -362,7 +366,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"CrashLoopBackOff"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.ContainerStatuses = []v1.ContainerStatus{ @@ -381,7 +385,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"CreateContainerConfigError"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.ContainerStatuses = []v1.ContainerStatus{ @@ -400,7 +404,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"ErrImagePull"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.ContainerStatuses = []v1.ContainerStatus{ @@ -419,7 +423,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"CreateContainerError"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.InitContainerStatuses = []v1.ContainerStatus{ @@ -439,7 +443,7 @@ func TestPodLifeTime(t *testing.T) { IncludingInitContainers: true, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.InitContainerStatuses = []v1.ContainerStatus{ @@ -458,7 +462,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"CreateContainerError"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.InitContainerStatuses = []v1.ContainerStatus{ @@ -478,7 +482,7 @@ func TestPodLifeTime(t *testing.T) { IncludingEphemeralContainers: true, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.EphemeralContainerStatuses = []v1.ContainerStatus{ @@ -497,7 +501,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"CreateContainerError"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.ContainerStatuses = []v1.ContainerStatus{ @@ -516,7 +520,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"InvalidImageName"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.ContainerStatuses = []v1.ContainerStatus{ @@ -535,7 +539,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"NodeLost"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.Reason = "NodeLost" @@ -548,7 +552,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"NodeAffinity"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.Reason = "NodeAffinity" @@ -561,7 +565,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"Shutdown"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.Reason = "Shutdown" @@ -574,7 +578,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"UnexpectedAdmissionError"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.Reason = "UnexpectedAdmissionError" @@ -587,7 +591,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{string(v1.PodSucceeded)}, }, pods: []*v1.Pod{p16}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.Phase = v1.PodSucceeded @@ -600,7 +604,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{string(v1.PodFailed)}, }, pods: []*v1.Pod{p16}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.Phase = v1.PodFailed @@ -613,7 +617,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{string(v1.PodUnknown)}, }, pods: []*v1.Pod{p16}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 1, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.Phase = v1.PodUnknown @@ -626,7 +630,7 @@ func TestPodLifeTime(t *testing.T) { States: []string{"ContainerCreating"}, }, pods: []*v1.Pod{p9}, - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{buildTestNode1()}, expectedEvictedPodCount: 0, applyPodsFunc: func(pods []*v1.Pod) { pods[0].Status.ContainerStatuses = []v1.ContainerStatus{ From 5b4719634c4563a1ca877982ac5b94de4460afe6 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:02:26 +0100 Subject: [PATCH 4/6] refactor(TestPodLifeTime): the default pod namespace will work the same way as the 'dev' one --- .../plugins/podlifetime/pod_lifetime_test.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index cf95dbcfc..e0c592376 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -45,59 +45,49 @@ func TestPodLifeTime(t *testing.T) { // Setup pods, one should be evicted p1 := test.BuildTestPod("p1", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime test.SetRSOwnerRef(pod) }) p2 := test.BuildTestPod("p2", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime test.SetRSOwnerRef(pod) }) // Setup pods, zero should be evicted p3 := test.BuildTestPod("p3", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime test.SetRSOwnerRef(pod) }) p4 := test.BuildTestPod("p4", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime test.SetRSOwnerRef(pod) }) // Setup pods, one should be evicted p5 := test.BuildTestPod("p5", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime test.SetRSOwnerRef(pod) }) p6 := test.BuildTestPod("p6", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = metav1.NewTime(time.Now().Add(-time.Second * 605)) test.SetRSOwnerRef(pod) }) // Setup pods, zero should be evicted p7 := test.BuildTestPod("p7", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = newerPodCreationTime }) p8 := test.BuildTestPod("p8", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = metav1.NewTime(time.Now().Add(-time.Second * 595)) }) // Setup two old pods with different status phases p9 := test.BuildTestPod("p9", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = "Pending" test.SetRSOwnerRef(pod) }) p10 := test.BuildTestPod("p10", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = "Running" test.SetRSOwnerRef(pod) @@ -111,40 +101,34 @@ func TestPodLifeTime(t *testing.T) { }, }, } - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime test.SetRSOwnerRef(pod) }) // Setup two old pods with different labels p12 := test.BuildTestPod("p12", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} test.SetRSOwnerRef(pod) }) p13 := test.BuildTestPod("p13", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} test.SetRSOwnerRef(pod) }) p14 := test.BuildTestPod("p14", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime test.SetRSOwnerRef(pod) pod.DeletionTimestamp = &metav1.Time{} }) p15 := test.BuildTestPod("p15", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime test.SetRSOwnerRef(pod) pod.DeletionTimestamp = &metav1.Time{} }) p16 := test.BuildTestPod("p16", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.Namespace = "dev" pod.ObjectMeta.CreationTimestamp = olderPodCreationTime pod.Status.Phase = v1.PodUnknown test.SetRSOwnerRef(pod) From 7d84b68556fb40d4926edaf1abe4cb25a9e7b5b3 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:28:05 +0100 Subject: [PATCH 5/6] refactor(TestPodLifeTime): consolidate defaults when building a test pod --- .../plugins/podlifetime/pod_lifetime_test.go | 59 ++++++++----------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index e0c592376..290870908 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -43,57 +43,54 @@ func TestPodLifeTime(t *testing.T) { olderPodCreationTime := metav1.NewTime(time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC)) newerPodCreationTime := metav1.NewTime(time.Now()) + buildTestPodForNode1 := func(name string, creationTime metav1.Time, apply func(*v1.Pod)) *v1.Pod { + return test.BuildTestPod(name, 100, 0, nodeName1, func(pod *v1.Pod) { + pod.ObjectMeta.CreationTimestamp = creationTime + if apply != nil { + apply(pod) + } + }) + } + // Setup pods, one should be evicted - p1 := test.BuildTestPod("p1", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = newerPodCreationTime + p1 := buildTestPodForNode1("p1", newerPodCreationTime, func(pod *v1.Pod) { test.SetRSOwnerRef(pod) }) - p2 := test.BuildTestPod("p2", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = olderPodCreationTime + p2 := buildTestPodForNode1("p2", olderPodCreationTime, func(pod *v1.Pod) { test.SetRSOwnerRef(pod) }) // Setup pods, zero should be evicted - p3 := test.BuildTestPod("p3", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = newerPodCreationTime + p3 := buildTestPodForNode1("p3", newerPodCreationTime, func(pod *v1.Pod) { test.SetRSOwnerRef(pod) }) - p4 := test.BuildTestPod("p4", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = newerPodCreationTime + p4 := buildTestPodForNode1("p4", newerPodCreationTime, func(pod *v1.Pod) { test.SetRSOwnerRef(pod) }) // Setup pods, one should be evicted - p5 := test.BuildTestPod("p5", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = newerPodCreationTime + p5 := buildTestPodForNode1("p5", newerPodCreationTime, func(pod *v1.Pod) { test.SetRSOwnerRef(pod) }) - p6 := test.BuildTestPod("p6", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = metav1.NewTime(time.Now().Add(-time.Second * 605)) + p6 := buildTestPodForNode1("p6", metav1.NewTime(time.Now().Add(-time.Second*605)), func(pod *v1.Pod) { test.SetRSOwnerRef(pod) }) // Setup pods, zero should be evicted - p7 := test.BuildTestPod("p7", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = newerPodCreationTime - }) - p8 := test.BuildTestPod("p8", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = metav1.NewTime(time.Now().Add(-time.Second * 595)) - }) + 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 - p9 := test.BuildTestPod("p9", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = olderPodCreationTime + p9 := buildTestPodForNode1("p9", olderPodCreationTime, func(pod *v1.Pod) { pod.Status.Phase = "Pending" test.SetRSOwnerRef(pod) }) - p10 := test.BuildTestPod("p10", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = olderPodCreationTime + p10 := buildTestPodForNode1("p10", olderPodCreationTime, func(pod *v1.Pod) { pod.Status.Phase = "Running" test.SetRSOwnerRef(pod) }) - p11 := test.BuildTestPod("p11", 100, 0, nodeName1, func(pod *v1.Pod) { + p11 := buildTestPodForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) { pod.Spec.Volumes = []v1.Volume{ { Name: "pvc", VolumeSource: v1.VolumeSource{ @@ -101,35 +98,29 @@ func TestPodLifeTime(t *testing.T) { }, }, } - pod.ObjectMeta.CreationTimestamp = olderPodCreationTime test.SetRSOwnerRef(pod) }) // Setup two old pods with different labels - p12 := test.BuildTestPod("p12", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = olderPodCreationTime + p12 := buildTestPodForNode1("p12", olderPodCreationTime, func(pod *v1.Pod) { pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} test.SetRSOwnerRef(pod) }) - p13 := test.BuildTestPod("p13", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = olderPodCreationTime + p13 := buildTestPodForNode1("p13", olderPodCreationTime, func(pod *v1.Pod) { pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} test.SetRSOwnerRef(pod) }) - p14 := test.BuildTestPod("p14", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = olderPodCreationTime + p14 := buildTestPodForNode1("p14", olderPodCreationTime, func(pod *v1.Pod) { test.SetRSOwnerRef(pod) pod.DeletionTimestamp = &metav1.Time{} }) - p15 := test.BuildTestPod("p15", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = olderPodCreationTime + p15 := buildTestPodForNode1("p15", olderPodCreationTime, func(pod *v1.Pod) { test.SetRSOwnerRef(pod) pod.DeletionTimestamp = &metav1.Time{} }) - p16 := test.BuildTestPod("p16", 100, 0, nodeName1, func(pod *v1.Pod) { - pod.ObjectMeta.CreationTimestamp = olderPodCreationTime + p16 := buildTestPodForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { pod.Status.Phase = v1.PodUnknown test.SetRSOwnerRef(pod) }) From 4f42a7ae9b8bafe2378ad93a21ca60df1d04e497 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 15:34:48 +0100 Subject: [PATCH 6/6] refactor(TestPodLifeTime): consolidate defaults when building a test pod with RS owner reference --- .../plugins/podlifetime/pod_lifetime_test.go | 57 ++++++++----------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go index 290870908..c0b117dd5 100644 --- a/pkg/framework/plugins/podlifetime/pod_lifetime_test.go +++ b/pkg/framework/plugins/podlifetime/pod_lifetime_test.go @@ -52,45 +52,40 @@ func TestPodLifeTime(t *testing.T) { }) } + buildTestPodWithRSOwnerRefForNode1 := func(name string, creationTime metav1.Time, apply func(*v1.Pod)) *v1.Pod { + return buildTestPodForNode1(name, creationTime, func(pod *v1.Pod) { + test.SetRSOwnerRef(pod) + if apply != nil { + apply(pod) + } + }) + } + // Setup pods, one should be evicted - p1 := buildTestPodForNode1("p1", newerPodCreationTime, func(pod *v1.Pod) { - test.SetRSOwnerRef(pod) - }) - p2 := buildTestPodForNode1("p2", olderPodCreationTime, func(pod *v1.Pod) { - test.SetRSOwnerRef(pod) - }) + p1 := buildTestPodWithRSOwnerRefForNode1("p1", newerPodCreationTime, nil) + p2 := buildTestPodWithRSOwnerRefForNode1("p2", olderPodCreationTime, nil) // Setup pods, zero should be evicted - p3 := buildTestPodForNode1("p3", newerPodCreationTime, func(pod *v1.Pod) { - test.SetRSOwnerRef(pod) - }) - p4 := buildTestPodForNode1("p4", newerPodCreationTime, func(pod *v1.Pod) { - test.SetRSOwnerRef(pod) - }) + p3 := buildTestPodWithRSOwnerRefForNode1("p3", newerPodCreationTime, nil) + p4 := buildTestPodWithRSOwnerRefForNode1("p4", newerPodCreationTime, nil) // Setup pods, one should be evicted - p5 := buildTestPodForNode1("p5", newerPodCreationTime, func(pod *v1.Pod) { - test.SetRSOwnerRef(pod) - }) - p6 := buildTestPodForNode1("p6", metav1.NewTime(time.Now().Add(-time.Second*605)), func(pod *v1.Pod) { - test.SetRSOwnerRef(pod) - }) + p5 := buildTestPodWithRSOwnerRefForNode1("p5", newerPodCreationTime, nil) + 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) // Setup two old pods with different status phases - p9 := buildTestPodForNode1("p9", olderPodCreationTime, func(pod *v1.Pod) { + p9 := buildTestPodWithRSOwnerRefForNode1("p9", olderPodCreationTime, func(pod *v1.Pod) { pod.Status.Phase = "Pending" - test.SetRSOwnerRef(pod) }) - p10 := buildTestPodForNode1("p10", olderPodCreationTime, func(pod *v1.Pod) { + p10 := buildTestPodWithRSOwnerRefForNode1("p10", olderPodCreationTime, func(pod *v1.Pod) { pod.Status.Phase = "Running" - test.SetRSOwnerRef(pod) }) - p11 := buildTestPodForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) { + p11 := buildTestPodWithRSOwnerRefForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) { pod.Spec.Volumes = []v1.Volume{ { Name: "pvc", VolumeSource: v1.VolumeSource{ @@ -98,31 +93,25 @@ func TestPodLifeTime(t *testing.T) { }, }, } - test.SetRSOwnerRef(pod) }) // Setup two old pods with different labels - p12 := buildTestPodForNode1("p12", olderPodCreationTime, func(pod *v1.Pod) { + p12 := buildTestPodWithRSOwnerRefForNode1("p12", olderPodCreationTime, func(pod *v1.Pod) { pod.ObjectMeta.Labels = map[string]string{"foo": "bar"} - test.SetRSOwnerRef(pod) }) - p13 := buildTestPodForNode1("p13", olderPodCreationTime, func(pod *v1.Pod) { + p13 := buildTestPodWithRSOwnerRefForNode1("p13", olderPodCreationTime, func(pod *v1.Pod) { pod.ObjectMeta.Labels = map[string]string{"foo": "bar1"} - test.SetRSOwnerRef(pod) }) - p14 := buildTestPodForNode1("p14", olderPodCreationTime, func(pod *v1.Pod) { - test.SetRSOwnerRef(pod) + p14 := buildTestPodWithRSOwnerRefForNode1("p14", olderPodCreationTime, func(pod *v1.Pod) { pod.DeletionTimestamp = &metav1.Time{} }) - p15 := buildTestPodForNode1("p15", olderPodCreationTime, func(pod *v1.Pod) { - test.SetRSOwnerRef(pod) + p15 := buildTestPodWithRSOwnerRefForNode1("p15", olderPodCreationTime, func(pod *v1.Pod) { pod.DeletionTimestamp = &metav1.Time{} }) - p16 := buildTestPodForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { + p16 := buildTestPodWithRSOwnerRefForNode1("p16", olderPodCreationTime, func(pod *v1.Pod) { pod.Status.Phase = v1.PodUnknown - test.SetRSOwnerRef(pod) }) var maxLifeTime uint = 600