Skip to content

Commit d4627f1

Browse files
committed
chore: call close framework when finishing
Signed-off-by: googs1025 <[email protected]>
1 parent 7e1a5a0 commit d4627f1

File tree

14 files changed

+98
-42
lines changed

14 files changed

+98
-42
lines changed

pkg/scheduler/eventhandlers_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ func TestAddAllEventHandlers(t *testing.T) {
482482
ctx, cancel := context.WithCancel(ctx)
483483
defer cancel()
484484

485-
informerFactory := informers.NewSharedInformerFactory(fake.NewSimpleClientset(), 0)
485+
informerFactory := informers.NewSharedInformerFactory(fake.NewClientset(), 0)
486486
schedulingQueue := queue.NewTestQueueWithInformerFactory(ctx, nil, informerFactory)
487487
testSched := Scheduler{
488488
StopEverything: ctx.Done(),

pkg/scheduler/extender_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func TestSchedulerWithExtenders(t *testing.T) {
317317

318318
for _, test := range tests {
319319
t.Run(test.name, func(t *testing.T) {
320-
client := clientsetfake.NewSimpleClientset()
320+
client := clientsetfake.NewClientset()
321321
informerFactory := informers.NewSharedInformerFactory(client, 0)
322322

323323
var extenders []framework.Extender

pkg/scheduler/framework/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ type Handle interface {
704704

705705
SharedInformerFactory() informers.SharedInformerFactory
706706

707-
// ResourceClaimInfos returns an assume cache of ResourceClaim objects
707+
// ResourceClaimCache returns an assume cache of ResourceClaim objects
708708
// which gets populated by the shared informer factory and the dynamic resources
709709
// plugin.
710710
ResourceClaimCache() *assumecache.AssumeCache

pkg/scheduler/framework/plugins/defaultbinder/default_binder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func TestDefaultBinder(t *testing.T) {
5858
defer cancel()
5959

6060
var gotBinding *v1.Binding
61-
client := fake.NewSimpleClientset(testPod)
61+
client := fake.NewClientset(testPod)
6262
client.PrependReactor("create", "pods", func(action clienttesting.Action) (bool, runtime.Object, error) {
6363
if action.GetSubresource() != "binding" {
6464
return false, nil, nil

pkg/scheduler/framework/plugins/defaultpreemption/default_preemption_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ func TestPostFilter(t *testing.T) {
340340
for _, pod := range tt.pods {
341341
podItems = append(podItems, *pod)
342342
}
343-
cs := clientsetfake.NewSimpleClientset(&v1.PodList{Items: podItems})
343+
cs := clientsetfake.NewClientset(&v1.PodList{Items: podItems})
344344
informerFactory := informers.NewSharedInformerFactory(cs, 0)
345345
podInformer := informerFactory.Core().V1().Pods().Informer()
346346
podInformer.GetStore().Add(tt.pod)
@@ -1087,7 +1087,7 @@ func TestDryRunPreemption(t *testing.T) {
10871087
for _, n := range nodes {
10881088
objs = append(objs, n)
10891089
}
1090-
informerFactory := informers.NewSharedInformerFactory(clientsetfake.NewSimpleClientset(objs...), 0)
1090+
informerFactory := informers.NewSharedInformerFactory(clientsetfake.NewClientset(objs...), 0)
10911091
parallelism := parallelize.DefaultParallelism
10921092
if tt.disableParallelism {
10931093
// We need disableParallelism because of the non-deterministic nature
@@ -1347,7 +1347,7 @@ func TestSelectBestCandidate(t *testing.T) {
13471347
for _, pod := range tt.pods {
13481348
objs = append(objs, pod)
13491349
}
1350-
cs := clientsetfake.NewSimpleClientset(objs...)
1350+
cs := clientsetfake.NewClientset(objs...)
13511351
informerFactory := informers.NewSharedInformerFactory(cs, 0)
13521352
snapshot := internalcache.NewSnapshot(tt.pods, nodes)
13531353
logger, ctx := ktesting.NewTestContext(t)
@@ -1685,7 +1685,7 @@ func TestPreempt(t *testing.T) {
16851685
labelKeys := []string{"hostname", "zone", "region"}
16861686
for _, test := range tests {
16871687
t.Run(test.name, func(t *testing.T) {
1688-
client := clientsetfake.NewSimpleClientset()
1688+
client := clientsetfake.NewClientset()
16891689
informerFactory := informers.NewSharedInformerFactory(client, 0)
16901690
podInformer := informerFactory.Core().V1().Pods().Informer()
16911691
podInformer.GetStore().Add(test.pod)

pkg/scheduler/framework/plugins/podtopologyspread/scoring_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestPreScoreSkip(t *testing.T) {
8989
_, ctx := ktesting.NewTestContext(t)
9090
ctx, cancel := context.WithCancel(ctx)
9191
defer cancel()
92-
informerFactory := informers.NewSharedInformerFactory(fake.NewSimpleClientset(tt.objs...), 0)
92+
informerFactory := informers.NewSharedInformerFactory(fake.NewClientset(tt.objs...), 0)
9393
f, err := frameworkruntime.NewFramework(ctx, nil, nil,
9494
frameworkruntime.WithSnapshotSharedLister(cache.NewSnapshot(nil, tt.nodes)),
9595
frameworkruntime.WithInformerFactory(informerFactory))
@@ -576,7 +576,7 @@ func TestPreScoreStateEmptyNodes(t *testing.T) {
576576
_, ctx := ktesting.NewTestContext(t)
577577
ctx, cancel := context.WithCancel(ctx)
578578
defer cancel()
579-
informerFactory := informers.NewSharedInformerFactory(fake.NewSimpleClientset(tt.objs...), 0)
579+
informerFactory := informers.NewSharedInformerFactory(fake.NewClientset(tt.objs...), 0)
580580
f, err := frameworkruntime.NewFramework(ctx, nil, nil,
581581
frameworkruntime.WithSnapshotSharedLister(cache.NewSnapshot(nil, tt.nodes)),
582582
frameworkruntime.WithInformerFactory(informerFactory))

pkg/scheduler/framework/plugins/testing/testing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func SetupPluginWithInformers(
4242
objs []runtime.Object,
4343
) framework.Plugin {
4444
objs = append([]runtime.Object{&v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ""}}}, objs...)
45-
informerFactory := informers.NewSharedInformerFactory(fake.NewSimpleClientset(objs...), 0)
45+
informerFactory := informers.NewSharedInformerFactory(fake.NewClientset(objs...), 0)
4646
fh, err := frameworkruntime.NewFramework(ctx, nil, nil,
4747
frameworkruntime.WithSnapshotSharedLister(sharedLister),
4848
frameworkruntime.WithInformerFactory(informerFactory))

pkg/scheduler/framework/preemption/preemption_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ func TestDryRunPreemption(t *testing.T) {
333333
for _, n := range tt.nodes {
334334
objs = append(objs, n)
335335
}
336-
informerFactory := informers.NewSharedInformerFactory(clientsetfake.NewSimpleClientset(objs...), 0)
336+
informerFactory := informers.NewSharedInformerFactory(clientsetfake.NewClientset(objs...), 0)
337337
parallelism := parallelize.DefaultParallelism
338338
_, ctx := ktesting.NewTestContext(t)
339339
ctx, cancel := context.WithCancel(ctx)
@@ -437,7 +437,7 @@ func TestSelectCandidate(t *testing.T) {
437437
for _, pod := range tt.testPods {
438438
objs = append(objs, pod)
439439
}
440-
informerFactory := informers.NewSharedInformerFactory(clientsetfake.NewSimpleClientset(objs...), 0)
440+
informerFactory := informers.NewSharedInformerFactory(clientsetfake.NewClientset(objs...), 0)
441441
snapshot := internalcache.NewSnapshot(tt.testPods, nodes)
442442
_, ctx := ktesting.NewTestContext(t)
443443
ctx, cancel := context.WithCancel(ctx)

pkg/scheduler/framework/runtime/framework_test.go

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,11 @@ func TestNewFrameworkMultiPointExpansion(t *testing.T) {
904904
ctx, cancel := context.WithCancel(ctx)
905905
defer cancel()
906906
fw, err := NewFramework(ctx, registry, &config.KubeSchedulerProfile{Plugins: tc.plugins})
907+
defer func() {
908+
if fw != nil {
909+
_ = fw.Close()
910+
}
911+
}()
907912
if err != nil {
908913
if tc.wantErr == "" || !strings.Contains(err.Error(), tc.wantErr) {
909914
t.Fatalf("Unexpected error, got %v, expect: %s", err, tc.wantErr)
@@ -913,7 +918,6 @@ func TestNewFrameworkMultiPointExpansion(t *testing.T) {
913918
t.Fatalf("Unexpected error, got %v, expect: %s", err, tc.wantErr)
914919
}
915920
}
916-
917921
if tc.wantErr == "" {
918922
if diff := cmp.Diff(tc.wantPlugins, fw.ListPlugins()); diff != "" {
919923
t.Fatalf("Unexpected eventToPlugin map (-want,+got):%s", diff)
@@ -969,7 +973,9 @@ func TestPreEnqueuePlugins(t *testing.T) {
969973
if err != nil {
970974
t.Fatalf("fail to create framework: %s", err)
971975
}
972-
976+
defer func() {
977+
_ = f.Close()
978+
}()
973979
got := f.PreEnqueuePlugins()
974980
if !reflect.DeepEqual(got, tt.want) {
975981
t.Errorf("PreEnqueuePlugins(): want %v, but got %v", tt.want, got)
@@ -1092,7 +1098,9 @@ func TestRunPreScorePlugins(t *testing.T) {
10921098
if err != nil {
10931099
t.Fatalf("Failed to create framework for testing: %v", err)
10941100
}
1095-
1101+
defer func() {
1102+
_ = f.Close()
1103+
}()
10961104
state := framework.NewCycleState()
10971105
status := f.RunPreScorePlugins(ctx, state, nil, nil)
10981106
if status.Code() != tt.wantStatusCode {
@@ -1486,6 +1494,9 @@ func TestRunScorePlugins(t *testing.T) {
14861494
if err != nil {
14871495
t.Fatalf("Failed to create framework for testing: %v", err)
14881496
}
1497+
defer func() {
1498+
_ = f.Close()
1499+
}()
14891500

14901501
state := framework.NewCycleState()
14911502
state.SkipScorePlugins = tt.skippedPlugins
@@ -1530,6 +1541,9 @@ func TestPreFilterPlugins(t *testing.T) {
15301541
if err != nil {
15311542
t.Fatalf("Failed to create framework for testing: %v", err)
15321543
}
1544+
defer func() {
1545+
_ = f.Close()
1546+
}()
15331547
state := framework.NewCycleState()
15341548

15351549
f.RunPreFilterPlugins(ctx, state, nil)
@@ -1719,6 +1733,9 @@ func TestRunPreFilterPlugins(t *testing.T) {
17191733
if err != nil {
17201734
t.Fatalf("Failed to create framework for testing: %v", err)
17211735
}
1736+
defer func() {
1737+
_ = f.Close()
1738+
}()
17221739

17231740
state := framework.NewCycleState()
17241741
result, status := f.RunPreFilterPlugins(ctx, state, nil)
@@ -1809,6 +1826,9 @@ func TestRunPreFilterExtensionRemovePod(t *testing.T) {
18091826
if err != nil {
18101827
t.Fatalf("Failed to create framework for testing: %v", err)
18111828
}
1829+
defer func() {
1830+
_ = f.Close()
1831+
}()
18121832

18131833
state := framework.NewCycleState()
18141834
state.SkipFilterPlugins = tt.skippedPluginNames
@@ -1893,6 +1913,9 @@ func TestRunPreFilterExtensionAddPod(t *testing.T) {
18931913
if err != nil {
18941914
t.Fatalf("Failed to create framework for testing: %v", err)
18951915
}
1916+
defer func() {
1917+
_ = f.Close()
1918+
}()
18961919

18971920
state := framework.NewCycleState()
18981921
state.SkipFilterPlugins = tt.skippedPluginNames
@@ -2096,6 +2119,9 @@ func TestFilterPlugins(t *testing.T) {
20962119
if err != nil {
20972120
t.Fatalf("fail to create framework: %s", err)
20982121
}
2122+
defer func() {
2123+
_ = f.Close()
2124+
}()
20992125
state := framework.NewCycleState()
21002126
state.SkipFilterPlugins = tt.skippedPlugins
21012127
gotStatus := f.RunFilterPlugins(ctx, state, pod, nil)
@@ -2220,6 +2246,9 @@ func TestPostFilterPlugins(t *testing.T) {
22202246
if err != nil {
22212247
t.Fatalf("fail to create framework: %s", err)
22222248
}
2249+
defer func() {
2250+
_ = f.Close()
2251+
}()
22232252
_, gotStatus := f.RunPostFilterPlugins(ctx, nil, pod, nil)
22242253
if !reflect.DeepEqual(gotStatus, tt.wantStatus) {
22252254
t.Errorf("Unexpected status. got: %v, want: %v", gotStatus, tt.wantStatus)
@@ -2371,6 +2400,9 @@ func TestFilterPluginsWithNominatedPods(t *testing.T) {
23712400
if err != nil {
23722401
t.Fatalf("fail to create framework: %s", err)
23732402
}
2403+
defer func() {
2404+
_ = f.Close()
2405+
}()
23742406
tt.nodeInfo.SetNode(tt.node)
23752407
gotStatus := f.RunFilterPluginsWithNominatedPods(ctx, framework.NewCycleState(), tt.pod, tt.nodeInfo)
23762408
if diff := cmp.Diff(gotStatus, tt.wantStatus, cmpOpts...); diff != "" {
@@ -2528,6 +2560,9 @@ func TestPreBindPlugins(t *testing.T) {
25282560
if err != nil {
25292561
t.Fatalf("fail to create framework: %s", err)
25302562
}
2563+
defer func() {
2564+
_ = f.Close()
2565+
}()
25312566

25322567
status := f.RunPreBindPlugins(ctx, nil, pod, "")
25332568

@@ -2683,6 +2718,9 @@ func TestReservePlugins(t *testing.T) {
26832718
ctx, cancel := context.WithCancel(context.Background())
26842719
defer cancel()
26852720
f, err := newFrameworkWithQueueSortAndBind(ctx, registry, profile)
2721+
defer func() {
2722+
_ = f.Close()
2723+
}()
26862724
if err != nil {
26872725
t.Fatalf("fail to create framework: %s", err)
26882726
}
@@ -2811,6 +2849,9 @@ func TestPermitPlugins(t *testing.T) {
28112849
f, err := newFrameworkWithQueueSortAndBind(ctx, registry, profile,
28122850
WithWaitingPods(NewWaitingPodsMap()),
28132851
)
2852+
defer func() {
2853+
_ = f.Close()
2854+
}()
28142855
if err != nil {
28152856
t.Fatalf("fail to create framework: %s", err)
28162857
}
@@ -3000,6 +3041,9 @@ func TestRecordingMetrics(t *testing.T) {
30003041
cancel()
30013042
t.Fatalf("Failed to create framework for testing: %v", err)
30023043
}
3044+
defer func() {
3045+
_ = f.Close()
3046+
}()
30033047

30043048
tt.action(f)
30053049

@@ -3113,6 +3157,9 @@ func TestRunBindPlugins(t *testing.T) {
31133157
cancel()
31143158
t.Fatal(err)
31153159
}
3160+
defer func() {
3161+
_ = fwk.Close()
3162+
}()
31163163

31173164
st := fwk.RunBindPlugins(context.Background(), state, pod, "")
31183165
if st.Code() != tt.wantStatus {
@@ -3171,6 +3218,9 @@ func TestPermitWaitDurationMetric(t *testing.T) {
31713218
if err != nil {
31723219
t.Fatalf("Failed to create framework for testing: %v", err)
31733220
}
3221+
defer func() {
3222+
_ = f.Close()
3223+
}()
31743224

31753225
f.RunPermitPlugins(ctx, nil, pod, "")
31763226
f.WaitOnPermit(ctx, pod)
@@ -3229,6 +3279,9 @@ func TestWaitOnPermit(t *testing.T) {
32293279
if err != nil {
32303280
t.Fatalf("Failed to create framework for testing: %v", err)
32313281
}
3282+
defer func() {
3283+
_ = f.Close()
3284+
}()
32323285

32333286
runPermitPluginsStatus := f.RunPermitPlugins(ctx, nil, pod, "")
32343287
if runPermitPluginsStatus.Code() != framework.Wait {
@@ -3283,6 +3336,9 @@ func TestListPlugins(t *testing.T) {
32833336
if err != nil {
32843337
t.Fatalf("Failed to create framework for testing: %v", err)
32853338
}
3339+
defer func() {
3340+
_ = f.Close()
3341+
}()
32863342
got := f.ListPlugins()
32873343
if diff := cmp.Diff(tt.want, got); diff != "" {
32883344
t.Errorf("unexpected plugins (-want,+got):\n%s", diff)

pkg/scheduler/internal/queue/scheduling_queue_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,7 @@ func TestPriorityQueue_NominatedPodDeleted(t *testing.T) {
20392039
for _, tt := range tests {
20402040
t.Run(tt.name, func(t *testing.T) {
20412041
logger, _ := ktesting.NewTestContext(t)
2042-
cs := fake.NewSimpleClientset(tt.podInfo.Pod)
2042+
cs := fake.NewClientset(tt.podInfo.Pod)
20432043
informerFactory := informers.NewSharedInformerFactory(cs, 0)
20442044
podLister := informerFactory.Core().V1().Pods().Lister()
20452045

0 commit comments

Comments
 (0)