1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 05:14:13 +01:00

refactor(TestFindDuplicatePods): replace direct ownerRef assignment with test.SetRSOwnerRef

This commit is contained in:
Jan Chaloupka
2025-12-14 13:14:01 +01:00
parent 008265db9b
commit 59f499e2cd

View File

@@ -73,19 +73,18 @@ func TestFindDuplicatePods(t *testing.T) {
}) })
node6 := test.BuildTestNode("n6", 200, 200, 10, nil) node6 := test.BuildTestNode("n6", 200, 200, 10, nil)
ownerRef := test.GetReplicaSetOwnerRefList()
// Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted. // Three Pods in the "dev" Namespace, bound to same ReplicaSet. 2 should be evicted.
p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) { p1 := buildTestPodForNode1("p1", func(pod *v1.Pod) {
pod.Namespace = "dev" pod.Namespace = "dev"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
}) })
p2 := buildTestPodForNode1("p2", func(pod *v1.Pod) { p2 := buildTestPodForNode1("p2", func(pod *v1.Pod) {
pod.Namespace = "dev" pod.Namespace = "dev"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
}) })
p3 := buildTestPodForNode1("p3", func(pod *v1.Pod) { p3 := buildTestPodForNode1("p3", func(pod *v1.Pod) {
pod.Namespace = "dev" pod.Namespace = "dev"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
}) })
// A DaemonSet. // A DaemonSet.
p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) { p4 := buildTestPodForNode1("p4", func(pod *v1.Pod) {
@@ -119,31 +118,31 @@ func TestFindDuplicatePods(t *testing.T) {
// Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted. // Three Pods in the "test" Namespace, bound to same ReplicaSet. 2 should be evicted.
p8 := buildTestPodForNode1("p8", func(pod *v1.Pod) { p8 := buildTestPodForNode1("p8", func(pod *v1.Pod) {
pod.Namespace = "test" pod.Namespace = "test"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
}) })
p9 := buildTestPodForNode1("p9", func(pod *v1.Pod) { p9 := buildTestPodForNode1("p9", func(pod *v1.Pod) {
pod.Namespace = "test" pod.Namespace = "test"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
}) })
p10 := buildTestPodForNode1("p10", func(pod *v1.Pod) { p10 := buildTestPodForNode1("p10", func(pod *v1.Pod) {
pod.Namespace = "test" pod.Namespace = "test"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
}) })
// Same owners, but different images // Same owners, but different images
p11 := buildTestPodForNode1("p11", func(pod *v1.Pod) { p11 := buildTestPodForNode1("p11", func(pod *v1.Pod) {
pod.Namespace = "different-images" pod.Namespace = "different-images"
pod.Spec.Containers[0].Image = "foo" pod.Spec.Containers[0].Image = "foo"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
}) })
p12 := buildTestPodForNode1("p12", func(pod *v1.Pod) { p12 := buildTestPodForNode1("p12", func(pod *v1.Pod) {
pod.Namespace = "different-images" pod.Namespace = "different-images"
pod.Spec.Containers[0].Image = "bar" pod.Spec.Containers[0].Image = "bar"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
}) })
// Multiple containers // Multiple containers
p13 := buildTestPodForNode1("p13", func(pod *v1.Pod) { p13 := buildTestPodForNode1("p13", func(pod *v1.Pod) {
pod.Namespace = "different-images" pod.Namespace = "different-images"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{
Name: "foo", Name: "foo",
Image: "foo", Image: "foo",
@@ -152,21 +151,21 @@ func TestFindDuplicatePods(t *testing.T) {
// ### Pods Evictable Based On Node Fit ### // ### Pods Evictable Based On Node Fit ###
p15 := buildTestPodForNode1("p15", func(pod *v1.Pod) { p15 := buildTestPodForNode1("p15", func(pod *v1.Pod) {
pod.Namespace = "node-fit" pod.Namespace = "node-fit"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
pod.Spec.NodeSelector = map[string]string{ pod.Spec.NodeSelector = map[string]string{
"datacenter": "west", "datacenter": "west",
} }
}) })
p16 := buildTestPodForNode1("NOT1", func(pod *v1.Pod) { p16 := buildTestPodForNode1("NOT1", func(pod *v1.Pod) {
pod.Namespace = "node-fit" pod.Namespace = "node-fit"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
pod.Spec.NodeSelector = map[string]string{ pod.Spec.NodeSelector = map[string]string{
"datacenter": "west", "datacenter": "west",
} }
}) })
p17 := buildTestPodForNode1("NOT2", func(pod *v1.Pod) { p17 := buildTestPodForNode1("NOT2", func(pod *v1.Pod) {
pod.Namespace = "node-fit" pod.Namespace = "node-fit"
pod.ObjectMeta.OwnerReferences = ownerRef test.SetRSOwnerRef(pod)
pod.Spec.NodeSelector = map[string]string{ pod.Spec.NodeSelector = map[string]string{
"datacenter": "west", "datacenter": "west",
} }