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

refactor(TestPodLifeTime): extract evictor configuration tests

This commit is contained in:
Jan Chaloupka
2025-12-13 13:53:59 +01:00
parent 2658864ac0
commit 2710fd3781

View File

@@ -143,45 +143,6 @@ func runPodLifeTimeTest(t *testing.T, tc podLifeTimeTestCase) {
func TestPodLifeTime(t *testing.T) {
var maxLifeTime uint = 600
testCases := []podLifeTimeTestCase{
{
description: "Does not evict pvc pods with ignorePvcPods set to true",
args: &PodLifeTimeArgs{
MaxPodLifeTimeSeconds: &maxLifeTime,
},
pods: []*v1.Pod{
buildTestPodWithRSOwnerRefForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) {
pod.Spec.Volumes = []v1.Volume{
{
Name: "pvc", VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: "foo"},
},
},
}
}),
},
nodes: []*v1.Node{buildTestNode1()},
expectedEvictedPodCount: 0,
ignorePvcPods: true,
},
{
description: "Evicts pvc pods with ignorePvcPods set to false (or unset)",
args: &PodLifeTimeArgs{
MaxPodLifeTimeSeconds: &maxLifeTime,
},
pods: []*v1.Pod{
buildTestPodWithRSOwnerRefForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) {
pod.Spec.Volumes = []v1.Volume{
{
Name: "pvc", VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: "foo"},
},
},
}
}),
},
nodes: []*v1.Node{buildTestNode1()},
expectedEvictedPodCount: 1,
},
{
description: "1 pod matching label selector should be evicted",
args: &PodLifeTimeArgs{
@@ -230,6 +191,57 @@ func TestPodLifeTime(t *testing.T) {
}
}
func TestPodLifeTime_EvictorConfiguration(t *testing.T) {
var maxLifeTime uint = 600
testCases := []podLifeTimeTestCase{
{
description: "Does not evict pvc pods with ignorePvcPods set to true",
args: &PodLifeTimeArgs{
MaxPodLifeTimeSeconds: &maxLifeTime,
},
pods: []*v1.Pod{
buildTestPodWithRSOwnerRefForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) {
pod.Spec.Volumes = []v1.Volume{
{
Name: "pvc", VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: "foo"},
},
},
}
}),
},
nodes: []*v1.Node{buildTestNode1()},
expectedEvictedPodCount: 0,
ignorePvcPods: true,
},
{
description: "Evicts pvc pods with ignorePvcPods set to false (or unset)",
args: &PodLifeTimeArgs{
MaxPodLifeTimeSeconds: &maxLifeTime,
},
pods: []*v1.Pod{
buildTestPodWithRSOwnerRefForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) {
pod.Spec.Volumes = []v1.Volume{
{
Name: "pvc", VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: "foo"},
},
},
}
}),
},
nodes: []*v1.Node{buildTestNode1()},
expectedEvictedPodCount: 1,
},
}
for _, tc := range testCases {
t.Run(tc.description, func(t *testing.T) {
runPodLifeTimeTest(t, tc)
})
}
}
func TestPodLifeTime_EvictionLimits(t *testing.T) {
var maxLifeTime uint = 600
testCases := []podLifeTimeTestCase{