@@ -641,6 +641,30 @@ func initTestOutput(tb testing.TB) io.Writer {
641
641
return output
642
642
}
643
643
644
+ type cleanupKeyType struct {}
645
+
646
+ var cleanupKey = cleanupKeyType {}
647
+
648
+ // shouldCleanup returns true if a function should clean up resource in the
649
+ // apiserver when the test is done. This is true for unit tests (etcd and
650
+ // apiserver get reused) and false for benchmarks (each benchmark starts with a
651
+ // clean state, so cleaning up just wastes time).
652
+ //
653
+ // The default if not explicitly set in the context is true.
654
+ func shouldCleanup (ctx context.Context ) bool {
655
+ val := ctx .Value (cleanupKey )
656
+ if enabled , ok := val .(bool ); ok {
657
+ return enabled
658
+ }
659
+ return true
660
+ }
661
+
662
+ // withCleanup sets whether cleaning up resources in the apiserver
663
+ // should be done. The default is true.
664
+ func withCleanup (tCtx ktesting.TContext , enabled bool ) ktesting.TContext {
665
+ return ktesting .WithValue (tCtx , cleanupKey , enabled )
666
+ }
667
+
644
668
var perfSchedulingLabelFilter = flag .String ("perf-scheduling-label-filter" , "performance" , "comma-separated list of labels which a testcase must have (no prefix or +) or must not have (-), used by BenchmarkPerfScheduling" )
645
669
646
670
// RunBenchmarkPerfScheduling runs the scheduler performance tests.
@@ -695,7 +719,12 @@ func RunBenchmarkPerfScheduling(b *testing.B, outOfTreePluginRegistry frameworkr
695
719
defer featuregatetesting .SetFeatureGateDuringTest (b , utilfeature .DefaultFeatureGate , feature , flag )()
696
720
}
697
721
informerFactory , tCtx := setupClusterForWorkload (tCtx , tc .SchedulerConfigPath , tc .FeatureGates , outOfTreePluginRegistry )
698
- results := runWorkload (tCtx , tc , w , informerFactory , false )
722
+
723
+ // No need to clean up, each benchmark testcase starts with an empty
724
+ // etcd database.
725
+ tCtx = withCleanup (tCtx , false )
726
+
727
+ results := runWorkload (tCtx , tc , w , informerFactory )
699
728
dataItems .DataItems = append (dataItems .DataItems , results ... )
700
729
701
730
if len (results ) > 0 {
@@ -799,7 +828,7 @@ func setupClusterForWorkload(tCtx ktesting.TContext, configPath string, featureG
799
828
return mustSetupCluster (tCtx , cfg , featureGates , outOfTreePluginRegistry )
800
829
}
801
830
802
- func runWorkload (tCtx ktesting.TContext , tc * testCase , w * workload , informerFactory informers.SharedInformerFactory , cleanup bool ) []DataItem {
831
+ func runWorkload (tCtx ktesting.TContext , tc * testCase , w * workload , informerFactory informers.SharedInformerFactory ) []DataItem {
803
832
b , benchmarking := tCtx .TB ().(* testing.B )
804
833
if benchmarking {
805
834
start := time .Now ()
@@ -811,6 +840,7 @@ func runWorkload(tCtx ktesting.TContext, tc *testCase, w *workload, informerFact
811
840
b .ReportMetric (duration .Seconds (), "runtime_seconds" )
812
841
})
813
842
}
843
+ cleanup := shouldCleanup (tCtx )
814
844
815
845
// Disable error checking of the sampling interval length in the
816
846
// throughput collector by default. When running benchmarks, report
0 commit comments