Skip to content

Commit 438debf

Browse files
authored
Merge pull request kubernetes#91057 from ingvagabund/start-informers-outside-of-InitTestScheduler
integration: start informer and scheduler outside of InitTestScheduler
2 parents 7580666 + 65e9826 commit 438debf

File tree

8 files changed

+47
-20
lines changed

8 files changed

+47
-20
lines changed

test/integration/node/lifecycle_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,14 @@ func TestTaintBasedEvictions(t *testing.T) {
161161
return
162162
}
163163

164-
go nc.Run(testCtx.Ctx.Done())
165-
166-
// Waiting for all controller sync.
164+
// Waiting for all controllers to sync
167165
externalInformers.Start(testCtx.Ctx.Done())
168166
externalInformers.WaitForCacheSync(testCtx.Ctx.Done())
169-
testCtx.InformerFactory.Start(testCtx.Ctx.Done())
170-
testCtx.InformerFactory.WaitForCacheSync(testCtx.Ctx.Done())
167+
testutils.SyncInformerFactory(testCtx)
168+
169+
// Run all controllers
170+
go nc.Run(testCtx.Ctx.Done())
171+
go testCtx.Scheduler.Run(testCtx.Ctx)
171172

172173
nodeRes := v1.ResourceList{
173174
v1.ResourceCPU: resource.MustParse("4000m"),

test/integration/scheduler/extender_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ func TestSchedulerExtender(t *testing.T) {
351351
policy.APIVersion = "v1"
352352

353353
testCtx = testutils.InitTestScheduler(t, testCtx, false, &policy)
354+
testutils.SyncInformerFactory(testCtx)
355+
go testCtx.Scheduler.Run(testCtx.Ctx)
354356
defer testutils.CleanupTest(t, testCtx)
355357

356358
DoTestPodScheduling(testCtx.NS, t, clientSet)

test/integration/scheduler/framework_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,10 +892,12 @@ func TestBindPlugin(t *testing.T) {
892892
},
893893
}
894894

895-
// Create the master and the scheduler with the test plugin set.
895+
// Create the scheduler with the test plugin set.
896896
testCtx := testutils.InitTestSchedulerWithOptions(t, testContext, false, nil, time.Second,
897897
scheduler.WithProfiles(prof),
898898
scheduler.WithFrameworkOutOfTreeRegistry(registry))
899+
testutils.SyncInformerFactory(testCtx)
900+
go testCtx.Scheduler.Run(testCtx.Ctx)
899901
defer testutils.CleanupTest(t, testCtx)
900902

901903
// Add a few nodes.
@@ -1552,14 +1554,17 @@ func TestPreemptWithPermitPlugin(t *testing.T) {
15521554
}
15531555

15541556
func initTestSchedulerForFrameworkTest(t *testing.T, testCtx *testutils.TestContext, nodeCount int, opts ...scheduler.Option) *testutils.TestContext {
1555-
c := testutils.InitTestSchedulerWithOptions(t, testCtx, false, nil, time.Second, opts...)
1557+
testCtx = testutils.InitTestSchedulerWithOptions(t, testCtx, false, nil, time.Second, opts...)
1558+
testutils.SyncInformerFactory(testCtx)
1559+
go testCtx.Scheduler.Run(testCtx.Ctx)
1560+
15561561
if nodeCount > 0 {
1557-
_, err := createNodes(c.ClientSet, "test-node", nil, nodeCount)
1562+
_, err := createNodes(testCtx.ClientSet, "test-node", nil, nodeCount)
15581563
if err != nil {
15591564
t.Fatalf("Cannot create nodes: %v", err)
15601565
}
15611566
}
1562-
return c
1567+
return testCtx
15631568
}
15641569

15651570
// initRegistryAndConfig returns registry and plugins config based on give plugins.

test/integration/scheduler/preemption_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ func TestPreemption(t *testing.T) {
148148
false, nil, time.Second,
149149
scheduler.WithProfiles(prof),
150150
scheduler.WithFrameworkOutOfTreeRegistry(registry))
151+
testutils.SyncInformerFactory(testCtx)
152+
go testCtx.Scheduler.Run(testCtx.Ctx)
151153

152154
defer testutils.CleanupTest(t, testCtx)
153155
cs := testCtx.ClientSet
@@ -527,9 +529,15 @@ func TestPodPriorityResolution(t *testing.T) {
527529
externalInformers := informers.NewSharedInformerFactory(externalClientset, time.Second)
528530
admission.SetExternalKubeClientSet(externalClientset)
529531
admission.SetExternalKubeInformerFactory(externalInformers)
532+
533+
// Waiting for all controllers to sync
534+
testutils.SyncInformerFactory(testCtx)
530535
externalInformers.Start(testCtx.Ctx.Done())
531536
externalInformers.WaitForCacheSync(testCtx.Ctx.Done())
532537

538+
// Run all controllers
539+
go testCtx.Scheduler.Run(testCtx.Ctx)
540+
533541
tests := []struct {
534542
Name string
535543
PriorityClass string

test/integration/scheduler/scheduler_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ func TestMultipleSchedulers(t *testing.T) {
539539
// 5. create and start a scheduler with name "foo-scheduler"
540540
fooProf := kubeschedulerconfig.KubeSchedulerProfile{SchedulerName: fooScheduler}
541541
testCtx = testutils.InitTestSchedulerWithOptions(t, testCtx, true, nil, time.Second, scheduler.WithProfiles(fooProf))
542+
testutils.SyncInformerFactory(testCtx)
543+
go testCtx.Scheduler.Run(testCtx.Ctx)
542544

543545
// 6. **check point-2**:
544546
// - testPodWithAnnotationFitsFoo should be scheduled

test/integration/scheduler/taint_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ func TestTaintNodeByCondition(t *testing.T) {
102102
t.Errorf("Failed to create node controller: %v", err)
103103
return
104104
}
105-
go nc.Run(testCtx.Ctx.Done())
106105

107-
// Waiting for all controller sync.
106+
// Waiting for all controllers to sync
108107
externalInformers.Start(testCtx.Ctx.Done())
109108
externalInformers.WaitForCacheSync(testCtx.Ctx.Done())
110-
testCtx.InformerFactory.Start(testCtx.Ctx.Done())
111-
testCtx.InformerFactory.WaitForCacheSync(testCtx.Ctx.Done())
109+
testutils.SyncInformerFactory(testCtx)
110+
111+
// Run all controllers
112+
go nc.Run(testCtx.Ctx.Done())
113+
go testCtx.Scheduler.Run(testCtx.Ctx)
112114

113115
// -------------------------------------------
114116
// Test TaintNodeByCondition feature.

test/integration/scheduler/util.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,21 @@ func initDisruptionController(t *testing.T, testCtx *testutils.TestContext) *dis
7979
// initTest initializes a test environment and creates master and scheduler with default
8080
// configuration.
8181
func initTest(t *testing.T, nsPrefix string, opts ...scheduler.Option) *testutils.TestContext {
82-
return testutils.InitTestSchedulerWithOptions(t, testutils.InitTestMaster(t, nsPrefix, nil), true, nil, time.Second, opts...)
82+
testCtx := testutils.InitTestSchedulerWithOptions(t, testutils.InitTestMaster(t, nsPrefix, nil), true, nil, time.Second, opts...)
83+
testutils.SyncInformerFactory(testCtx)
84+
go testCtx.Scheduler.Run(testCtx.Ctx)
85+
return testCtx
8386
}
8487

8588
// initTestDisablePreemption initializes a test environment and creates master and scheduler with default
8689
// configuration but with pod preemption disabled.
8790
func initTestDisablePreemption(t *testing.T, nsPrefix string) *testutils.TestContext {
88-
return testutils.InitTestSchedulerWithOptions(
91+
testCtx := testutils.InitTestSchedulerWithOptions(
8992
t, testutils.InitTestMaster(t, nsPrefix, nil), true, nil,
9093
time.Second, scheduler.WithPreemptionDisabled(true))
94+
testutils.SyncInformerFactory(testCtx)
95+
go testCtx.Scheduler.Run(testCtx.Ctx)
96+
return testCtx
9197
}
9298

9399
// waitForReflection waits till the passFunc confirms that the object it expects

test/integration/util/util.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,12 @@ func PodDeleted(c clientset.Interface, podNamespace, podName string) wait.Condit
181181
}
182182
}
183183

184+
// SyncInformerFactory starts informer and waits for caches to be synced
185+
func SyncInformerFactory(testCtx *TestContext) {
186+
testCtx.InformerFactory.Start(testCtx.Ctx.Done())
187+
testCtx.InformerFactory.WaitForCacheSync(testCtx.Ctx.Done())
188+
}
189+
184190
// CleanupTest cleans related resources which were created during integration test
185191
func CleanupTest(t *testing.T, testCtx *TestContext) {
186192
// Kill the scheduler.
@@ -408,11 +414,6 @@ func InitTestSchedulerWithOptions(
408414
stopCh := make(chan struct{})
409415
eventBroadcaster.StartRecordingToSink(stopCh)
410416

411-
testCtx.InformerFactory.Start(testCtx.Scheduler.StopEverything)
412-
testCtx.InformerFactory.WaitForCacheSync(testCtx.Scheduler.StopEverything)
413-
414-
go testCtx.Scheduler.Run(testCtx.Ctx)
415-
416417
return testCtx
417418
}
418419

0 commit comments

Comments
 (0)