mirror of
https://github.com/kubernetes-sigs/descheduler.git
synced 2026-01-26 13:29:11 +01:00
refactor(TestPodLifeTime): consolidate all owner references
test.GetReplicaSetOwnerRefList produces the same value everything it's invoked.
This commit is contained in:
@@ -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
|
||||
}),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user