Repository: kubernetes/kubernetes
File: test/integration/scheduler_perf/dra/dra_test.go (Go)

Code before:
			defer structured.EnableAllocators()

			// In order to run with the "stable" implementation, we have to disable
			// some features, something that isn't specified in the YAML
			// configuration because for other implementations we want the default
			// features. Using "AllAlpha" and "AllBeta" would be better here,
			// but interacts poorly with setting the emulated version to 1.33 later
			// on ("scheduler_perf.go:1117: failed to set emulation version to 1.33 during test:
			// cannot set feature gate NominatedNodeNameForExpectation to false, feature is PreAlpha at emulated version 1.33, ...")
			//
			// Once the current "incubating" becomes "stable", this can be replaced
			// with two sub tests:
			// - "ga-only": keep disabling optional features
			// - "default": don't change features
			var options []perf.SchedulerPerfOption
			if allocatorName == "stable" {
				options = append(options, perf.WithPreRunFn(func(tCtx ktesting.TContext) error {
					overrides := featuregatetesting.FeatureOverrides{
						features.DRAAdminAccess:     false,
						features.DRAPrioritizedList: false,
					}
					// If version emulation already caused features to be off,
					// then we do not need and maybe even cannot turn them
					// off (pre-alpha = feature doesn't event exist).
					if utilfeature.DefaultFeatureGate.(featuregate.MutableVersionedFeatureGate).
						EmulationVersion().AtLeast(version.MustParse("1.34")) {
						overrides[features.DRAConsumableCapacity] = false
					}
					featuregatetesting.SetFeatureGatesDuringTest(tCtx, utilfeature.DefaultFeatureGate, overrides)

					tCtx.Skip("stopping")

					return nil
				}))
			}

			perf.RunIntegrationPerfScheduling(t, "performance-config.yaml", options...)
		})
	}
}

// These benchmarks have to contain the word BenchmarkPerfScheduling to be picked up
// by benchmark jobs.
//
// Sub-tests should have worked, too, but gotestsum was unhappy.

func BenchmarkPerfScheduling(b *testing.B) {
	// Restrict benchmarking to the default allocator.
	structured.EnableAllocators("incubating")
	defer structured.EnableAllocators()


Review comment (suggestion):
verify: test-featuregates:

```
Test files may not access mutable global feature gates directly:
test/integration/scheduler_perf/dra/dra_test.go:					if utilfeature.DefaultMutableFeatureGate.EmulationVersion().AtLeast(version.MustParse("1.34")) {

Use this invocation instead:
  featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.<FeatureName>, <value>)
```

The check in 
https://github.com/kubernetes/kubernetes/blob/4179ebc3d6528d16d1295f9e64d43c7b829124b1/hack/verify-test-featuregates.sh#L33
is annoyingly broad and doesn't allow suppression.

For now, as a workaround, you can put a `func preRun(tCtx ktesting.TContext) error` into `dra.go` and use it here with `options = append(options, perf.WithPreRunFn(preRun))`.







Code after:
			defer structured.EnableAllocators()

			// In order to run with the "stable" implementation, we have to disable
			// some features, something that isn't specified in the YAML
			// configuration because for other implementations we want the default
			// features. Using "AllAlpha" and "AllBeta" would be better here,
			// but interacts poorly with setting the emulated version to 1.33 later
			// on ("scheduler_perf.go:1117: failed to set emulation version to 1.33 during test:
			// cannot set feature gate NominatedNodeNameForExpectation to false, feature is PreAlpha at emulated version 1.33, ...")
			//
			// Once the current "incubating" becomes "stable", this can be replaced
			// with two sub tests:
			// - "ga-only": keep disabling optional features
			// - "default": don't change features
			var options []perf.SchedulerPerfOption
			if allocatorName == "stable" {
				options = append(options, perf.WithPreRunFn(func(tCtx ktesting.TContext) error {
					overrides := featuregatetesting.FeatureOverrides{
						features.DRAAdminAccess:     false,
						features.DRAPrioritizedList: false,
					}
					// If version emulation already caused features to be off,
					// then we do not need and maybe even cannot turn them
					// off (pre-alpha = feature doesn't event exist).
					if utilfeature.DefaultFeatureGate.(featuregate.MutableVersionedFeatureGate).
						EmulationVersion().AtLeast(version.MustParse("1.34")) {
						overrides[features.DRAConsumableCapacity] = false
					}
					featuregatetesting.SetFeatureGatesDuringTest(tCtx, utilfeature.DefaultFeatureGate, overrides)
					return nil
				}))
			}

			perf.RunIntegrationPerfScheduling(t, "performance-config.yaml", options...)
		})
	}
}

// These benchmarks have to contain the word BenchmarkPerfScheduling to be picked up
// by benchmark jobs.
//
// Sub-tests should have worked, too, but gotestsum was unhappy.

func BenchmarkPerfScheduling(b *testing.B) {
	// Restrict benchmarking to the default allocator.
	structured.EnableAllocators("incubating")
	defer structured.EnableAllocators()

	// "dra" is how this was called traditionally.
	// It's kept to avoid changing perf-dash results.
	perf.RunBenchmarkPerfScheduling(b, "performance-config.yaml", "dra", nil)