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