scheduler: make ApplyFeatureGates() stateless

This commit is contained in:
Wei Huang
2019-07-30 11:41:57 -07:00
parent 1871f75b32
commit eb3ed24853
6 changed files with 80 additions and 15 deletions

View File

@@ -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) {

View File

@@ -21,6 +21,6 @@ import (
)
// ApplyFeatureGates applies algorithm by feature gates.
func ApplyFeatureGates() {
defaults.ApplyFeatureGates()
func ApplyFeatureGates() func() {
return defaults.ApplyFeatureGates()
}

View File

@@ -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) {