@@ -715,7 +715,7 @@ func Test_InFlightPods(t *testing.T) {
715
715
case action .eventHappens != nil :
716
716
q .MoveAllToActiveOrBackoffQueue (logger , * action .eventHappens , nil , nil , nil )
717
717
case action .podEnqueued != nil :
718
- err := q .AddUnschedulableIfNotPresent (logger , action .podEnqueued , q .SchedulingCycle ())
718
+ err := q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( action .podEnqueued ) , q .SchedulingCycle ())
719
719
if err != nil {
720
720
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
721
721
}
@@ -1062,7 +1062,7 @@ func TestPriorityQueue_Update(t *testing.T) {
1062
1062
name : "when updating a pod which is in unschedulable queue and is backing off, it will be moved to backoff queue" ,
1063
1063
wantQ : backoffQ ,
1064
1064
prepareFunc : func (t * testing.T , logger klog.Logger , q * PriorityQueue ) (oldPod , newPod * v1.Pod ) {
1065
- q .unschedulablePods .addOrUpdate (q .newQueuedPodInfo (medPriorityPodInfo .Pod , queuePlugin ))
1065
+ q .unschedulablePods .addOrUpdate (newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (medPriorityPodInfo .Pod , queuePlugin ) ))
1066
1066
updatedPod := medPriorityPodInfo .Pod .DeepCopy ()
1067
1067
updatedPod .Annotations ["foo" ] = "test"
1068
1068
return medPriorityPodInfo .Pod , updatedPod
@@ -1073,7 +1073,7 @@ func TestPriorityQueue_Update(t *testing.T) {
1073
1073
name : "when updating a pod which is in unschedulable queue and is not backing off, it will be moved to active queue" ,
1074
1074
wantQ : activeQ ,
1075
1075
prepareFunc : func (t * testing.T , logger klog.Logger , q * PriorityQueue ) (oldPod , newPod * v1.Pod ) {
1076
- q .unschedulablePods .addOrUpdate (q .newQueuedPodInfo (medPriorityPodInfo .Pod , queuePlugin ))
1076
+ q .unschedulablePods .addOrUpdate (newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (medPriorityPodInfo .Pod , queuePlugin ) ))
1077
1077
updatedPod := medPriorityPodInfo .Pod .DeepCopy ()
1078
1078
updatedPod .Annotations ["foo" ] = "test1"
1079
1079
// Move clock by podInitialBackoffDuration, so that pods in the unschedulablePods would pass the backing off,
@@ -1217,7 +1217,7 @@ func TestPriorityQueue_UpdateWhenInflight(t *testing.T) {
1217
1217
// test-pod got rejected by fakePlugin,
1218
1218
// but the update event that it just got may change this scheduling result,
1219
1219
// and hence we should put this pod to activeQ/backoffQ.
1220
- err := q .AddUnschedulableIfNotPresent (logger , newQueuedPodInfoForLookup (updatedPod , "fakePlugin" ), q .SchedulingCycle ())
1220
+ err := q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( newQueuedPodInfoForLookup (updatedPod , "fakePlugin" ) ), q .SchedulingCycle ())
1221
1221
if err != nil {
1222
1222
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1223
1223
}
@@ -1567,7 +1567,7 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueueWithQueueingHint(t *testing.
1567
1567
},
1568
1568
{
1569
1569
name : "Queue queues pod to backoffQ if Pod is backing off" ,
1570
- podInfo : & framework.QueuedPodInfo {PodInfo : mustNewPodInfo (p ), UnschedulablePlugins : sets .New ("foo" )},
1570
+ podInfo : & framework.QueuedPodInfo {PodInfo : mustNewPodInfo (p ), Attempts : 1 , UnschedulablePlugins : sets .New ("foo" )},
1571
1571
hint : queueHintReturnQueue ,
1572
1572
expectedQ : backoffQ ,
1573
1573
},
@@ -1598,6 +1598,12 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueueWithQueueingHint(t *testing.
1598
1598
hint : queueHintReturnQueue ,
1599
1599
expectedQ : activeQ ,
1600
1600
},
1601
+ {
1602
+ name : "Pod that experienced a scheduling failure before should be queued to backoffQ after un-gated" ,
1603
+ podInfo : setQueuedPodInfoGated (& framework.QueuedPodInfo {PodInfo : mustNewPodInfo (p ), Attempts : 1 , UnschedulablePlugins : sets .New ("foo" )}),
1604
+ hint : queueHintReturnQueue ,
1605
+ expectedQ : backoffQ ,
1606
+ },
1601
1607
}
1602
1608
1603
1609
for _ , test := range tests {
@@ -1666,11 +1672,11 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueue(t *testing.T) {
1666
1672
t .Errorf ("Expected: %v after Pop, but got: %v" , highPriorityPodInfo .Pod .Name , p .Pod .Name )
1667
1673
}
1668
1674
expectInFlightPods (t , q , unschedulablePodInfo .Pod .UID , highPriorityPodInfo .Pod .UID )
1669
- err := q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ), q .SchedulingCycle ())
1675
+ err := q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ) ), q .SchedulingCycle ())
1670
1676
if err != nil {
1671
1677
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1672
1678
}
1673
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ), q .SchedulingCycle ())
1679
+ err = q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ) ), q .SchedulingCycle ())
1674
1680
if err != nil {
1675
1681
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1676
1682
}
@@ -1683,7 +1689,7 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueue(t *testing.T) {
1683
1689
}
1684
1690
expectInFlightPods (t , q , hpp1 .UID )
1685
1691
// This Pod will go to backoffQ because no failure plugin is associated with it.
1686
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (hpp1 ), q .SchedulingCycle ())
1692
+ err = q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (hpp1 ) ), q .SchedulingCycle ())
1687
1693
if err != nil {
1688
1694
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1689
1695
}
@@ -1696,7 +1702,7 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueue(t *testing.T) {
1696
1702
}
1697
1703
expectInFlightPods (t , q , hpp2 .UID )
1698
1704
// This Pod will go to the unschedulable Pod pool.
1699
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (hpp2 , "barPlugin" ), q .SchedulingCycle ())
1705
+ err = q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (hpp2 , "barPlugin" ) ), q .SchedulingCycle ())
1700
1706
if err != nil {
1701
1707
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1702
1708
}
@@ -1740,9 +1746,9 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueue(t *testing.T) {
1740
1746
if p , err := q .Pop (logger ); err != nil || p .Pod != hpp1 {
1741
1747
t .Errorf ("Expected: %v after Pop, but got: %v" , hpp1 , p .Pod .Name )
1742
1748
}
1743
- unschedulableQueuedPodInfo := q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" )
1744
- highPriorityQueuedPodInfo := q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" )
1745
- hpp1QueuedPodInfo := q .newQueuedPodInfo (hpp1 )
1749
+ unschedulableQueuedPodInfo := newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ) )
1750
+ highPriorityQueuedPodInfo := newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ) )
1751
+ hpp1QueuedPodInfo := newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (hpp1 ) )
1746
1752
expectInFlightPods (t , q , medPriorityPodInfo .Pod .UID , unschedulablePodInfo .Pod .UID , highPriorityPodInfo .Pod .UID , hpp1 .UID )
1747
1753
err = q .AddUnschedulableIfNotPresent (logger , unschedulableQueuedPodInfo , q .SchedulingCycle ())
1748
1754
if err != nil {
@@ -1808,25 +1814,25 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueueWithOutQueueingHint(t *testi
1808
1814
t .Errorf ("add failed: %v" , err )
1809
1815
}
1810
1816
1811
- err := q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ), q .SchedulingCycle ())
1817
+ err := q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ) ), q .SchedulingCycle ())
1812
1818
if err != nil {
1813
1819
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1814
1820
}
1815
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ), q .SchedulingCycle ())
1821
+ err = q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ) ), q .SchedulingCycle ())
1816
1822
if err != nil {
1817
1823
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1818
1824
}
1819
1825
// Construct a Pod, but don't associate its scheduler failure to any plugin
1820
1826
hpp1 := clonePod (highPriorityPodInfo .Pod , "hpp1" )
1821
1827
// This Pod will go to backoffQ because no failure plugin is associated with it.
1822
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (hpp1 ), q .SchedulingCycle ())
1828
+ err = q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (hpp1 ) ), q .SchedulingCycle ())
1823
1829
if err != nil {
1824
1830
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1825
1831
}
1826
1832
// Construct another Pod, and associate its scheduler failure to plugin "barPlugin".
1827
1833
hpp2 := clonePod (highPriorityPodInfo .Pod , "hpp2" )
1828
1834
// This Pod will go to the unschedulable Pod pool.
1829
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (hpp2 , "barPlugin" ), q .SchedulingCycle ())
1835
+ err = q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (hpp2 , "barPlugin" ) ), q .SchedulingCycle ())
1830
1836
if err != nil {
1831
1837
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
1832
1838
}
@@ -1855,9 +1861,9 @@ func TestPriorityQueue_MoveAllToActiveOrBackoffQueueWithOutQueueingHint(t *testi
1855
1861
}
1856
1862
1857
1863
q .schedulingCycle ++
1858
- unschedulableQueuedPodInfo := q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" )
1859
- highPriorityQueuedPodInfo := q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" )
1860
- hpp1QueuedPodInfo := q .newQueuedPodInfo (hpp1 )
1864
+ unschedulableQueuedPodInfo := newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (unschedulablePodInfo .Pod , "fooPlugin" ) )
1865
+ highPriorityQueuedPodInfo := newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (highPriorityPodInfo .Pod , "fooPlugin" ) )
1866
+ hpp1QueuedPodInfo := newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (hpp1 ) )
1861
1867
err = q .AddUnschedulableIfNotPresent (logger , unschedulableQueuedPodInfo , q .SchedulingCycle ())
1862
1868
if err != nil {
1863
1869
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
@@ -2087,11 +2093,11 @@ func TestPriorityQueue_PendingPods(t *testing.T) {
2087
2093
t .Errorf ("Expected: %v after Pop, but got: %v" , highPriorityPodInfo .Pod .Name , p .Pod .Name )
2088
2094
}
2089
2095
q .Add (logger , medPriorityPodInfo .Pod )
2090
- err := q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (unschedulablePodInfo .Pod , "plugin" ), q .SchedulingCycle ())
2096
+ err := q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (unschedulablePodInfo .Pod , "plugin" ) ), q .SchedulingCycle ())
2091
2097
if err != nil {
2092
2098
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
2093
2099
}
2094
- err = q .AddUnschedulableIfNotPresent (logger , q .newQueuedPodInfo (highPriorityPodInfo .Pod , "plugin" ), q .SchedulingCycle ())
2100
+ err = q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( q .newQueuedPodInfo (highPriorityPodInfo .Pod , "plugin" ) ), q .SchedulingCycle ())
2095
2101
if err != nil {
2096
2102
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
2097
2103
}
@@ -2740,6 +2746,7 @@ var (
2740
2746
Reason : v1 .PodReasonUnschedulable ,
2741
2747
Message : "fake scheduling failure" ,
2742
2748
})
2749
+ pInfo = newAttemptedQueuedPodInfo (pInfo )
2743
2750
}
2744
2751
queue .unschedulablePods .addOrUpdate (pInfo )
2745
2752
}
@@ -2884,6 +2891,16 @@ func TestPendingPodsMetric(t *testing.T) {
2884
2891
totalWithDelay := 20
2885
2892
pInfosWithDelay := makeQueuedPodInfos (totalWithDelay , "z" , queueable , timestamp .Add (2 * time .Second ))
2886
2893
2894
+ resetPodInfos := func () {
2895
+ // reset PodInfo's Attempts because they influence the backoff time calculation.
2896
+ for i := range pInfos {
2897
+ pInfos [i ].Attempts = 0
2898
+ }
2899
+ for i := range pInfosWithDelay {
2900
+ pInfosWithDelay [i ].Attempts = 0
2901
+ }
2902
+ }
2903
+
2887
2904
tests := []struct {
2888
2905
name string
2889
2906
operations []operation
@@ -3118,6 +3135,7 @@ scheduler_plugin_execution_duration_seconds_count{extension_point="PreEnqueue",p
3118
3135
for _ , test := range tests {
3119
3136
t .Run (test .name , func (t * testing.T ) {
3120
3137
resetMetrics ()
3138
+ resetPodInfos ()
3121
3139
logger , ctx := ktesting .NewTestContext (t )
3122
3140
ctx , cancel := context .WithCancel (ctx )
3123
3141
defer cancel ()
@@ -3489,7 +3507,7 @@ func TestMoveAllToActiveOrBackoffQueue_PreEnqueueChecks(t *testing.T) {
3489
3507
t .Errorf ("Expected: %v after Pop, but got: %v" , podInfo .Pod .Name , p .Pod .Name )
3490
3508
}
3491
3509
podInfo .UnschedulablePlugins = sets .New ("plugin" )
3492
- err := q .AddUnschedulableIfNotPresent (logger , podInfo , q .schedulingCycle )
3510
+ err := q .AddUnschedulableIfNotPresent (logger , newAttemptedQueuedPodInfo ( podInfo ) , q .schedulingCycle )
3493
3511
if err != nil {
3494
3512
t .Fatalf ("unexpected error from AddUnschedulableIfNotPresent: %v" , err )
3495
3513
}
@@ -3902,3 +3920,8 @@ func Test_queuedPodInfo_gatedSetUponCreationAndUnsetUponUpdate(t *testing.T) {
3902
3920
t .Error ("expected pod to be ungated" )
3903
3921
}
3904
3922
}
3923
+
3924
+ func newAttemptedQueuedPodInfo (podInfo * framework.QueuedPodInfo ) * framework.QueuedPodInfo {
3925
+ podInfo .Attempts ++
3926
+ return podInfo
3927
+ }
0 commit comments