@@ -31,14 +31,23 @@ func testPodList() []v1.Pod {
3131 },
3232 ObjectMeta : metav1.ObjectMeta {
3333 Name : "bearded-dragon" ,
34- Annotations : map [string ]string {"example/key" : "lizard" },
34+ Annotations : map [string ]string {"example/key" : "lizard" , "controller.kubernetes.io/pod-deletion-cost" : "invalid" },
3535 },
3636 },
3737 {
3838 Status : v1.PodStatus {},
3939 ObjectMeta : metav1.ObjectMeta {
4040 Name : "nil-start-time" ,
41- Annotations : map [string ]string {"example/key" : "lizard" },
41+ Annotations : map [string ]string {"example/key" : "lizard" , "controller.kubernetes.io/pod-deletion-cost" : "-100" },
42+ },
43+ },
44+ {
45+ Status : v1.PodStatus {
46+ StartTime : epocPlus (5 * time .Minute ),
47+ },
48+ ObjectMeta : metav1.ObjectMeta {
49+ Name : "expensive" ,
50+ Annotations : map [string ]string {"example/key" : "not-lizard" , "controller.kubernetes.io/pod-deletion-cost" : "500" },
4251 },
4352 },
4453 {
@@ -325,7 +334,8 @@ func TestOptions(t *testing.T) {
325334 sorter (subject )
326335 assert .Equal (t , "corgi" , subject [0 ].ObjectMeta .Name )
327336 assert .Equal (t , "bearded-dragon" , subject [1 ].ObjectMeta .Name )
328- assert .Equal (t , "nil-start-time" , subject [2 ].ObjectMeta .Name )
337+ assert .Equal (t , "expensive" , subject [2 ].ObjectMeta .Name )
338+ assert .Equal (t , "nil-start-time" , subject [3 ].ObjectMeta .Name )
329339 assert .ElementsMatch (t , testPodList (), subject )
330340 })
331341 t .Run ("youngest-first" , func (t * testing.T ) {
@@ -336,9 +346,22 @@ func TestOptions(t *testing.T) {
336346 assert .NoError (t , err )
337347 subject := testPodList ()
338348 sorter (subject )
339- assert .Equal (t , "bearded-dragon" , subject [0 ].ObjectMeta .Name )
340- assert .Equal (t , "corgi" , subject [1 ].ObjectMeta .Name )
341- assert .Equal (t , "nil-start-time" , subject [2 ].ObjectMeta .Name )
349+ assert .Equal (t , "expensive" , subject [0 ].ObjectMeta .Name )
350+ assert .Equal (t , "bearded-dragon" , subject [1 ].ObjectMeta .Name )
351+ assert .Equal (t , "corgi" , subject [2 ].ObjectMeta .Name )
352+ assert .Equal (t , "nil-start-time" , subject [3 ].ObjectMeta .Name )
353+ assert .ElementsMatch (t , testPodList (), subject )
354+ })
355+ t .Run ("pod-deletion-cost" , func (t * testing.T ) {
356+ os .Clearenv ()
357+ os .Setenv (envPodSortingStrategy , "pod-deletion-cost" )
358+ sorter , err := podSortingStrategy ()
359+ assert .NotNil (t , sorter )
360+ assert .NoError (t , err )
361+ subject := testPodList ()
362+ sorter (subject )
363+ assert .Equal (t , "nil-start-time" , subject [0 ].ObjectMeta .Name )
364+ assert .Equal (t , "expensive" , subject [3 ].ObjectMeta .Name )
342365 assert .ElementsMatch (t , testPodList (), subject )
343366 })
344367 })
0 commit comments