@@ -102,8 +102,10 @@ type PermitPlugin struct {
102
102
timeoutPermit bool
103
103
waitAndRejectPermit bool
104
104
waitAndAllowPermit bool
105
- allowPermit bool
106
105
cancelled bool
106
+ waitingPod string
107
+ rejectingPod string
108
+ allowingPod string
107
109
fh framework.FrameworkHandle
108
110
}
109
111
@@ -406,27 +408,20 @@ func (pp *PermitPlugin) Permit(ctx context.Context, state *framework.CycleState,
406
408
}()
407
409
return framework .NewStatus (framework .Wait , "" ), 3 * time .Second
408
410
}
409
-
410
- if pp .allowPermit && pod .Name != "waiting-pod" {
411
- return nil , 0
412
- }
413
411
if pp .waitAndRejectPermit || pp .waitAndAllowPermit {
414
- if pod .Name == "waiting-pod" {
412
+ if pp .waitingPod == "" || pp .waitingPod == pod .Name {
413
+ pp .waitingPod = pod .Name
415
414
return framework .NewStatus (framework .Wait , "" ), 30 * time .Second
416
415
}
417
- // This is the signalling pod, wait until the waiting-pod is actually waiting and then either reject or allow it.
418
- wait .Poll (10 * time .Millisecond , 30 * time .Second , func () (bool , error ) {
419
- w := false
420
- pp .fh .IterateOverWaitingPods (func (wp framework.WaitingPod ) { w = true })
421
- return w , nil
422
- })
423
416
if pp .waitAndRejectPermit {
417
+ pp .rejectingPod = pod .Name
424
418
pp .fh .IterateOverWaitingPods (func (wp framework.WaitingPod ) {
425
419
wp .Reject (fmt .Sprintf ("reject pod %v" , wp .GetPod ().Name ))
426
420
})
427
421
return framework .NewStatus (framework .Unschedulable , fmt .Sprintf ("reject pod %v" , pod .Name )), 0
428
422
}
429
423
if pp .waitAndAllowPermit {
424
+ pp .allowingPod = pod .Name
430
425
pp .allowAllPods ()
431
426
return nil , 0
432
427
}
@@ -452,8 +447,10 @@ func (pp *PermitPlugin) reset() {
452
447
pp .timeoutPermit = false
453
448
pp .waitAndRejectPermit = false
454
449
pp .waitAndAllowPermit = false
455
- pp .allowPermit = false
456
450
pp .cancelled = false
451
+ pp .waitingPod = ""
452
+ pp .allowingPod = ""
453
+ pp .rejectingPod = ""
457
454
}
458
455
459
456
// newPermitPlugin returns a factory for permit plugin with specified PermitPlugin.
@@ -1300,6 +1297,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
1300
1297
registry , prof := initRegistryAndConfig (permitPlugin )
1301
1298
1302
1299
// Create the master and the scheduler with the test plugin set.
1300
+ // TODO Make the subtests not share scheduler instances.
1303
1301
testCtx := initTestSchedulerForFrameworkTest (t , testutils .InitTestMaster (t , "permit-plugin" , nil ), 2 ,
1304
1302
scheduler .WithProfiles (prof ),
1305
1303
scheduler .WithFrameworkOutOfTreeRegistry (registry ))
@@ -1326,31 +1324,42 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
1326
1324
permitPlugin .waitAndRejectPermit = test .waitReject
1327
1325
permitPlugin .waitAndAllowPermit = test .waitAllow
1328
1326
1329
- // Create two pods.
1330
- waitingPod , err := createPausePod (testCtx .ClientSet ,
1331
- initPausePod (testCtx .ClientSet , & pausePodConfig {Name : "waiting-pod" , Namespace : testCtx .NS .Name }))
1327
+ // Create two pods. First pod to enter Permit() will wait and a second one will either
1328
+ // reject or allow first one.
1329
+ podA , err := createPausePod (testCtx .ClientSet ,
1330
+ initPausePod (testCtx .ClientSet , & pausePodConfig {Name : "pod-a" , Namespace : testCtx .NS .Name }))
1332
1331
if err != nil {
1333
- t .Errorf ("Error while creating the waiting pod: %v" , err )
1332
+ t .Errorf ("Error while creating the first pod: %v" , err )
1334
1333
}
1335
- signallingPod , err := createPausePod (testCtx .ClientSet ,
1336
- initPausePod (testCtx .ClientSet , & pausePodConfig {Name : "signalling- pod" , Namespace : testCtx .NS .Name }))
1334
+ podB , err := createPausePod (testCtx .ClientSet ,
1335
+ initPausePod (testCtx .ClientSet , & pausePodConfig {Name : "pod-b " , Namespace : testCtx .NS .Name }))
1337
1336
if err != nil {
1338
- t .Errorf ("Error while creating the signalling pod: %v" , err )
1337
+ t .Errorf ("Error while creating the second pod: %v" , err )
1339
1338
}
1340
1339
1341
1340
if test .waitReject {
1342
- if err = waitForPodUnschedulable (testCtx .ClientSet , waitingPod ); err != nil {
1343
- t .Errorf ("test #%v: Didn't expect the waiting pod to be scheduled. error: %v" , i , err )
1341
+ if err = waitForPodUnschedulable (testCtx .ClientSet , podA ); err != nil {
1342
+ t .Errorf ("test #%v: Didn't expect the first pod to be scheduled. error: %v" , i , err )
1344
1343
}
1345
- if err = waitForPodUnschedulable (testCtx .ClientSet , signallingPod ); err != nil {
1346
- t .Errorf ("test #%v: Didn't expect the signalling pod to be scheduled. error: %v" , i , err )
1344
+ if err = waitForPodUnschedulable (testCtx .ClientSet , podB ); err != nil {
1345
+ t .Errorf ("test #%v: Didn't expect the second pod to be scheduled. error: %v" , i , err )
1346
+ }
1347
+ if ! ((permitPlugin .waitingPod == podA .Name && permitPlugin .rejectingPod == podB .Name ) ||
1348
+ (permitPlugin .waitingPod == podB .Name && permitPlugin .rejectingPod == podA .Name )) {
1349
+ t .Errorf ("test #%v: Expect one pod to wait and another pod to reject instead %s waited and %s rejected." ,
1350
+ i , permitPlugin .waitingPod , permitPlugin .rejectingPod )
1347
1351
}
1348
1352
} else {
1349
- if err = testutils .WaitForPodToSchedule (testCtx .ClientSet , waitingPod ); err != nil {
1350
- t .Errorf ("test #%v: Expected the waiting pod to be scheduled. error: %v" , i , err )
1353
+ if err = testutils .WaitForPodToSchedule (testCtx .ClientSet , podA ); err != nil {
1354
+ t .Errorf ("test #%v: Expected the first pod to be scheduled. error: %v" , i , err )
1355
+ }
1356
+ if err = testutils .WaitForPodToSchedule (testCtx .ClientSet , podB ); err != nil {
1357
+ t .Errorf ("test #%v: Expected the second pod to be scheduled. error: %v" , i , err )
1351
1358
}
1352
- if err = testutils .WaitForPodToSchedule (testCtx .ClientSet , signallingPod ); err != nil {
1353
- t .Errorf ("test #%v: Expected the signalling pod to be scheduled. error: %v" , i , err )
1359
+ if ! ((permitPlugin .waitingPod == podA .Name && permitPlugin .allowingPod == podB .Name ) ||
1360
+ (permitPlugin .waitingPod == podB .Name && permitPlugin .allowingPod == podA .Name )) {
1361
+ t .Errorf ("test #%v: Expect one pod to wait and another pod to allow instead %s waited and %s allowed." ,
1362
+ i , permitPlugin .waitingPod , permitPlugin .allowingPod )
1354
1363
}
1355
1364
}
1356
1365
@@ -1359,7 +1368,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
1359
1368
}
1360
1369
1361
1370
permitPlugin .reset ()
1362
- testutils .CleanupPods (testCtx .ClientSet , t , []* v1.Pod {waitingPod , signallingPod })
1371
+ testutils .CleanupPods (testCtx .ClientSet , t , []* v1.Pod {podA , podB })
1363
1372
}
1364
1373
}
1365
1374
@@ -1499,15 +1508,14 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
1499
1508
permitPlugin .timeoutPermit = false
1500
1509
permitPlugin .waitAndRejectPermit = false
1501
1510
permitPlugin .waitAndAllowPermit = true
1502
- permitPlugin .allowPermit = true
1503
1511
1504
1512
lowPriority , highPriority := int32 (100 ), int32 (300 )
1505
1513
resourceRequest := v1.ResourceRequirements {Requests : v1.ResourceList {
1506
1514
v1 .ResourceCPU : * resource .NewMilliQuantity (400 , resource .DecimalSI ),
1507
1515
v1 .ResourceMemory : * resource .NewQuantity (400 , resource .DecimalSI )},
1508
1516
}
1509
1517
1510
- // Create two pods .
1518
+ // First pod will go waiting .
1511
1519
waitingPod := initPausePod (testCtx .ClientSet , & pausePodConfig {Name : "waiting-pod" , Namespace : testCtx .NS .Name , Priority : & lowPriority , Resources : & resourceRequest })
1512
1520
waitingPod .Spec .TerminationGracePeriodSeconds = new (int64 )
1513
1521
waitingPod , err = createPausePod (testCtx .ClientSet , waitingPod )
@@ -1521,6 +1529,7 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
1521
1529
return w , nil
1522
1530
})
1523
1531
1532
+ // Create second pod which should preempt first pod.
1524
1533
preemptorPod , err := createPausePod (testCtx .ClientSet ,
1525
1534
initPausePod (testCtx .ClientSet , & pausePodConfig {Name : "preemptor-pod" , Namespace : testCtx .NS .Name , Priority : & highPriority , Resources : & resourceRequest }))
1526
1535
if err != nil {
0 commit comments