@@ -318,6 +318,10 @@ var (
318
318
OwnerReference (podName , podUID + "-other" , podKind ).
319
319
UID ("other" ).
320
320
Obj ()
321
+ unscheduledPodWithClaimName = st .MakePod ().Name (podName ).Namespace (namespace ).
322
+ UID (podUID ).
323
+ PodResourceClaims (v1.PodResourceClaim {Name : resourceName , ResourceClaimName : & claimName }).
324
+ Obj ()
321
325
podWithClaimName = st .MakePod ().Name (podName ).Namespace (namespace ).
322
326
UID (podUID ).
323
327
PodResourceClaims (v1.PodResourceClaim {Name : resourceName , ResourceClaimName : & claimName }).
@@ -494,6 +498,23 @@ func TestHandlers(t *testing.T) {
494
498
// At the moment, the code reliably cancels right away.
495
499
wantEvents : []* v1.Event {cancelPodEviction },
496
500
},
501
+ "evict-pod-after-scheduling" : {
502
+ initialState : state {
503
+ pods : []* v1.Pod {unscheduledPodWithClaimName },
504
+ slices : []* resourceapi.ResourceSlice {sliceTainted , slice2 },
505
+ allocatedClaims : []allocatedClaim {{ResourceClaim : inUseClaim , evictionTime : & taintTime }},
506
+ },
507
+ events : []any {
508
+ // Normally the scheduler shouldn't schedule when there is a taint,
509
+ // but perhaps it didn't know yet.
510
+ update (unscheduledPodWithClaimName , podWithClaimName ),
511
+ },
512
+ finalState : state {
513
+ slices : []* resourceapi.ResourceSlice {sliceTainted , slice2 },
514
+ allocatedClaims : []allocatedClaim {{ResourceClaim : inUseClaim , evictionTime : & taintTime }},
515
+ evicting : []evictAt {{newObject (podWithClaimName ), taintTime .Time }},
516
+ },
517
+ },
497
518
"evict-pod-resourceclaim-unrelated-changes" : {
498
519
initialState : state {
499
520
pods : []* v1.Pod {podWithClaimName },
@@ -1339,22 +1360,22 @@ func TestEviction(t *testing.T) {
1339
1360
wg .Add (1 )
1340
1361
go func () {
1341
1362
defer wg .Done ()
1342
- controller .Run (tCtx )
1363
+ assert . NoError ( tCtx , controller .Run (tCtx ), "eviction controller failed" )
1343
1364
}()
1344
1365
1345
1366
// Eventually the controller should have synced it's informers.
1346
- require .Eventually (tCtx , func () bool {
1367
+ ktesting .Eventually (tCtx , func (tCtx ktesting. TContext ) bool {
1347
1368
return controller .hasSynced .Load () > 0
1348
- }, 30 * time .Second , time . Millisecond , "controller synced" )
1369
+ }). WithTimeout ( 30 * time .Second ). Should ( gomega . BeTrueBecause ( "controller synced" ) )
1349
1370
if tt .afterSync != nil {
1350
1371
tt .afterSync (tCtx )
1351
1372
}
1352
1373
1353
1374
// Eventually the pod gets deleted (= evicted).
1354
- assert .Eventually (tCtx , func () bool {
1375
+ ktesting .Eventually (tCtx , func (tCtx ktesting. TContext ) bool {
1355
1376
_ , err := fakeClientset .CoreV1 ().Pods (pod .Namespace ).Get (tCtx , pod .Name , metav1.GetOptions {})
1356
1377
return apierrors .IsNotFound (err )
1357
- }, 30 * time .Second , time . Millisecond , "pod evicted" )
1378
+ }). WithTimeout ( 30 * time .Second ). Should ( gomega . BeTrueBecause ( "pod evicted" ) )
1358
1379
1359
1380
pod := pod .DeepCopy ()
1360
1381
pod .Status .Conditions = []v1.PodCondition {{
@@ -1369,7 +1390,10 @@ func TestEviction(t *testing.T) {
1369
1390
1370
1391
// Shortly after deletion we should also see updated metrics.
1371
1392
// This is the last thing the controller does for a pod.
1393
+ // However, actually creating the event on the server is asynchronous,
1394
+ // so we also have to wait for that.
1372
1395
ktesting .Eventually (tCtx , func (tCtx ktesting.TContext ) error {
1396
+ gomega .NewWithT (tCtx ).Expect (listEvents (tCtx )).Should (matchDeletionEvent ())
1373
1397
return testPodDeletionsMetrics (controller , 1 )
1374
1398
}).WithTimeout (30 * time .Second ).Should (gomega .Succeed (), "pod eviction done" )
1375
1399
@@ -1450,7 +1474,7 @@ func testCancelEviction(tCtx ktesting.TContext, deletePod bool) {
1450
1474
wg .Add (1 )
1451
1475
go func () {
1452
1476
defer wg .Done ()
1453
- controller .Run (tCtx )
1477
+ assert . NoError ( tCtx , controller .Run (tCtx ), "eviction controller failed" )
1454
1478
}()
1455
1479
1456
1480
// Eventually the pod gets scheduled for eviction.
@@ -1543,15 +1567,15 @@ func TestParallelPodDeletion(t *testing.T) {
1543
1567
wg .Add (1 )
1544
1568
go func () {
1545
1569
defer wg .Done ()
1546
- controller .Run (tCtx )
1570
+ assert . NoError ( tCtx , controller .Run (tCtx ), "eviction controller failed" )
1547
1571
}()
1548
1572
1549
1573
// Eventually the pod gets deleted, in this test by us.
1550
- assert .Eventually (tCtx , func () bool {
1574
+ ktesting .Eventually (tCtx , func (tCtx ktesting. TContext ) bool {
1551
1575
mutex .Lock ()
1552
1576
defer mutex .Unlock ()
1553
1577
return podGets >= 1
1554
- }, 30 * time .Second , time . Millisecond , "pod eviction started" )
1578
+ }). WithTimeout ( 30 * time .Second ). Should ( gomega . BeTrueBecause ( "pod eviction started" ) )
1555
1579
1556
1580
// We don't want any events.
1557
1581
ktesting .Consistently (tCtx , func (tCtx ktesting.TContext ) error {
@@ -1622,11 +1646,12 @@ func TestRetry(t *testing.T) {
1622
1646
wg .Add (1 )
1623
1647
go func () {
1624
1648
defer wg .Done ()
1625
- controller .Run (tCtx )
1649
+ assert . NoError ( tCtx , controller .Run (tCtx ), "eviction controller failed" )
1626
1650
}()
1627
1651
1628
- // Eventually the pod gets deleted.
1652
+ // Eventually the pod gets deleted and the event is recorded .
1629
1653
ktesting .Eventually (tCtx , func (tCtx ktesting.TContext ) error {
1654
+ gomega .NewWithT (tCtx ).Expect (listEvents (tCtx )).Should (matchDeletionEvent ())
1630
1655
return testPodDeletionsMetrics (controller , 1 )
1631
1656
}).WithTimeout (30 * time .Second ).Should (gomega .Succeed (), "pod eviction done" )
1632
1657
@@ -1694,15 +1719,15 @@ func TestEvictionFailure(t *testing.T) {
1694
1719
wg .Add (1 )
1695
1720
go func () {
1696
1721
defer wg .Done ()
1697
- controller .Run (tCtx )
1722
+ assert . NoError ( tCtx , controller .Run (tCtx ), "eviction controller failed" )
1698
1723
}()
1699
1724
1700
1725
// Eventually deletion is attempted a few times.
1701
- assert .Eventually (tCtx , func () bool {
1726
+ ktesting .Eventually (tCtx , func (tCtx ktesting. TContext ) int {
1702
1727
mutex .Lock ()
1703
1728
defer mutex .Unlock ()
1704
- return podDeletions >= retries
1705
- }, 30 * time .Second , time . Millisecond , "pod eviction failed" )
1729
+ return podDeletions
1730
+ }). WithTimeout ( 30 * time .Second ). Should ( gomega . BeNumerically ( ">=" , retries ) , "pod eviction failed" )
1706
1731
1707
1732
// Now we can check the API calls.
1708
1733
ktesting .Consistently (tCtx , func (tCtx ktesting.TContext ) error {
0 commit comments