mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Optimize Repeated registration of AlgorithmProvider when ApplyFeatureGates
Add InsertPredicateKeyToAlgorithmProviderMap() and RemovePredicateKeyFromAlgorithmProviderMap() to insert/remove fit predicate key of all algorithmProviders which in algorithmProviderMap Add Func RemovePredicateKeyFromAlgoProvider() AND InsertPredicateKeyToAlgoProvider() which can insert/remove fit predicate key to specific algorithmProvider
This commit is contained in:
parent
d7e56d5330
commit
a48cc26443
@ -195,20 +195,24 @@ func defaultPredicates() sets.String {
|
||||
|
||||
// ApplyFeatureGates applies algorithm by feature gates.
|
||||
func ApplyFeatureGates() {
|
||||
predSet := defaultPredicates()
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(features.TaintNodesByCondition) {
|
||||
// Remove "CheckNodeCondition" predicate
|
||||
factory.RemoveFitPredicate("CheckNodeCondition")
|
||||
predSet.Delete("CheckNodeCondition")
|
||||
// Remove Key "CheckNodeCondition" From All Algorithm Provider
|
||||
// The key will be removed from all providers which in algorithmProviderMap[]
|
||||
// if you just want remove specific provider, call func RemovePredicateKeyFromAlgoProvider()
|
||||
factory.RemovePredicateKeyFromAlgorithmProviderMap("CheckNodeCondition")
|
||||
|
||||
// Fit is determined based on whether a pod can tolerate all of the node's taints
|
||||
predSet.Insert(factory.RegisterMandatoryFitPredicate("PodToleratesNodeTaints", predicates.PodToleratesNodeTaints))
|
||||
factory.RegisterMandatoryFitPredicate("PodToleratesNodeTaints", predicates.PodToleratesNodeTaints)
|
||||
// Insert Key "PodToleratesNodeTaints" To All Algorithm Provider
|
||||
// The key will insert to all providers which in algorithmProviderMap[]
|
||||
// if you just want insert to specific provider, call func InsertPredicateKeyToAlgoProvider()
|
||||
factory.InsertPredicateKeyToAlgorithmProviderMap("PodToleratesNodeTaints")
|
||||
|
||||
glog.Warningf("TaintNodesByCondition is enabled, PodToleratesNodeTaints predicate is mandatory")
|
||||
}
|
||||
|
||||
registerAlgorithmProvider(predSet, defaultPriorities())
|
||||
}
|
||||
|
||||
func registerAlgorithmProvider(predSet, priSet sets.String) {
|
||||
|
@ -115,6 +115,56 @@ func RemoveFitPredicate(name string) {
|
||||
mandatoryFitPredicates.Delete(name)
|
||||
}
|
||||
|
||||
// RemovePredicateKeyFromAlgoProvider removes a fit predicate key from algorithmProvider.
|
||||
func RemovePredicateKeyFromAlgoProvider(providerName, key string) error {
|
||||
schedulerFactoryMutex.Lock()
|
||||
defer schedulerFactoryMutex.Unlock()
|
||||
|
||||
validateAlgorithmNameOrDie(providerName)
|
||||
provider, ok := algorithmProviderMap[providerName]
|
||||
if !ok {
|
||||
return fmt.Errorf("plugin %v has not been registered", providerName)
|
||||
}
|
||||
provider.FitPredicateKeys.Delete(key)
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovePredicateKeyFromAlgoProvider removes a fit predicate key from all algorithmProviders which in algorithmProviderMap.
|
||||
func RemovePredicateKeyFromAlgorithmProviderMap(key string) {
|
||||
schedulerFactoryMutex.Lock()
|
||||
defer schedulerFactoryMutex.Unlock()
|
||||
|
||||
for _, provider := range algorithmProviderMap {
|
||||
provider.FitPredicateKeys.Delete(key)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// InsertPredicateKeyToAlgoProvider insert a fit predicate key to algorithmProvider.
|
||||
func InsertPredicateKeyToAlgoProvider(providerName, key string) error {
|
||||
schedulerFactoryMutex.Lock()
|
||||
defer schedulerFactoryMutex.Unlock()
|
||||
|
||||
validateAlgorithmNameOrDie(providerName)
|
||||
provider, ok := algorithmProviderMap[providerName]
|
||||
if !ok {
|
||||
return fmt.Errorf("plugin %v has not been registered", providerName)
|
||||
}
|
||||
provider.FitPredicateKeys.Insert(key)
|
||||
return nil
|
||||
}
|
||||
|
||||
// InsertPredicateKeyToAlgorithmProviderMap insert a fit predicate key to all algorithmProviders which in algorithmProviderMap.
|
||||
func InsertPredicateKeyToAlgorithmProviderMap(key string) {
|
||||
schedulerFactoryMutex.Lock()
|
||||
defer schedulerFactoryMutex.Unlock()
|
||||
|
||||
for _, provider := range algorithmProviderMap {
|
||||
provider.FitPredicateKeys.Insert(key)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// RegisterMandatoryFitPredicate registers a fit predicate with the algorithm registry, the predicate is used by
|
||||
// kubelet, DaemonSet; it is always included in configuration. Returns the name with which the predicate was
|
||||
// registered.
|
||||
|
Loading…
Reference in New Issue
Block a user