@@ -490,6 +490,7 @@ func TestSortingActivePods(t *testing.T) {
490
490
now := metav1 .Now ()
491
491
then := metav1.Time {Time : now .AddDate (0 , - 1 , 0 )}
492
492
493
+ restartAlways := v1 .ContainerRestartPolicyAlways
493
494
tests := []struct {
494
495
name string
495
496
pods []v1.Pod
@@ -545,6 +546,22 @@ func TestSortingActivePods(t *testing.T) {
545
546
ContainerStatuses : []v1.ContainerStatus {{RestartCount : 3 }, {RestartCount : 0 }},
546
547
},
547
548
},
549
+ {
550
+ ObjectMeta : metav1.ObjectMeta {Name : "lowerSidecarContainerRestartCount" , CreationTimestamp : now },
551
+ Spec : v1.PodSpec {
552
+ NodeName : "foo" ,
553
+ InitContainers : []v1.Container {{
554
+ Name : "sidecar" ,
555
+ RestartPolicy : & restartAlways ,
556
+ }},
557
+ },
558
+ Status : v1.PodStatus {
559
+ Phase : v1 .PodRunning ,
560
+ Conditions : []v1.PodCondition {{Type : v1 .PodReady , Status : v1 .ConditionTrue , LastTransitionTime : then }},
561
+ ContainerStatuses : []v1.ContainerStatus {{RestartCount : 2 }, {RestartCount : 1 }},
562
+ InitContainerStatuses : []v1.ContainerStatus {{Name : "sidecar" , RestartCount : 2 }},
563
+ },
564
+ },
548
565
{
549
566
ObjectMeta : metav1.ObjectMeta {Name : "lowerContainerRestartCount" , CreationTimestamp : now },
550
567
Spec : v1.PodSpec {NodeName : "foo" },
@@ -572,6 +589,7 @@ func TestSortingActivePods(t *testing.T) {
572
589
"runningNoLastTransitionTime" ,
573
590
"runningWithLastTransitionTime" ,
574
591
"runningLongerTime" ,
592
+ "lowerSidecarContainerRestartCount" ,
575
593
"lowerContainerRestartCount" ,
576
594
"oldest" ,
577
595
},
@@ -610,44 +628,52 @@ func TestSortingActivePodsWithRanks(t *testing.T) {
610
628
then5Hours := metav1.Time {Time : now .Add (- 5 * time .Hour )}
611
629
then8Hours := metav1.Time {Time : now .Add (- 8 * time .Hour )}
612
630
zeroTime := metav1.Time {}
613
- pod := func (podName , nodeName string , phase v1.PodPhase , ready bool , restarts int32 , readySince metav1.Time , created metav1.Time , annotations map [string ]string ) * v1.Pod {
631
+ restartAlways := v1 .ContainerRestartPolicyAlways
632
+ pod := func (podName , nodeName string , phase v1.PodPhase , ready bool , restarts int32 , sideRestarts int32 , readySince metav1.Time , created metav1.Time , annotations map [string ]string ) * v1.Pod {
614
633
var conditions []v1.PodCondition
615
634
var containerStatuses []v1.ContainerStatus
635
+ var initContainerStatuses []v1.ContainerStatus
616
636
if ready {
617
637
conditions = []v1.PodCondition {{Type : v1 .PodReady , Status : v1 .ConditionTrue , LastTransitionTime : readySince }}
618
638
containerStatuses = []v1.ContainerStatus {{RestartCount : restarts }}
639
+ initContainerStatuses = []v1.ContainerStatus {{Name : "sidecar" , RestartCount : sideRestarts }}
619
640
}
620
641
return & v1.Pod {
621
642
ObjectMeta : metav1.ObjectMeta {
622
643
CreationTimestamp : created ,
623
644
Name : podName ,
624
645
Annotations : annotations ,
625
646
},
626
- Spec : v1.PodSpec {NodeName : nodeName },
647
+ Spec : v1.PodSpec {
648
+ NodeName : nodeName ,
649
+ InitContainers : []v1.Container {{Name : "sidecar" , RestartPolicy : & restartAlways }},
650
+ },
627
651
Status : v1.PodStatus {
628
- Conditions : conditions ,
629
- ContainerStatuses : containerStatuses ,
630
- Phase : phase ,
652
+ Conditions : conditions ,
653
+ ContainerStatuses : containerStatuses ,
654
+ InitContainerStatuses : initContainerStatuses ,
655
+ Phase : phase ,
631
656
},
632
657
}
633
658
}
634
659
var (
635
- unscheduledPod = pod ("unscheduled" , "" , v1 .PodPending , false , 0 , zeroTime , zeroTime , nil )
636
- scheduledPendingPod = pod ("pending" , "node" , v1 .PodPending , false , 0 , zeroTime , zeroTime , nil )
637
- unknownPhasePod = pod ("unknown-phase" , "node" , v1 .PodUnknown , false , 0 , zeroTime , zeroTime , nil )
638
- runningNotReadyPod = pod ("not-ready" , "node" , v1 .PodRunning , false , 0 , zeroTime , zeroTime , nil )
639
- runningReadyNoLastTransitionTimePod = pod ("ready-no-last-transition-time" , "node" , v1 .PodRunning , true , 0 , zeroTime , zeroTime , nil )
640
- runningReadyNow = pod ("ready-now" , "node" , v1 .PodRunning , true , 0 , now , now , nil )
641
- runningReadyThen = pod ("ready-then" , "node" , v1 .PodRunning , true , 0 , then1Month , then1Month , nil )
642
- runningReadyNowHighRestarts = pod ("ready-high-restarts" , "node" , v1 .PodRunning , true , 9001 , now , now , nil )
643
- runningReadyNowCreatedThen = pod ("ready-now-created-then" , "node" , v1 .PodRunning , true , 0 , now , then1Month , nil )
644
- lowPodDeletionCost = pod ("low-deletion-cost" , "node" , v1 .PodRunning , true , 0 , now , then1Month , map [string ]string {core .PodDeletionCost : "10" })
645
- highPodDeletionCost = pod ("high-deletion-cost" , "node" , v1 .PodRunning , true , 0 , now , then1Month , map [string ]string {core .PodDeletionCost : "100" })
646
- unscheduled5Hours = pod ("unscheduled-5-hours" , "" , v1 .PodPending , false , 0 , then5Hours , then5Hours , nil )
647
- unscheduled8Hours = pod ("unscheduled-10-hours" , "" , v1 .PodPending , false , 0 , then8Hours , then8Hours , nil )
648
- ready2Hours = pod ("ready-2-hours" , "" , v1 .PodRunning , true , 0 , then2Hours , then1Month , nil )
649
- ready5Hours = pod ("ready-5-hours" , "" , v1 .PodRunning , true , 0 , then5Hours , then1Month , nil )
650
- ready10Hours = pod ("ready-10-hours" , "" , v1 .PodRunning , true , 0 , then8Hours , then1Month , nil )
660
+ unscheduledPod = pod ("unscheduled" , "" , v1 .PodPending , false , 0 , 0 , zeroTime , zeroTime , nil )
661
+ scheduledPendingPod = pod ("pending" , "node" , v1 .PodPending , false , 0 , 0 , zeroTime , zeroTime , nil )
662
+ unknownPhasePod = pod ("unknown-phase" , "node" , v1 .PodUnknown , false , 0 , 0 , zeroTime , zeroTime , nil )
663
+ runningNotReadyPod = pod ("not-ready" , "node" , v1 .PodRunning , false , 0 , 0 , zeroTime , zeroTime , nil )
664
+ runningReadyNoLastTransitionTimePod = pod ("ready-no-last-transition-time" , "node" , v1 .PodRunning , true , 0 , 0 , zeroTime , zeroTime , nil )
665
+ runningReadyNow = pod ("ready-now" , "node" , v1 .PodRunning , true , 0 , 0 , now , now , nil )
666
+ runningReadyThen = pod ("ready-then" , "node" , v1 .PodRunning , true , 0 , 0 , then1Month , then1Month , nil )
667
+ runningReadyNowHighRestarts = pod ("ready-high-restarts" , "node" , v1 .PodRunning , true , 9001 , 0 , now , now , nil )
668
+ runningReadyNowHighSideRestarts = pod ("ready-high-restarts" , "node" , v1 .PodRunning , true , 9001 , 9001 , now , now , nil )
669
+ runningReadyNowCreatedThen = pod ("ready-now-created-then" , "node" , v1 .PodRunning , true , 0 , 0 , now , then1Month , nil )
670
+ lowPodDeletionCost = pod ("low-deletion-cost" , "node" , v1 .PodRunning , true , 0 , 0 , now , then1Month , map [string ]string {core .PodDeletionCost : "10" })
671
+ highPodDeletionCost = pod ("high-deletion-cost" , "node" , v1 .PodRunning , true , 0 , 0 , now , then1Month , map [string ]string {core .PodDeletionCost : "100" })
672
+ unscheduled5Hours = pod ("unscheduled-5-hours" , "" , v1 .PodPending , false , 0 , 0 , then5Hours , then5Hours , nil )
673
+ unscheduled8Hours = pod ("unscheduled-10-hours" , "" , v1 .PodPending , false , 0 , 0 , then8Hours , then8Hours , nil )
674
+ ready2Hours = pod ("ready-2-hours" , "" , v1 .PodRunning , true , 0 , 0 , then2Hours , then1Month , nil )
675
+ ready5Hours = pod ("ready-5-hours" , "" , v1 .PodRunning , true , 0 , 0 , then5Hours , then1Month , nil )
676
+ ready10Hours = pod ("ready-10-hours" , "" , v1 .PodRunning , true , 0 , 0 , then8Hours , then1Month , nil )
651
677
)
652
678
equalityTests := []struct {
653
679
p1 * v1.Pod
@@ -702,6 +728,7 @@ func TestSortingActivePodsWithRanks(t *testing.T) {
702
728
{lesser : podWithRank {runningReadyNow , 1 }, greater : podWithRank {runningReadyThen , 1 }},
703
729
{lesser : podWithRank {runningReadyNow , 2 }, greater : podWithRank {runningReadyThen , 1 }},
704
730
{lesser : podWithRank {runningReadyNowHighRestarts , 1 }, greater : podWithRank {runningReadyNow , 1 }},
731
+ {lesser : podWithRank {runningReadyNowHighSideRestarts , 1 }, greater : podWithRank {runningReadyNowHighRestarts , 1 }},
705
732
{lesser : podWithRank {runningReadyNow , 2 }, greater : podWithRank {runningReadyNowHighRestarts , 1 }},
706
733
{lesser : podWithRank {runningReadyNow , 1 }, greater : podWithRank {runningReadyNowCreatedThen , 1 }},
707
734
{lesser : podWithRank {runningReadyNowCreatedThen , 2 }, greater : podWithRank {runningReadyNow , 1 }},
0 commit comments