@@ -1262,45 +1262,9 @@ func TestBindPlugin(t *testing.T) {
1262
1262
1263
1263
// TestPostBindPlugin tests invocation of postbind plugins.
1264
1264
func TestPostBindPlugin (t * testing.T ) {
1265
- // Create a plugin registry for testing. Register a prebind and a postbind plugin.
1266
- preBindPlugin := & PreBindPlugin {}
1267
- postBindPlugin := & PostBindPlugin {name : postBindPluginName }
1268
- registry := frameworkruntime.Registry {
1269
- preBindPluginName : newPlugin (preBindPlugin ),
1270
- postBindPluginName : newPlugin (postBindPlugin ),
1271
- }
1272
-
1273
- // Setup initial prebind and postbind plugin for testing.
1274
- prof := schedulerconfig.KubeSchedulerProfile {
1275
- SchedulerName : v1 .DefaultSchedulerName ,
1276
- Plugins : & schedulerconfig.Plugins {
1277
- PreBind : & schedulerconfig.PluginSet {
1278
- Enabled : []schedulerconfig.Plugin {
1279
- {
1280
- Name : preBindPluginName ,
1281
- },
1282
- },
1283
- },
1284
- PostBind : & schedulerconfig.PluginSet {
1285
- Enabled : []schedulerconfig.Plugin {
1286
- {
1287
- Name : postBindPluginName ,
1288
- },
1289
- },
1290
- },
1291
- },
1292
- }
1293
-
1294
- // Create the master and the scheduler with the test plugin set.
1295
- testCtx := initTestSchedulerForFrameworkTest (t , testutils .InitTestMaster (t , "postbind-plugin" , nil ), 2 ,
1296
- scheduler .WithProfiles (prof ),
1297
- scheduler .WithFrameworkOutOfTreeRegistry (registry ))
1298
- defer testutils .CleanupTest (t , testCtx )
1299
-
1300
1265
tests := []struct {
1301
- name string
1302
- preBindFail bool
1303
- preBindReject bool
1266
+ name string
1267
+ preBindFail bool
1304
1268
}{
1305
1269
{
1306
1270
name : "plugin preBind fail" ,
@@ -1314,7 +1278,46 @@ func TestPostBindPlugin(t *testing.T) {
1314
1278
1315
1279
for _ , test := range tests {
1316
1280
t .Run (test .name , func (t * testing.T ) {
1317
- preBindPlugin .failPreBind = test .preBindFail
1281
+ // Create a plugin registry for testing. Register a prebind and a postbind plugin.
1282
+ preBindPlugin := & PreBindPlugin {
1283
+ failPreBind : test .preBindFail ,
1284
+ }
1285
+ postBindPlugin := & PostBindPlugin {
1286
+ name : postBindPluginName ,
1287
+ pluginInvokeEventChan : make (chan pluginInvokeEvent , 1 ),
1288
+ }
1289
+ registry := frameworkruntime.Registry {
1290
+ preBindPluginName : newPlugin (preBindPlugin ),
1291
+ postBindPluginName : newPlugin (postBindPlugin ),
1292
+ }
1293
+
1294
+ // Setup initial prebind and postbind plugin for testing.
1295
+ prof := schedulerconfig.KubeSchedulerProfile {
1296
+ SchedulerName : v1 .DefaultSchedulerName ,
1297
+ Plugins : & schedulerconfig.Plugins {
1298
+ PreBind : & schedulerconfig.PluginSet {
1299
+ Enabled : []schedulerconfig.Plugin {
1300
+ {
1301
+ Name : preBindPluginName ,
1302
+ },
1303
+ },
1304
+ },
1305
+ PostBind : & schedulerconfig.PluginSet {
1306
+ Enabled : []schedulerconfig.Plugin {
1307
+ {
1308
+ Name : postBindPluginName ,
1309
+ },
1310
+ },
1311
+ },
1312
+ },
1313
+ }
1314
+
1315
+ // Create the master and the scheduler with the test plugin set.
1316
+ testCtx := initTestSchedulerForFrameworkTest (t , testutils .InitTestMaster (t , "postbind-plugin" , nil ), 2 ,
1317
+ scheduler .WithProfiles (prof ),
1318
+ scheduler .WithFrameworkOutOfTreeRegistry (registry ))
1319
+ defer testutils .CleanupTest (t , testCtx )
1320
+
1318
1321
// Create a best effort pod.
1319
1322
pod , err := createPausePod (testCtx .ClientSet ,
1320
1323
initPausePod (& pausePodConfig {Name : "test-pod" , Namespace : testCtx .NS .Name }))
@@ -1333,13 +1336,16 @@ func TestPostBindPlugin(t *testing.T) {
1333
1336
if err = testutils .WaitForPodToSchedule (testCtx .ClientSet , pod ); err != nil {
1334
1337
t .Errorf ("Expected the pod to be scheduled. error: %v" , err )
1335
1338
}
1339
+ select {
1340
+ case <- postBindPlugin .pluginInvokeEventChan :
1341
+ case <- time .After (time .Second * 15 ):
1342
+ t .Errorf ("pluginInvokeEventChan timed out" )
1343
+ }
1336
1344
if postBindPlugin .numPostBindCalled == 0 {
1337
1345
t .Errorf ("Expected the postbind plugin to be called, was called %d times." , postBindPlugin .numPostBindCalled )
1338
1346
}
1339
1347
}
1340
1348
1341
- postBindPlugin .reset ()
1342
- preBindPlugin .reset ()
1343
1349
testutils .CleanupPods (testCtx .ClientSet , t , []* v1.Pod {pod })
1344
1350
})
1345
1351
}
0 commit comments