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

refactor(TestPodLifeTime): inline pod creation in each unit test to avoid accidental pod spec updates

This commit is contained in:
Jan Chaloupka
2025-12-10 16:03:33 +01:00
parent 41a0a9c994
commit 3ea0eadcb3

View File

@@ -70,16 +70,6 @@ func TestPodLifeTime(t *testing.T) {
})
}
p11 := buildTestPodWithRSOwnerRefForNode1("p11", olderPodCreationTime, func(pod *v1.Pod) {
pod.Spec.Volumes = []v1.Volume{
{
Name: "pvc", VolumeSource: v1.VolumeSource{
PersistentVolumeClaim: &v1.PersistentVolumeClaimVolumeSource{ClaimName: "foo"},
},
},
}
})
// Setup two old pods with different labels
p12 := buildTestPodWithRSOwnerRefForNode1("p12", olderPodCreationTime, func(pod *v1.Pod) {
pod.ObjectMeta.Labels = map[string]string{"foo": "bar"}
@@ -226,7 +216,17 @@ func TestPodLifeTime(t *testing.T) {
args: &PodLifeTimeArgs{
MaxPodLifeTimeSeconds: &maxLifeTime,
},
pods: []*v1.Pod{p11},
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,
@@ -236,7 +236,17 @@ func TestPodLifeTime(t *testing.T) {
args: &PodLifeTimeArgs{
MaxPodLifeTimeSeconds: &maxLifeTime,
},
pods: []*v1.Pod{p11},
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,
},