Skip to content

Commit 5f4adaf

Browse files
authored
Merge pull request kubernetes#136303 from ShaanveerS/fix-flake
scheduler: deflake TestUnReservePreBindPlugins
2 parents 3863ed8 + 42b16a8 commit 5f4adaf

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

test/integration/scheduler/plugins/plugins_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ type PreEnqueuePlugin struct {
9292
admit bool
9393
}
9494

95+
type PreEnqueueGateAfterPreBindPlugin struct {
96+
preBind *PreBindPlugin
97+
}
98+
9599
type PreFilterPlugin struct {
96100
numPreFilterCalled atomic.Int64
97101
failPreFilter bool
@@ -306,6 +310,7 @@ const (
306310
preBindPluginName = "prebind-plugin"
307311
postBindPluginName = "postbind-plugin"
308312
permitPluginName = "permit-plugin"
313+
preEnqueueGatePluginName = "preenqueue-gate-plugin"
309314
)
310315

311316
var _ fwk.PreEnqueuePlugin = &PreEnqueuePlugin{}
@@ -326,6 +331,7 @@ var _ fwk.PostBindPlugin = &PostBindPlugin{}
326331
var _ fwk.PermitPlugin = &PermitPlugin{}
327332
var _ fwk.EnqueueExtensions = &PermitPlugin{}
328333
var _ fwk.QueueSortPlugin = &QueueSortPlugin{}
334+
var _ fwk.PreEnqueuePlugin = &PreEnqueueGateAfterPreBindPlugin{}
329335

330336
func (ep *QueueSortPlugin) Name() string {
331337
return queuesortPluginName
@@ -521,6 +527,16 @@ func (pp *PreBindPlugin) EventsToRegister(_ context.Context) ([]fwk.ClusterEvent
521527
return nil, nil
522528
}
523529

530+
func (pp *PreBindPlugin) hasTriedPreBind(uid types.UID) bool {
531+
pp.mutex.Lock()
532+
defer pp.mutex.Unlock()
533+
if pp.podUIDs == nil {
534+
return false
535+
}
536+
_, ok := pp.podUIDs[uid]
537+
return ok
538+
}
539+
524540
const bindPluginAnnotation = "bindPluginName"
525541

526542
func (bp *BindPlugin) Name() string {
@@ -691,6 +707,19 @@ func (pp *PermitPlugin) EventsToRegister(_ context.Context) ([]fwk.ClusterEventW
691707
return nil, nil
692708
}
693709

710+
// Name returns name of the plugin.
711+
func (pl *PreEnqueueGateAfterPreBindPlugin) Name() string {
712+
return preEnqueueGatePluginName
713+
}
714+
715+
// PreEnqueue is a test function that blocks re-enqueue after PreBind was attempted.
716+
func (pl *PreEnqueueGateAfterPreBindPlugin) PreEnqueue(ctx context.Context, p *v1.Pod) *fwk.Status {
717+
if pl.preBind != nil && pl.preBind.hasTriedPreBind(p.UID) {
718+
return fwk.NewStatus(fwk.UnschedulableAndUnresolvable, "test gate: block re-enqueue after PreBind was attempted")
719+
}
720+
return nil
721+
}
722+
694723
// TestPreFilterPlugin tests invocation of prefilter plugins.
695724
func TestPreFilterPlugin(t *testing.T) {
696725
testContext := testutils.InitTestAPIServer(t, "prefilter-plugin", nil)
@@ -1590,7 +1619,8 @@ func TestUnReservePreBindPlugins(t *testing.T) {
15901619
name: "reservePlugin",
15911620
failReserve: false,
15921621
}
1593-
registry, profile := initRegistryAndConfig(t, []fwk.Plugin{test.plugin, reservePlugin}...)
1622+
requeueGate := &PreEnqueueGateAfterPreBindPlugin{preBind: test.plugin}
1623+
registry, profile := initRegistryAndConfig(t, []fwk.Plugin{requeueGate, test.plugin, reservePlugin}...)
15941624

15951625
testCtx, teardown := schedulerutils.InitTestSchedulerForFrameworkTest(t, testContext, 2, true,
15961626
scheduler.WithProfiles(profile),

0 commit comments

Comments
 (0)