Skip to content

Commit d7e7136

Browse files
authored
Merge pull request kubernetes#88563 from mateuszlitwin/mlitwin-fix-permit-integration-test
fix TestCoSchedulinngWithPermitPlugin and test PermitPlugin
2 parents e865c0b + b93e3d1 commit d7e7136

File tree

1 file changed

+40
-31
lines changed

1 file changed

+40
-31
lines changed

test/integration/scheduler/framework_test.go

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@ type PermitPlugin struct {
102102
timeoutPermit bool
103103
waitAndRejectPermit bool
104104
waitAndAllowPermit bool
105-
allowPermit bool
106105
cancelled bool
106+
waitingPod string
107+
rejectingPod string
108+
allowingPod string
107109
fh framework.FrameworkHandle
108110
}
109111

@@ -406,27 +408,20 @@ func (pp *PermitPlugin) Permit(ctx context.Context, state *framework.CycleState,
406408
}()
407409
return framework.NewStatus(framework.Wait, ""), 3 * time.Second
408410
}
409-
410-
if pp.allowPermit && pod.Name != "waiting-pod" {
411-
return nil, 0
412-
}
413411
if pp.waitAndRejectPermit || pp.waitAndAllowPermit {
414-
if pod.Name == "waiting-pod" {
412+
if pp.waitingPod == "" || pp.waitingPod == pod.Name {
413+
pp.waitingPod = pod.Name
415414
return framework.NewStatus(framework.Wait, ""), 30 * time.Second
416415
}
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-
})
423416
if pp.waitAndRejectPermit {
417+
pp.rejectingPod = pod.Name
424418
pp.fh.IterateOverWaitingPods(func(wp framework.WaitingPod) {
425419
wp.Reject(fmt.Sprintf("reject pod %v", wp.GetPod().Name))
426420
})
427421
return framework.NewStatus(framework.Unschedulable, fmt.Sprintf("reject pod %v", pod.Name)), 0
428422
}
429423
if pp.waitAndAllowPermit {
424+
pp.allowingPod = pod.Name
430425
pp.allowAllPods()
431426
return nil, 0
432427
}
@@ -452,8 +447,10 @@ func (pp *PermitPlugin) reset() {
452447
pp.timeoutPermit = false
453448
pp.waitAndRejectPermit = false
454449
pp.waitAndAllowPermit = false
455-
pp.allowPermit = false
456450
pp.cancelled = false
451+
pp.waitingPod = ""
452+
pp.allowingPod = ""
453+
pp.rejectingPod = ""
457454
}
458455

459456
// newPermitPlugin returns a factory for permit plugin with specified PermitPlugin.
@@ -1300,6 +1297,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
13001297
registry, prof := initRegistryAndConfig(permitPlugin)
13011298

13021299
// Create the master and the scheduler with the test plugin set.
1300+
// TODO Make the subtests not share scheduler instances.
13031301
testCtx := initTestSchedulerForFrameworkTest(t, testutils.InitTestMaster(t, "permit-plugin", nil), 2,
13041302
scheduler.WithProfiles(prof),
13051303
scheduler.WithFrameworkOutOfTreeRegistry(registry))
@@ -1326,31 +1324,42 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
13261324
permitPlugin.waitAndRejectPermit = test.waitReject
13271325
permitPlugin.waitAndAllowPermit = test.waitAllow
13281326

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}))
13321331
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)
13341333
}
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}))
13371336
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)
13391338
}
13401339

13411340
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)
13441343
}
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)
13471351
}
13481352
} 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)
13511358
}
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)
13541363
}
13551364
}
13561365

@@ -1359,7 +1368,7 @@ func TestCoSchedulingWithPermitPlugin(t *testing.T) {
13591368
}
13601369

13611370
permitPlugin.reset()
1362-
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{waitingPod, signallingPod})
1371+
testutils.CleanupPods(testCtx.ClientSet, t, []*v1.Pod{podA, podB})
13631372
}
13641373
}
13651374

@@ -1499,15 +1508,14 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
14991508
permitPlugin.timeoutPermit = false
15001509
permitPlugin.waitAndRejectPermit = false
15011510
permitPlugin.waitAndAllowPermit = true
1502-
permitPlugin.allowPermit = true
15031511

15041512
lowPriority, highPriority := int32(100), int32(300)
15051513
resourceRequest := v1.ResourceRequirements{Requests: v1.ResourceList{
15061514
v1.ResourceCPU: *resource.NewMilliQuantity(400, resource.DecimalSI),
15071515
v1.ResourceMemory: *resource.NewQuantity(400, resource.DecimalSI)},
15081516
}
15091517

1510-
// Create two pods.
1518+
// First pod will go waiting.
15111519
waitingPod := initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "waiting-pod", Namespace: testCtx.NS.Name, Priority: &lowPriority, Resources: &resourceRequest})
15121520
waitingPod.Spec.TerminationGracePeriodSeconds = new(int64)
15131521
waitingPod, err = createPausePod(testCtx.ClientSet, waitingPod)
@@ -1521,6 +1529,7 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
15211529
return w, nil
15221530
})
15231531

1532+
// Create second pod which should preempt first pod.
15241533
preemptorPod, err := createPausePod(testCtx.ClientSet,
15251534
initPausePod(testCtx.ClientSet, &pausePodConfig{Name: "preemptor-pod", Namespace: testCtx.NS.Name, Priority: &highPriority, Resources: &resourceRequest}))
15261535
if err != nil {

0 commit comments

Comments
 (0)