From a869a898257b520a5bb1ac0fef4cf3852bb6b1e4 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Wed, 25 Jan 2023 10:18:00 +0100 Subject: [PATCH] scheduler perf: remove cleanup func b.Cleanup may as well get called inside the function instead of leaving that to the caller. --- .../scheduler_perf/scheduler_perf_test.go | 3 +-- test/integration/scheduler_perf/util.go | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/test/integration/scheduler_perf/scheduler_perf_test.go b/test/integration/scheduler_perf/scheduler_perf_test.go index 9177fc6bb89..9baefac4a2b 100644 --- a/test/integration/scheduler_perf/scheduler_perf_test.go +++ b/test/integration/scheduler_perf/scheduler_perf_test.go @@ -750,8 +750,7 @@ func runWorkload(ctx context.Context, b *testing.B, tc *testCase, w *workload) [ b.Fatalf("validate scheduler config file failed: %v", err) } } - finalFunc, podInformer, client, dynClient := mustSetupScheduler(ctx, b, cfg) - b.Cleanup(finalFunc) + podInformer, client, dynClient := mustSetupScheduler(ctx, b, cfg) var mu sync.Mutex var dataItems []DataItem diff --git a/test/integration/scheduler_perf/util.go b/test/integration/scheduler_perf/util.go index 73db210fa5f..f97e7e10d18 100644 --- a/test/integration/scheduler_perf/util.go +++ b/test/integration/scheduler_perf/util.go @@ -75,8 +75,7 @@ func newDefaultComponentConfig() (*config.KubeSchedulerConfiguration, error) { // remove resources after finished. // Notes on rate limiter: // - client rate limit is set to 5000. -func mustSetupScheduler(ctx context.Context, b *testing.B, config *config.KubeSchedulerConfiguration) (util.ShutdownFunc, coreinformers.PodInformer, clientset.Interface, dynamic.Interface) { - ctx, cancel := context.WithCancel(ctx) +func mustSetupScheduler(ctx context.Context, b *testing.B, config *config.KubeSchedulerConfiguration) (coreinformers.PodInformer, clientset.Interface, dynamic.Interface) { // Run API server with minimimal logging by default. Can be raised with -v. framework.MinVerbosity = 0 @@ -86,6 +85,12 @@ func mustSetupScheduler(ctx context.Context, b *testing.B, config *config.KubeSc opts.Admission.GenericAdmission.DisablePlugins = []string{"ServiceAccount", "TaintNodesByCondition", "Priority"} }, }) + b.Cleanup(tearDownFn) + + // Cleanup will be in reverse order: first the clients get cancelled, + // then the apiserver is torn down. + ctx, cancel := context.WithCancel(ctx) + b.Cleanup(cancel) // TODO: client connection configuration, such as QPS or Burst is configurable in theory, this could be derived from the `config`, need to // support this when there is any testcase that depends on such configuration. @@ -110,12 +115,7 @@ func mustSetupScheduler(ctx context.Context, b *testing.B, config *config.KubeSc _, podInformer := util.StartScheduler(ctx, client, cfg, config) util.StartFakePVController(ctx, client) - shutdownFn := func() { - cancel() - tearDownFn() - } - - return shutdownFn, podInformer, client, dynClient + return podInformer, client, dynClient } // Returns the list of scheduled pods in the specified namespaces.