mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
scheduler: make ApplyFeatureGates() stateless
This commit is contained in:
@@ -57,7 +57,11 @@ func defaultPredicates() sets.String {
|
||||
}
|
||||
|
||||
// ApplyFeatureGates applies algorithm by feature gates.
|
||||
func ApplyFeatureGates() {
|
||||
// The returned function is used to restore the state of registered predicates/priorities
|
||||
// when this function is called, and should be called in tests which may modify the value
|
||||
// of a feature gate temporarily.
|
||||
func ApplyFeatureGates() (restore func()) {
|
||||
snapshot := factory.Copy()
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.TaintNodesByCondition) {
|
||||
// Remove "CheckNodeCondition", "CheckNodeMemoryPressure", "CheckNodePIDPressure"
|
||||
// and "CheckNodeDiskPressure" predicates
|
||||
@@ -105,6 +109,11 @@ func ApplyFeatureGates() {
|
||||
// Register the priority function to specific provider too.
|
||||
factory.InsertPriorityKeyToAlgorithmProviderMap(factory.RegisterPriorityMapReduceFunction(priorities.ResourceLimitsPriority, priorities.ResourceLimitsPriorityMap, nil, 1))
|
||||
}
|
||||
|
||||
restore = func() {
|
||||
factory.Apply(snapshot)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func registerAlgorithmProvider(predSet, priSet sets.String) {
|
||||
|
||||
@@ -21,6 +21,6 @@ import (
|
||||
)
|
||||
|
||||
// ApplyFeatureGates applies algorithm by feature gates.
|
||||
func ApplyFeatureGates() {
|
||||
defaults.ApplyFeatureGates()
|
||||
func ApplyFeatureGates() func() {
|
||||
return defaults.ApplyFeatureGates()
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ func TestApplyFeatureGates(t *testing.T) {
|
||||
// Apply features for algorithm providers.
|
||||
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.TaintNodesByCondition, true)()
|
||||
|
||||
ApplyFeatureGates()
|
||||
defer ApplyFeatureGates()()
|
||||
|
||||
for _, pn := range algorithmProviderNames {
|
||||
t.Run(pn, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user