scheduler-perf: add option to enable api-server initialization

This commit is contained in:
@saza-ku
2025-03-28 17:38:01 +09:00
parent bdda0a530e
commit 04d0715e66
2 changed files with 40 additions and 1 deletions

View File

@@ -0,0 +1,20 @@
package benchmark
import "k8s.io/kubernetes/test/utils/ktesting"
type SchedulerPerfOption func(options *schedulerPerfOptions)
// PrepareFn is a function that is called before the benchmarks run.
type PrepareFn func(tCtx ktesting.TContext) error
type schedulerPerfOptions struct {
prepareFn PrepareFn
}
// WithPrepareFn is the option to set a function that is called
// before the benchmarks run. (e.g. applying CRDs for custom plugins)
func WithPrepareFn(prepareFn PrepareFn) SchedulerPerfOption {
return func(s *schedulerPerfOptions) {
s.prepareFn = prepareFn
}
}

View File

@@ -1147,7 +1147,19 @@ func fixJSONOutput(b *testing.B) {
// You can pass your own scheduler plugins via outOfTreePluginRegistry.
// Also, you may want to put your plugins in PluginNames variable in this package
// to collect metrics for them.
func RunBenchmarkPerfScheduling(b *testing.B, configFile string, topicName string, outOfTreePluginRegistry frameworkruntime.Registry) {
func RunBenchmarkPerfScheduling(b *testing.B, configFile string, topicName string, outOfTreePluginRegistry frameworkruntime.Registry, options ...SchedulerPerfOption) {
opts := &schedulerPerfOptions{
prepareFn: nil,
}
for _, option := range options {
option(opts)
}
runBenchmarkPerSchedulingImpl(b, configFile, topicName, outOfTreePluginRegistry, opts)
}
func runBenchmarkPerSchedulingImpl(b *testing.B, configFile string, topicName string, outOfTreePluginRegistry frameworkruntime.Registry, options *schedulerPerfOptions) {
testCases, err := getTestCases(configFile)
if err != nil {
b.Fatal(err)
@@ -1194,6 +1206,13 @@ func RunBenchmarkPerfScheduling(b *testing.B, configFile string, topicName strin
b.Fatalf("workload %s is not valid: %v", w.Name, err)
}
if options.prepareFn != nil {
err = options.prepareFn(tCtx)
if err != nil {
b.Fatalf("failed to run prepareFn: %v", err)
}
}
results, err := runWorkload(tCtx, tc, w, informerFactory)
if err != nil {
tCtx.Fatalf("Error running workload %s: %s", w.Name, err)