@@ -697,7 +697,7 @@ func Test_InFlightPods(t *testing.T) {
697
697
case action .eventHappens != nil :
698
698
q .MoveAllToActiveOrBackoffQueue (logger , * action .eventHappens , nil , nil , nil )
699
699
case action .podEnqueued != nil :
700
- err := q .AddUnschedulableIfNotPresent (logger , action .podEnqueued , q .SchedulingCycle ())
700
+ err := q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( action .podEnqueued ) , q .SchedulingCycle ())
701
701
if err != nil {
702
702
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
703
703
}
@@ -1028,7 +1028,7 @@ func TestPriorityQueue_Update(t *testing.T) {
1028
1028
name : "when updating a pod which is in unschedulable queue and is backing off, it will be moved to backoff queue" ,
1029
1029
wantQ : backoffQ ,
1030
1030
prepareFunc : func (t * testing.T , logger klog.Logger , q * PriorityQueue ) (oldPod , newPod * v1.Pod ) {
1031
- q .unschedulablePods .addOrUpdate (q .newQueuedPodInfo (medPriorityPodInfo .Pod , queuePlugin ))
1031
+ q .unschedulablePods .addOrUpdate (attemptQueuedPodInfo ( q .newQueuedPodInfo (medPriorityPodInfo .Pod , queuePlugin ) ))
1032
1032
updatedPod := medPriorityPodInfo .Pod .DeepCopy ()
1033
1033
updatedPod .Annotations ["foo" ] = "test"
1034
1034
return medPriorityPodInfo .Pod , updatedPod
@@ -1039,7 +1039,7 @@ func TestPriorityQueue_Update(t *testing.T) {
1039
1039
name : "when updating a pod which is in unschedulable queue and is not backing off, it will be moved to active queue" ,
1040
1040
wantQ : activeQ ,
1041
1041
prepareFunc : func (t * testing.T , logger klog.Logger , q * PriorityQueue ) (oldPod , newPod * v1.Pod ) {
1042
- q .unschedulablePods .addOrUpdate (q .newQueuedPodInfo (medPriorityPodInfo .Pod , queuePlugin ))
1042
+ q .unschedulablePods .addOrUpdate (attemptQueuedPodInfo ( q .newQueuedPodInfo (medPriorityPodInfo .Pod , queuePlugin ) ))
1043
1043
updatedPod := medPriorityPodInfo .Pod .DeepCopy ()
1044
1044
updatedPod .Annotations ["foo" ] = "test1"
1045
1045
// Move clock by podInitialBackoffDuration, so that pods in the unschedulablePods would pass the backing off,
@@ -1175,7 +1175,7 @@ func TestPriorityQueue_UpdateWhenInflight(t *testing.T) {
1175
1175
// test-pod got rejected by fakePlugin,
1176
1176
// but the update event that it just got may change this scheduling result,
1177
1177
// and hence we should put this pod to activeQ/backoffQ.
1178
- err := q .AddUnschedulableIfNotPresent (logger , newQueuedPodInfoForLookup (updatedPod , "fakePlugin" ), q .SchedulingCycle ())
1178
+ err := q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( newQueuedPodInfoForLookup (updatedPod , "fakePlugin" ) ), q .SchedulingCycle ())
1179
1179
if err != nil {
1180
1180
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1181
1181
}
@@ -1519,7 +1519,7 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueueWithQueueingHint(t *testing.
1519
1519
},
1520
1520
{
1521
1521
name : "Queue queues pod to backoffQ if Pod is backing off" ,
1522
- podInfo : & framework.QueuedPodInfo {PodInfo : mustNewPodInfo (p ), UnschedulablePlugins : sets .New ("foo" )},
1522
+ podInfo : & framework.QueuedPodInfo {PodInfo : mustNewPodInfo (p ), Attempts : 1 , UnschedulablePlugins : sets .New ("foo" )},
1523
1523
hint : queueHintReturnQueue ,
1524
1524
expectedQ : backoffQ ,
1525
1525
},
@@ -1550,6 +1550,12 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueueWithQueueingHint(t *testing.
1550
1550
hint : queueHintReturnQueue ,
1551
1551
expectedQ : activeQ ,
1552
1552
},
1553
+ {
1554
+ name : "Pod that experienced a scheduling failure before should be queued to backoffQ after un-gated" ,
1555
+ podInfo : setQueuedPodInfoGated (& framework.QueuedPodInfo {PodInfo : mustNewPodInfo (p ), Attempts : 1 , UnschedulablePlugins : sets .New ("foo" )}),
1556
+ hint : queueHintReturnQueue ,
1557
+ expectedQ : backoffQ ,
1558
+ },
1553
1559
}
1554
1560
1555
1561
for _ , test := range tests {
@@ -1618,11 +1624,11 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueue(t *testing.T) {
1618
1624
t .Errorf ("Expected: %v after Pop, but got: %v" , highPriorityPodInfo .Pod .Name , p .Pod .Name )
1619
1625
}
1620
1626
expectInFlightPods (t , q , unschedulablePodInfo .Pod .UID , highPriorityPodInfo .Pod .UID )
1621
- err := q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ), q .SchedulingCycle ())
1627
+ err := q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ) ), q .SchedulingCycle ())
1622
1628
if err != nil {
1623
1629
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1624
1630
}
1625
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ), q .SchedulingCycle ())
1631
+ err = q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ) ), q .SchedulingCycle ())
1626
1632
if err != nil {
1627
1633
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1628
1634
}
@@ -1635,7 +1641,7 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueue(t *testing.T) {
1635
1641
}
1636
1642
expectInFlightPods (t , q , hpp1 .UID )
1637
1643
// This Pod will go to backoffQ because no failure plugin is associated with it.
1638
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (hpp1 ), q .SchedulingCycle ())
1644
+ err = q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( q .newQueuedPodInfo (hpp1 ) ), q .SchedulingCycle ())
1639
1645
if err != nil {
1640
1646
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1641
1647
}
@@ -1648,7 +1654,7 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueue(t *testing.T) {
1648
1654
}
1649
1655
expectInFlightPods (t , q , hpp2 .UID )
1650
1656
// This Pod will go to the unschedulable Pod pool.
1651
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (hpp2 , "barPlugin" ), q .SchedulingCycle ())
1657
+ err = q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( q .newQueuedPodInfo (hpp2 , "barPlugin" ) ), q .SchedulingCycle ())
1652
1658
if err != nil {
1653
1659
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1654
1660
}
@@ -1691,9 +1697,9 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueue(t *testing.T) {
1691
1697
if p , err := q .Pop (logger ); err != nil || p .Pod != hpp1 {
1692
1698
t .Errorf ("Expected: %v after Pop, but got: %v" , hpp1 , p .Pod .Name )
1693
1699
}
1694
- unschedulableQueuedPodInfo := q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" )
1695
- highPriorityQueuedPodInfo := q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" )
1696
- hpp1QueuedPodInfo := q .newQueuedPodInfo (hpp1 )
1700
+ unschedulableQueuedPodInfo := attemptQueuedPodInfo ( q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ) )
1701
+ highPriorityQueuedPodInfo := attemptQueuedPodInfo ( q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ) )
1702
+ hpp1QueuedPodInfo := attemptQueuedPodInfo ( q .newQueuedPodInfo (hpp1 ) )
1697
1703
expectInFlightPods (t , q , medPriorityPodInfo .Pod .UID , unschedulablePodInfo .Pod .UID , highPriorityPodInfo .Pod .UID , hpp1 .UID )
1698
1704
err = q .AddUnschedulableIfNotPresent (logger , unschedulableQueuedPodInfo , q .SchedulingCycle ())
1699
1705
if err != nil {
@@ -1757,25 +1763,25 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueueWithOutQueueingHint(t *testi
1757
1763
// To simulate the pod is failed in scheduling in the real world, Pop() the pod from activeQ before AddUnschedulableIfNotPresent()s below.
1758
1764
q .Add (logger , medPriorityPodInfo .Pod )
1759
1765
1760
- err := q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ), q .SchedulingCycle ())
1766
+ err := q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ) ), q .SchedulingCycle ())
1761
1767
if err != nil {
1762
1768
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1763
1769
}
1764
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ), q .SchedulingCycle ())
1770
+ err = q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ) ), q .SchedulingCycle ())
1765
1771
if err != nil {
1766
1772
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1767
1773
}
1768
1774
// Construct a Pod, but don't associate its scheduler failure to any plugin
1769
1775
hpp1 := clonePod (highPriorityPodInfo .Pod , "hpp1" )
1770
1776
// This Pod will go to backoffQ because no failure plugin is associated with it.
1771
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (hpp1 ), q .SchedulingCycle ())
1777
+ err = q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( q .newQueuedPodInfo (hpp1 ) ), q .SchedulingCycle ())
1772
1778
if err != nil {
1773
1779
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1774
1780
}
1775
1781
// Construct another Pod, and associate its scheduler failure to plugin "barPlugin".
1776
1782
hpp2 := clonePod (highPriorityPodInfo .Pod , "hpp2" )
1777
1783
// This Pod will go to the unschedulable Pod pool.
1778
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (hpp2 , "barPlugin" ), q .SchedulingCycle ())
1784
+ err = q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( q .newQueuedPodInfo (hpp2 , "barPlugin" ) ), q .SchedulingCycle ())
1779
1785
if err != nil {
1780
1786
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1781
1787
}
@@ -1803,9 +1809,9 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueueWithOutQueueingHint(t *testi
1803
1809
}
1804
1810
}
1805
1811
1806
- unschedulableQueuedPodInfo := q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" )
1807
- highPriorityQueuedPodInfo := q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" )
1808
- hpp1QueuedPodInfo := q .newQueuedPodInfo (hpp1 )
1812
+ unschedulableQueuedPodInfo := attemptQueuedPodInfo ( q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ) )
1813
+ highPriorityQueuedPodInfo := attemptQueuedPodInfo ( q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ) )
1814
+ hpp1QueuedPodInfo := attemptQueuedPodInfo ( q .newQueuedPodInfo (hpp1 ) )
1809
1815
err = q .AddUnschedulableIfNotPresent (logger , unschedulableQueuedPodInfo , q .SchedulingCycle ())
1810
1816
if err != nil {
1811
1817
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
@@ -2071,11 +2077,11 @@ func TestPriorityQueue_PendingPods(t *testing.T) {
2071
2077
t .Errorf ("Expected: %v after Pop, but got: %v" , highPriorityPodInfo .Pod .Name , p .Pod .Name )
2072
2078
}
2073
2079
q .Add (logger , medPriorityPodInfo .Pod )
2074
- err := q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (unschedulablePodInfo .Pod , "plugin" ), q .SchedulingCycle ())
2080
+ err := q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( q .newQueuedPodInfo (unschedulablePodInfo .Pod , "plugin" ) ), q .SchedulingCycle ())
2075
2081
if err != nil {
2076
2082
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
2077
2083
}
2078
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (highPriorityPodInfo .Pod , "plugin" ), q .SchedulingCycle ())
2084
+ err = q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( q .newQueuedPodInfo (highPriorityPodInfo .Pod , "plugin" ) ), q .SchedulingCycle ())
2079
2085
if err != nil {
2080
2086
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
2081
2087
}
@@ -2720,6 +2726,7 @@ var (
2720
2726
Reason : v1 .PodReasonUnschedulable ,
2721
2727
Message : "fake scheduling failure" ,
2722
2728
})
2729
+ pInfo = attemptQueuedPodInfo (pInfo )
2723
2730
}
2724
2731
queue .unschedulablePods .addOrUpdate (pInfo )
2725
2732
}
@@ -2859,6 +2866,16 @@ func TestPendingPodsMetric(t *testing.T) {
2859
2866
totalWithDelay := 20
2860
2867
pInfosWithDelay := makeQueuedPodInfos (totalWithDelay , "z" , queueable , timestamp .Add (2 * time .Second ))
2861
2868
2869
+ resetPodInfos := func () {
2870
+ // reset PodInfo's Attempts because they influence the backoff time calculation.
2871
+ for i := range pInfos {
2872
+ pInfos [i ].Attempts = 0
2873
+ }
2874
+ for i := range pInfosWithDelay {
2875
+ pInfosWithDelay [i ].Attempts = 0
2876
+ }
2877
+ }
2878
+
2862
2879
tests := []struct {
2863
2880
name string
2864
2881
operations []operation
@@ -3093,6 +3110,7 @@ scheduler_plugin_execution_duration_seconds_count{extension_point="PreEnqueue",p
3093
3110
for _ , test := range tests {
3094
3111
t .Run (test .name , func (t * testing.T ) {
3095
3112
resetMetrics ()
3113
+ resetPodInfos ()
3096
3114
logger , ctx := ktesting .NewTestContext (t )
3097
3115
ctx , cancel := context .WithCancel (ctx )
3098
3116
defer cancel ()
@@ -3465,7 +3483,7 @@ func TestMoveAllToActiveOrBackoffQueue_PreEnqueueChecks(t *testing.T) {
3465
3483
t .Errorf ("Expected: %v after Pop, but got: %v" , podInfo .Pod .Name , p .Pod .Name )
3466
3484
}
3467
3485
podInfo .UnschedulablePlugins = sets .New ("plugin" )
3468
- err := q .AddUnschedulableIfNotPresent (logger , podInfo , q .activeQ .schedulingCycle ())
3486
+ err := q .AddUnschedulableIfNotPresent (logger , attemptQueuedPodInfo ( podInfo ) , q .activeQ .schedulingCycle ())
3469
3487
if err != nil {
3470
3488
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
3471
3489
}
@@ -3870,3 +3888,8 @@ func Test_queuedPodInfo_gatedSetUponCreationAndUnsetUponUpdate(t *testing.T) {
3870
3888
t .Error ("Expected pod to be ungated" )
3871
3889
}
3872
3890
}
3891
+
3892
+ func attemptQueuedPodInfo (podInfo * framework.QueuedPodInfo ) * framework.QueuedPodInfo {
3893
+ podInfo .Attempts ++
3894
+ return podInfo
3895
+ }
0 commit comments