From 3a3e72e9c25ef7dbb6417ac97f9b788266c1b46a Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Wed, 10 Dec 2025 14:21:42 +0100 Subject: [PATCH] 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 }), },