From aec4416099d83b49ec5d76d991ba1350b280ba17 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Mon, 15 Dec 2025 15:59:01 +0100 Subject: [PATCH] refactor(TestRemovePodsViolatingNodeAffinity): add buildUnschedulableNodeWithLabels function --- .../node_affinity_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/framework/plugins/removepodsviolatingnodeaffinity/node_affinity_test.go b/pkg/framework/plugins/removepodsviolatingnodeaffinity/node_affinity_test.go index 10ea1a3ec..51e352738 100644 --- a/pkg/framework/plugins/removepodsviolatingnodeaffinity/node_affinity_test.go +++ b/pkg/framework/plugins/removepodsviolatingnodeaffinity/node_affinity_test.go @@ -52,12 +52,14 @@ func buildTestPod(name string, nodeName string, apply func(*v1.Pod)) *v1.Pod { return test.BuildTestPod(name, 100, 0, nodeName, apply) } -func TestRemovePodsViolatingNodeAffinity(t *testing.T) { - unschedulableNodeWithLabels := buildTestNode(unschedulableNodeWithLabelsName, func(node *v1.Node) { +func buildUnschedulableNodeWithLabels() *v1.Node { + return buildTestNode(unschedulableNodeWithLabelsName, func(node *v1.Node) { setNodeDesiredNodeLabel(node) node.Spec.Unschedulable = true }) +} +func TestRemovePodsViolatingNodeAffinity(t *testing.T) { addPodsToNode := func(nodeName string, deletionTimestamp *metav1.Time, affinityType string) []*v1.Pod { podWithNodeAffinity := buildTestPod("podWithNodeAffinity", nodeName, func(pod *v1.Pod) { pod.Spec.Affinity = &v1.Affinity{ @@ -373,7 +375,7 @@ func TestRemovePodsViolatingNodeAffinity(t *testing.T) { pods: addPodsToNode(nodeWithoutLabelsName, nil, "requiredDuringSchedulingIgnoredDuringExecution"), nodes: []*v1.Node{ buildTestNode(nodeWithoutLabelsName, nil), - unschedulableNodeWithLabels, + buildUnschedulableNodeWithLabels(), }, nodefit: true, }, @@ -386,7 +388,7 @@ func TestRemovePodsViolatingNodeAffinity(t *testing.T) { pods: addPodsToNode(nodeWithoutLabelsName, nil, "preferredDuringSchedulingIgnoredDuringExecution"), nodes: []*v1.Node{ buildTestNode(nodeWithoutLabelsName, nil), - unschedulableNodeWithLabels, + buildUnschedulableNodeWithLabels(), }, nodefit: true, }, @@ -399,7 +401,7 @@ func TestRemovePodsViolatingNodeAffinity(t *testing.T) { pods: addPodsToNode(nodeWithoutLabelsName, nil, "requiredDuringSchedulingIgnoredDuringExecution"), nodes: []*v1.Node{ buildTestNode(nodeWithLabelsName, setNodeDesiredNodeLabel), - unschedulableNodeWithLabels, + buildUnschedulableNodeWithLabels(), }, maxPodsToEvictPerNode: &uint1, nodefit: true, @@ -413,7 +415,7 @@ func TestRemovePodsViolatingNodeAffinity(t *testing.T) { pods: addPodsToNode(nodeWithoutLabelsName, nil, "preferredDuringSchedulingIgnoredDuringExecution"), nodes: []*v1.Node{ buildTestNode(nodeWithLabelsName, setNodeDesiredNodeLabel), - unschedulableNodeWithLabels, + buildUnschedulableNodeWithLabels(), }, maxPodsToEvictPerNode: &uint1, nodefit: true,