From 6ebb0b7aa734c63b84a718a4dd021a7e3d88701b Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 00:23:03 +0100 Subject: [PATCH 01/14] refactor(TestRemovePodsHavingTooManyRestarts): extract setPodContainerStatusRestartCount helper --- .../toomanyrestarts_test.go | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 20bcbdaaa..25fb2e3f4 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -33,6 +33,24 @@ import ( "sigs.k8s.io/descheduler/test" ) +func setPodContainerStatusRestartCount(pod *v1.Pod, base int32) { + pod.Status = v1.PodStatus{ + InitContainerStatuses: []v1.ContainerStatus{ + { + RestartCount: 5 * base, + }, + }, + ContainerStatuses: []v1.ContainerStatus{ + { + RestartCount: 10 * base, + }, + { + RestartCount: 10 * base, + }, + }, + } +} + func initPods(node *v1.Node) []*v1.Pod { pods := make([]*v1.Pod, 0) @@ -41,21 +59,7 @@ func initPods(node *v1.Node) []*v1.Pod { pod.ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList() // pod at index i will have 25 * i restarts. - pod.Status = v1.PodStatus{ - InitContainerStatuses: []v1.ContainerStatus{ - { - RestartCount: 5 * i, - }, - }, - ContainerStatuses: []v1.ContainerStatus{ - { - RestartCount: 10 * i, - }, - { - RestartCount: 10 * i, - }, - }, - } + setPodContainerStatusRestartCount(pod, i) pods = append(pods, pod) } From bf9cf0ee1c9419a739af822f2039d052abe6e03f Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 11:03:45 +0100 Subject: [PATCH 02/14] refactor(TestRemovePodsHavingTooManyRestarts): use test.Set...OwnerRef instead --- .../toomanyrestarts_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 25fb2e3f4..066c4fb3e 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -55,19 +55,19 @@ func initPods(node *v1.Node) []*v1.Pod { pods := make([]*v1.Pod, 0) for i := int32(0); i <= 9; i++ { - pod := test.BuildTestPod(fmt.Sprintf("pod-%d", i), 100, 0, node.Name, nil) - pod.ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList() - - // pod at index i will have 25 * i restarts. - setPodContainerStatusRestartCount(pod, i) + pod := test.BuildTestPod(fmt.Sprintf("pod-%d", i), 100, 0, node.Name, func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + // pod at index i will have 25 * i restarts, 5 for init container, 20 for other two containers + setPodContainerStatusRestartCount(pod, i) + }) pods = append(pods, pod) } // The following 3 pods won't get evicted. // A daemonset. - pods[6].ObjectMeta.OwnerReferences = test.GetDaemonSetOwnerRefList() + test.SetDSOwnerRef(pods[6]) // A pod with local storage. - pods[7].ObjectMeta.OwnerReferences = test.GetNormalPodOwnerRefList() + test.SetNormalOwnerRef(pods[7]) pods[7].Spec.Volumes = []v1.Volume{ { Name: "sample", From ec58fed521e876d1c06f0cb7764f4e370c85e221 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 11:04:52 +0100 Subject: [PATCH 03/14] refactor(TestRemovePodsHavingTooManyRestarts): create each init container through a single invocation --- .../toomanyrestarts_test.go | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 066c4fb3e..92a4bf2c5 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -33,6 +33,10 @@ import ( "sigs.k8s.io/descheduler/test" ) +const ( + nodeName1 = "node1" +) + func setPodContainerStatusRestartCount(pod *v1.Pod, base int32) { pod.Status = v1.PodStatus{ InitContainerStatuses: []v1.ContainerStatus{ @@ -51,16 +55,22 @@ func setPodContainerStatusRestartCount(pod *v1.Pod, base int32) { } } +func initPodContainersWithStatusRestartCount(name string, base int32, apply func(pod *v1.Pod)) *v1.Pod { + return test.BuildTestPod(name, 100, 0, nodeName1, func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + // pod at index i will have 25 * i restarts, 5 for init container, 20 for other two containers + setPodContainerStatusRestartCount(pod, base) + if apply != nil { + apply(pod) + } + }) +} + func initPods(node *v1.Node) []*v1.Pod { pods := make([]*v1.Pod, 0) for i := int32(0); i <= 9; i++ { - pod := test.BuildTestPod(fmt.Sprintf("pod-%d", i), 100, 0, node.Name, func(pod *v1.Pod) { - test.SetNormalOwnerRef(pod) - // pod at index i will have 25 * i restarts, 5 for init container, 20 for other two containers - setPodContainerStatusRestartCount(pod, i) - }) - pods = append(pods, pod) + pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, nil)) } // The following 3 pods won't get evicted. @@ -86,7 +96,7 @@ func initPods(node *v1.Node) []*v1.Pod { } func TestRemovePodsHavingTooManyRestarts(t *testing.T) { - node1 := test.BuildTestNode("node1", 2000, 3000, 10, nil) + node1 := test.BuildTestNode(nodeName1, 2000, 3000, 10, nil) node2 := test.BuildTestNode("node2", 2000, 3000, 10, func(node *v1.Node) { node.Spec.Taints = []v1.Taint{ { From 8c70b0208879863cf99567570c79be3b6ac832ba Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 11:26:02 +0100 Subject: [PATCH 04/14] refactor(TestRemovePodsHavingTooManyRestarts): single testing pods creation --- .../toomanyrestarts_test.go | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 92a4bf2c5..553a4921a 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -70,28 +70,37 @@ func initPods(node *v1.Node) []*v1.Pod { pods := make([]*v1.Pod, 0) for i := int32(0); i <= 9; i++ { - pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, nil)) + switch i { + default: + pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, nil)) + // The following 3 pods won't get evicted. + // A daemonset. + case 6: + pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, test.SetDSOwnerRef)) + // A pod with local storage. + case 7: + pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, func(pod *v1.Pod) { + test.SetNormalOwnerRef(pod) + pod.Spec.Volumes = []v1.Volume{ + { + Name: "sample", + VolumeSource: v1.VolumeSource{ + HostPath: &v1.HostPathVolumeSource{Path: "somePath"}, + EmptyDir: &v1.EmptyDirVolumeSource{ + SizeLimit: resource.NewQuantity(int64(10), resource.BinarySI), + }, + }, + }, + } + })) + // A Mirror Pod. + case 8: + pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, func(pod *v1.Pod) { + pod.Annotations = test.GetMirrorPodAnnotation() + })) + } } - // The following 3 pods won't get evicted. - // A daemonset. - test.SetDSOwnerRef(pods[6]) - // A pod with local storage. - test.SetNormalOwnerRef(pods[7]) - pods[7].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. - pods[8].Annotations = test.GetMirrorPodAnnotation() - return pods } From a94d22fd1b09d4960eb9546c721d64978b3e5717 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 11:37:22 +0100 Subject: [PATCH 05/14] refactor(TestRemovePodsHavingTooManyRestarts): create all testing pods under initPods --- .../toomanyrestarts_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 553a4921a..8e85ebac7 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -35,6 +35,8 @@ import ( const ( nodeName1 = "node1" + nodeName4 = "node4" + nodeName5 = "node5" ) func setPodContainerStatusRestartCount(pod *v1.Pod, base int32) { @@ -101,6 +103,12 @@ func initPods(node *v1.Node) []*v1.Pod { } } + pods = append( + pods, + test.BuildTestPod("CPU-consumer-1", 150, 100, nodeName4, test.SetNormalOwnerRef), + test.BuildTestPod("CPU-consumer-2", 150, 100, nodeName5, test.SetNormalOwnerRef), + ) + return pods } @@ -120,8 +128,8 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { Unschedulable: true, } }) - node4 := test.BuildTestNode("node4", 200, 3000, 10, nil) - node5 := test.BuildTestNode("node5", 2000, 3000, 10, nil) + node4 := test.BuildTestNode(nodeName4, 200, 3000, 10, nil) + node5 := test.BuildTestNode(nodeName5, 2000, 3000, 10, nil) createRemovePodsHavingTooManyRestartsAgrs := func( podRestartThresholds int32, @@ -331,8 +339,6 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { t.Run(tc.description, func(t *testing.T) { pods := append( initPods(node1), - test.BuildTestPod("CPU-consumer-1", 150, 100, node4.Name, test.SetNormalOwnerRef), - test.BuildTestPod("CPU-consumer-2", 150, 100, node5.Name, test.SetNormalOwnerRef), ) if tc.applyFunc != nil { tc.applyFunc(pods) From 60fa5aa2282787ebf2a9a7573a90a76f62396da9 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 11:43:51 +0100 Subject: [PATCH 06/14] refactor(TestRemovePodsHavingTooManyRestarts): create all the pods as part of a unit test definition --- .../toomanyrestarts_test.go | 45 +++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 8e85ebac7..8d6319fa6 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -68,17 +68,22 @@ func initPodContainersWithStatusRestartCount(name string, base int32, apply func }) } -func initPods(node *v1.Node) []*v1.Pod { +func initPods(apply func(pod *v1.Pod)) []*v1.Pod { pods := make([]*v1.Pod, 0) for i := int32(0); i <= 9; i++ { switch i { default: - pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, nil)) + pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, apply)) // The following 3 pods won't get evicted. // A daemonset. case 6: - pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, test.SetDSOwnerRef)) + pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, func(pod *v1.Pod) { + test.SetDSOwnerRef(pod) + if apply != nil { + apply(pod) + } + })) // A pod with local storage. case 7: pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, func(pod *v1.Pod) { @@ -94,11 +99,17 @@ func initPods(node *v1.Node) []*v1.Pod { }, }, } + if apply != nil { + apply(pod) + } })) // A Mirror Pod. case 8: pods = append(pods, initPodContainersWithStatusRestartCount(fmt.Sprintf("pod-%d", i), i, func(pod *v1.Pod) { pod.Annotations = test.GetMirrorPodAnnotation() + if apply != nil { + apply(pod) + } })) } } @@ -145,6 +156,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { tests := []struct { description string + pods []*v1.Pod nodes []*v1.Node args RemovePodsHavingTooManyRestartsArgs expectedEvictedPodCount uint @@ -156,48 +168,56 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "All pods have total restarts under threshold, no pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(10000, true), + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 0, }, { description: "Some pods have total restarts bigger than threshold", args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 6, }, { description: "Nine pods have total restarts equals threshold(includingInitContainers=true), 6 pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(1*25, true), + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 6, }, { description: "Nine pods have total restarts equals threshold(includingInitContainers=false), 5 pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(1*25, false), + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 5, }, { description: "All pods have total restarts equals threshold(includingInitContainers=true), 6 pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(1*20, true), + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 6, }, { description: "Nine pods have total restarts equals threshold(includingInitContainers=false), 6 pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(1*20, false), + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 6, }, { description: "Five pods have total restarts bigger than threshold(includingInitContainers=true), but only 1 pod eviction", args: createRemovePodsHavingTooManyRestartsAgrs(5*25+1, true), + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 1, }, { description: "Five pods have total restarts bigger than threshold(includingInitContainers=false), but only 1 pod eviction", args: createRemovePodsHavingTooManyRestartsAgrs(5*20+1, false), + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 1, nodeFit: false, @@ -205,6 +225,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3), 3 pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, @@ -212,6 +233,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "All pods have total restarts equals threshold(maxNoOfPodsToEvictPerNamespace=3), 3 pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 3, maxNoOfPodsToEvictPerNamespace: &uint3, @@ -219,6 +241,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node is tainted, 0 pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), nodes: []*v1.Node{node1, node2}, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, @@ -227,6 +250,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node is not schedulable, 0 pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), nodes: []*v1.Node{node1, node3}, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, @@ -235,6 +259,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node does not have enough CPU, 0 pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), nodes: []*v1.Node{node1, node4}, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, @@ -243,6 +268,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node has enough CPU, 3 pod evictions", args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), nodes: []*v1.Node{node1, node5}, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, @@ -251,6 +277,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "pods are in CrashLoopBackOff with states=CrashLoopBackOff, 3 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}}, + pods: initPods(nil), nodes: []*v1.Node{node1, node5}, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, @@ -268,6 +295,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "pods without CrashLoopBackOff with states=CrashLoopBackOff, 0 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}}, + pods: initPods(nil), nodes: []*v1.Node{node1, node5}, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, @@ -276,6 +304,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "pods running with state=Running, 3 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{string(v1.PodRunning)}}, + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, @@ -288,6 +317,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "pods pending with state=Running, 0 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{string(v1.PodRunning)}}, + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, @@ -300,6 +330,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "pods pending with initContainer with states=CrashLoopBackOff threshold(includingInitContainers=true), 3 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}, IncludingInitContainers: true}, + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, @@ -318,6 +349,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "pods pending with initContainer with states=CrashLoopBackOff threshold(includingInitContainers=false), 0 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}, IncludingInitContainers: false}, + pods: initPods(nil), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, @@ -337,11 +369,8 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { for _, tc := range tests { t.Run(tc.description, func(t *testing.T) { - pods := append( - initPods(node1), - ) if tc.applyFunc != nil { - tc.applyFunc(pods) + tc.applyFunc(tc.pods) } ctx, cancel := context.WithCancel(context.Background()) @@ -351,7 +380,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { for _, node := range tc.nodes { objs = append(objs, node) } - for _, pod := range pods { + for _, pod := range tc.pods { objs = append(objs, pod) } fakeClient := fake.NewSimpleClientset(objs...) From 2af9ea844960e6c10f5457c498477b92a0426463 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 11:50:54 +0100 Subject: [PATCH 07/14] refactor(TestRemovePodsHavingTooManyRestarts): remove applyFunc and apply modifications in initPods --- .../toomanyrestarts_test.go | 82 +++++++------------ 1 file changed, 31 insertions(+), 51 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 8d6319fa6..fa51a6094 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -163,7 +163,6 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { maxPodsToEvictPerNode *uint maxNoOfPodsToEvictPerNamespace *uint nodeFit bool - applyFunc func([]*v1.Pod) }{ { description: "All pods have total restarts under threshold, no pod evictions", @@ -277,20 +276,17 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "pods are in CrashLoopBackOff with states=CrashLoopBackOff, 3 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}}, - pods: initPods(nil), + pods: initPods(func(pod *v1.Pod) { + if len(pod.Status.ContainerStatuses) > 0 { + pod.Status.ContainerStatuses[0].State = v1.ContainerState{ + Waiting: &v1.ContainerStateWaiting{Reason: "CrashLoopBackOff"}, + } + } + }), nodes: []*v1.Node{node1, node5}, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, nodeFit: true, - applyFunc: func(pods []*v1.Pod) { - for _, pod := range pods { - if len(pod.Status.ContainerStatuses) > 0 { - pod.Status.ContainerStatuses[0].State = v1.ContainerState{ - Waiting: &v1.ContainerStateWaiting{Reason: "CrashLoopBackOff"}, - } - } - } - }, }, { description: "pods without CrashLoopBackOff with states=CrashLoopBackOff, 0 pod evictions", @@ -304,75 +300,59 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { { description: "pods running with state=Running, 3 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{string(v1.PodRunning)}}, - pods: initPods(nil), + pods: initPods(func(pod *v1.Pod) { + pod.Status.Phase = v1.PodRunning + }), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, - applyFunc: func(pods []*v1.Pod) { - for _, pod := range pods { - pod.Status.Phase = v1.PodRunning - } - }, }, { description: "pods pending with state=Running, 0 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{string(v1.PodRunning)}}, - pods: initPods(nil), + pods: initPods(func(pod *v1.Pod) { + pod.Status.Phase = v1.PodPending + }), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, - applyFunc: func(pods []*v1.Pod) { - for _, pod := range pods { - pod.Status.Phase = v1.PodPending - } - }, }, { description: "pods pending with initContainer with states=CrashLoopBackOff threshold(includingInitContainers=true), 3 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}, IncludingInitContainers: true}, - pods: initPods(nil), + pods: initPods(func(pod *v1.Pod) { + pod.Status.InitContainerStatuses = []v1.ContainerStatus{ + { + State: v1.ContainerState{ + Waiting: &v1.ContainerStateWaiting{Reason: "CrashLoopBackOff"}, + }, + }, + } + }), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, - applyFunc: func(pods []*v1.Pod) { - for _, pod := range pods { - pod.Status.InitContainerStatuses = []v1.ContainerStatus{ - { - State: v1.ContainerState{ - Waiting: &v1.ContainerStateWaiting{Reason: "CrashLoopBackOff"}, - }, - }, - } - } - }, }, { description: "pods pending with initContainer with states=CrashLoopBackOff threshold(includingInitContainers=false), 0 pod evictions", args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}, IncludingInitContainers: false}, - pods: initPods(nil), + pods: initPods(func(pod *v1.Pod) { + pod.Status.InitContainerStatuses = []v1.ContainerStatus{ + { + State: v1.ContainerState{ + Waiting: &v1.ContainerStateWaiting{Reason: "CrashLoopBackOff"}, + }, + }, + } + }), nodes: []*v1.Node{node1}, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, - applyFunc: func(pods []*v1.Pod) { - for _, pod := range pods { - pod.Status.InitContainerStatuses = []v1.ContainerStatus{ - { - State: v1.ContainerState{ - Waiting: &v1.ContainerStateWaiting{Reason: "CrashLoopBackOff"}, - }, - }, - } - } - }, }, } for _, tc := range tests { t.Run(tc.description, func(t *testing.T) { - if tc.applyFunc != nil { - tc.applyFunc(tc.pods) - } - ctx, cancel := context.WithCancel(context.Background()) defer cancel() From a5d3241a540db551cfd6e6510f726990a076d431 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 11:58:12 +0100 Subject: [PATCH 08/14] refactor(TestRemovePodsHavingTooManyRestarts): replace test.BuildTestNode with buildTestNode helpers --- .../toomanyrestarts_test.go | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index fa51a6094..3602c047b 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -35,10 +35,15 @@ import ( const ( nodeName1 = "node1" + nodeName2 = "node2" nodeName4 = "node4" nodeName5 = "node5" ) +func buildTestNode(nodeName string, apply func(*v1.Node)) *v1.Node { + return test.BuildTestNode(nodeName, 2000, 3000, 10, apply) +} + func setPodContainerStatusRestartCount(pod *v1.Pod, base int32) { pod.Status = v1.PodStatus{ InitContainerStatuses: []v1.ContainerStatus{ @@ -124,8 +129,8 @@ func initPods(apply func(pod *v1.Pod)) []*v1.Pod { } func TestRemovePodsHavingTooManyRestarts(t *testing.T) { - node1 := test.BuildTestNode(nodeName1, 2000, 3000, 10, nil) - node2 := test.BuildTestNode("node2", 2000, 3000, 10, func(node *v1.Node) { + node1 := buildTestNode(nodeName1, nil) + node2 := buildTestNode(nodeName2, func(node *v1.Node) { node.Spec.Taints = []v1.Taint{ { Key: "hardware", @@ -134,13 +139,13 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { }, } }) - node3 := test.BuildTestNode("node3", 2000, 3000, 10, func(node *v1.Node) { + node3 := buildTestNode("node3", func(node *v1.Node) { node.Spec = v1.NodeSpec{ Unschedulable: true, } }) node4 := test.BuildTestNode(nodeName4, 200, 3000, 10, nil) - node5 := test.BuildTestNode(nodeName5, 2000, 3000, 10, nil) + node5 := buildTestNode(nodeName5, nil) createRemovePodsHavingTooManyRestartsAgrs := func( podRestartThresholds int32, @@ -274,9 +279,9 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { nodeFit: true, }, { - description: "pods are in CrashLoopBackOff with states=CrashLoopBackOff, 3 pod evictions", - args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}}, - pods: initPods(func(pod *v1.Pod) { + description: "pods are in CrashLoopBackOff with states=CrashLoopBackOff, 3 pod evictions", + args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}}, + pods: initPods(func(pod *v1.Pod) { if len(pod.Status.ContainerStatuses) > 0 { pod.Status.ContainerStatuses[0].State = v1.ContainerState{ Waiting: &v1.ContainerStateWaiting{Reason: "CrashLoopBackOff"}, @@ -298,9 +303,9 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { nodeFit: true, }, { - description: "pods running with state=Running, 3 pod evictions", - args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{string(v1.PodRunning)}}, - pods: initPods(func(pod *v1.Pod) { + description: "pods running with state=Running, 3 pod evictions", + args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{string(v1.PodRunning)}}, + pods: initPods(func(pod *v1.Pod) { pod.Status.Phase = v1.PodRunning }), nodes: []*v1.Node{node1}, @@ -308,9 +313,9 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { maxPodsToEvictPerNode: &uint3, }, { - description: "pods pending with state=Running, 0 pod evictions", - args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{string(v1.PodRunning)}}, - pods: initPods(func(pod *v1.Pod) { + description: "pods pending with state=Running, 0 pod evictions", + args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{string(v1.PodRunning)}}, + pods: initPods(func(pod *v1.Pod) { pod.Status.Phase = v1.PodPending }), nodes: []*v1.Node{node1}, @@ -318,9 +323,9 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { maxPodsToEvictPerNode: &uint3, }, { - description: "pods pending with initContainer with states=CrashLoopBackOff threshold(includingInitContainers=true), 3 pod evictions", - args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}, IncludingInitContainers: true}, - pods: initPods(func(pod *v1.Pod) { + description: "pods pending with initContainer with states=CrashLoopBackOff threshold(includingInitContainers=true), 3 pod evictions", + args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}, IncludingInitContainers: true}, + pods: initPods(func(pod *v1.Pod) { pod.Status.InitContainerStatuses = []v1.ContainerStatus{ { State: v1.ContainerState{ @@ -334,9 +339,9 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { maxPodsToEvictPerNode: &uint3, }, { - description: "pods pending with initContainer with states=CrashLoopBackOff threshold(includingInitContainers=false), 0 pod evictions", - args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}, IncludingInitContainers: false}, - pods: initPods(func(pod *v1.Pod) { + description: "pods pending with initContainer with states=CrashLoopBackOff threshold(includingInitContainers=false), 0 pod evictions", + args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}, IncludingInitContainers: false}, + pods: initPods(func(pod *v1.Pod) { pod.Status.InitContainerStatuses = []v1.ContainerStatus{ { State: v1.ContainerState{ From be275deea5156cceca3c6ff876e4efb99d804b77 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:06:47 +0100 Subject: [PATCH 09/14] refactor(TestRemovePodsHavingTooManyRestarts): node3 as a constant --- .../removepodshavingtoomanyrestarts/toomanyrestarts_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 3602c047b..aa70ed028 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -36,6 +36,7 @@ import ( const ( nodeName1 = "node1" nodeName2 = "node2" + nodeName3 = "node3" nodeName4 = "node4" nodeName5 = "node5" ) @@ -139,7 +140,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { }, } }) - node3 := buildTestNode("node3", func(node *v1.Node) { + node3 := buildTestNode(nodeName3, func(node *v1.Node) { node.Spec = v1.NodeSpec{ Unschedulable: true, } From b069ae009a98c6415837f55f73940f4d7dae636f Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:08:58 +0100 Subject: [PATCH 10/14] refactor(TestRemovePodsHavingTooManyRestarts): inline node1 --- .../toomanyrestarts_test.go | 177 +++++++++++------- 1 file changed, 111 insertions(+), 66 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index aa70ed028..658a68a13 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -130,7 +130,6 @@ func initPods(apply func(pod *v1.Pod)) []*v1.Pod { } func TestRemovePodsHavingTooManyRestarts(t *testing.T) { - node1 := buildTestNode(nodeName1, nil) node2 := buildTestNode(nodeName2, func(node *v1.Node) { node.Spec.Taints = []v1.Taint{ { @@ -171,110 +170,142 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { nodeFit bool }{ { - description: "All pods have total restarts under threshold, no pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(10000, true), - pods: initPods(nil), - nodes: []*v1.Node{node1}, + description: "All pods have total restarts under threshold, no pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(10000, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 0, }, { - description: "Some pods have total restarts bigger than threshold", - args: createRemovePodsHavingTooManyRestartsAgrs(1, true), - pods: initPods(nil), - nodes: []*v1.Node{node1}, + description: "Some pods have total restarts bigger than threshold", + args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 6, }, { - description: "Nine pods have total restarts equals threshold(includingInitContainers=true), 6 pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(1*25, true), - pods: initPods(nil), - nodes: []*v1.Node{node1}, + description: "Nine pods have total restarts equals threshold(includingInitContainers=true), 6 pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(1*25, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 6, }, { - description: "Nine pods have total restarts equals threshold(includingInitContainers=false), 5 pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(1*25, false), - pods: initPods(nil), - nodes: []*v1.Node{node1}, + description: "Nine pods have total restarts equals threshold(includingInitContainers=false), 5 pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(1*25, false), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 5, }, { - description: "All pods have total restarts equals threshold(includingInitContainers=true), 6 pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(1*20, true), - pods: initPods(nil), - nodes: []*v1.Node{node1}, + description: "All pods have total restarts equals threshold(includingInitContainers=true), 6 pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(1*20, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 6, }, { - description: "Nine pods have total restarts equals threshold(includingInitContainers=false), 6 pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(1*20, false), - pods: initPods(nil), - nodes: []*v1.Node{node1}, + description: "Nine pods have total restarts equals threshold(includingInitContainers=false), 6 pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(1*20, false), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 6, }, { - description: "Five pods have total restarts bigger than threshold(includingInitContainers=true), but only 1 pod eviction", - args: createRemovePodsHavingTooManyRestartsAgrs(5*25+1, true), - pods: initPods(nil), - nodes: []*v1.Node{node1}, + description: "Five pods have total restarts bigger than threshold(includingInitContainers=true), but only 1 pod eviction", + args: createRemovePodsHavingTooManyRestartsAgrs(5*25+1, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 1, }, { - description: "Five pods have total restarts bigger than threshold(includingInitContainers=false), but only 1 pod eviction", - args: createRemovePodsHavingTooManyRestartsAgrs(5*20+1, false), - pods: initPods(nil), - nodes: []*v1.Node{node1}, + description: "Five pods have total restarts bigger than threshold(includingInitContainers=false), but only 1 pod eviction", + args: createRemovePodsHavingTooManyRestartsAgrs(5*20+1, false), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 1, nodeFit: false, }, { - description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3), 3 pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(1, true), - pods: initPods(nil), - nodes: []*v1.Node{node1}, + description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3), 3 pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, }, { - description: "All pods have total restarts equals threshold(maxNoOfPodsToEvictPerNamespace=3), 3 pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(1, true), - pods: initPods(nil), - nodes: []*v1.Node{node1}, + description: "All pods have total restarts equals threshold(maxNoOfPodsToEvictPerNamespace=3), 3 pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 3, maxNoOfPodsToEvictPerNamespace: &uint3, }, { - description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node is tainted, 0 pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(1, true), - pods: initPods(nil), - nodes: []*v1.Node{node1, node2}, + description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node is tainted, 0 pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node2, + }, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, nodeFit: true, }, { - description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node is not schedulable, 0 pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(1, true), - pods: initPods(nil), - nodes: []*v1.Node{node1, node3}, + description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node is not schedulable, 0 pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node3, + }, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, nodeFit: true, }, { - description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node does not have enough CPU, 0 pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(1, true), - pods: initPods(nil), - nodes: []*v1.Node{node1, node4}, + description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node does not have enough CPU, 0 pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node4, + }, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, nodeFit: true, }, { - description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node has enough CPU, 3 pod evictions", - args: createRemovePodsHavingTooManyRestartsAgrs(1, true), - pods: initPods(nil), - nodes: []*v1.Node{node1, node5}, + description: "All pods have total restarts equals threshold(maxPodsToEvictPerNode=3) but the only other node has enough CPU, 3 pod evictions", + args: createRemovePodsHavingTooManyRestartsAgrs(1, true), + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node5, + }, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, nodeFit: true, @@ -289,16 +320,22 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { } } }), - nodes: []*v1.Node{node1, node5}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node5, + }, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, nodeFit: true, }, { - description: "pods without CrashLoopBackOff with states=CrashLoopBackOff, 0 pod evictions", - args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}}, - pods: initPods(nil), - nodes: []*v1.Node{node1, node5}, + description: "pods without CrashLoopBackOff with states=CrashLoopBackOff, 0 pod evictions", + args: RemovePodsHavingTooManyRestartsArgs{PodRestartThreshold: 1, States: []string{"CrashLoopBackOff"}}, + pods: initPods(nil), + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + node5, + }, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, nodeFit: true, @@ -309,7 +346,9 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { pods: initPods(func(pod *v1.Pod) { pod.Status.Phase = v1.PodRunning }), - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, }, @@ -319,7 +358,9 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { pods: initPods(func(pod *v1.Pod) { pod.Status.Phase = v1.PodPending }), - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, }, @@ -335,7 +376,9 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { }, } }), - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, }, @@ -351,7 +394,9 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { }, } }), - nodes: []*v1.Node{node1}, + nodes: []*v1.Node{ + buildTestNode(nodeName1, nil), + }, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, }, From 35d2103fcfc8c62dae401bc9d15dc9508ff3a52f Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:10:34 +0100 Subject: [PATCH 11/14] refactor(TestRemovePodsHavingTooManyRestarts): inline node2 --- .../toomanyrestarts_test.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 658a68a13..01f798d43 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -130,15 +130,6 @@ func initPods(apply func(pod *v1.Pod)) []*v1.Pod { } func TestRemovePodsHavingTooManyRestarts(t *testing.T) { - node2 := buildTestNode(nodeName2, func(node *v1.Node) { - node.Spec.Taints = []v1.Taint{ - { - Key: "hardware", - Value: "gpu", - Effect: v1.TaintEffectNoSchedule, - }, - } - }) node3 := buildTestNode(nodeName3, func(node *v1.Node) { node.Spec = v1.NodeSpec{ Unschedulable: true, @@ -268,7 +259,15 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { pods: initPods(nil), nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node2, + buildTestNode(nodeName2, func(node *v1.Node) { + node.Spec.Taints = []v1.Taint{ + { + Key: "hardware", + Value: "gpu", + Effect: v1.TaintEffectNoSchedule, + }, + } + }), }, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, From 76895273f93e43a505a4f5f2e9d4a2cb1ad4c775 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:11:09 +0100 Subject: [PATCH 12/14] refactor(TestRemovePodsHavingTooManyRestarts): inline node3 --- .../toomanyrestarts_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index 01f798d43..e552b2310 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -130,11 +130,6 @@ func initPods(apply func(pod *v1.Pod)) []*v1.Pod { } func TestRemovePodsHavingTooManyRestarts(t *testing.T) { - node3 := buildTestNode(nodeName3, func(node *v1.Node) { - node.Spec = v1.NodeSpec{ - Unschedulable: true, - } - }) node4 := test.BuildTestNode(nodeName4, 200, 3000, 10, nil) node5 := buildTestNode(nodeName5, nil) @@ -279,7 +274,11 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { pods: initPods(nil), nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node3, + buildTestNode(nodeName3, func(node *v1.Node) { + node.Spec = v1.NodeSpec{ + Unschedulable: true, + } + }), }, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, From 75f655e27124c8bbf907dd675a85fdcd6d5c2323 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:12:03 +0100 Subject: [PATCH 13/14] refactor(TestRemovePodsHavingTooManyRestarts): inline node4 --- .../removepodshavingtoomanyrestarts/toomanyrestarts_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index e552b2310..f85b8eb2b 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -130,7 +130,6 @@ func initPods(apply func(pod *v1.Pod)) []*v1.Pod { } func TestRemovePodsHavingTooManyRestarts(t *testing.T) { - node4 := test.BuildTestNode(nodeName4, 200, 3000, 10, nil) node5 := buildTestNode(nodeName5, nil) createRemovePodsHavingTooManyRestartsAgrs := func( @@ -290,7 +289,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { pods: initPods(nil), nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node4, + test.BuildTestNode(nodeName4, 200, 3000, 10, nil), }, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3, From ee73336fd8272c389a2dfe5f43dcd6197edeb091 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 12:12:33 +0100 Subject: [PATCH 14/14] refactor(TestRemovePodsHavingTooManyRestarts): inline node5 --- .../toomanyrestarts_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go index f85b8eb2b..b5bcddb26 100644 --- a/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go +++ b/pkg/framework/plugins/removepodshavingtoomanyrestarts/toomanyrestarts_test.go @@ -130,8 +130,6 @@ func initPods(apply func(pod *v1.Pod)) []*v1.Pod { } func TestRemovePodsHavingTooManyRestarts(t *testing.T) { - node5 := buildTestNode(nodeName5, nil) - createRemovePodsHavingTooManyRestartsAgrs := func( podRestartThresholds int32, includingInitContainers bool, @@ -301,7 +299,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { pods: initPods(nil), nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node5, + buildTestNode(nodeName5, nil), }, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, @@ -319,7 +317,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { }), nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node5, + buildTestNode(nodeName5, nil), }, expectedEvictedPodCount: 3, maxPodsToEvictPerNode: &uint3, @@ -331,7 +329,7 @@ func TestRemovePodsHavingTooManyRestarts(t *testing.T) { pods: initPods(nil), nodes: []*v1.Node{ buildTestNode(nodeName1, nil), - node5, + buildTestNode(nodeName5, nil), }, expectedEvictedPodCount: 0, maxPodsToEvictPerNode: &uint3,