mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-03 18:27:49 +00:00
Merge pull request #6128 from abhgupta/abhgupta-dev
Updating priority function weight based on specified configuration
This commit is contained in:
@@ -59,11 +59,11 @@ func defaultPriorities() util.StringSet {
|
|||||||
// spreads pods by minimizing the number of pods (belonging to the same service) on the same minion.
|
// spreads pods by minimizing the number of pods (belonging to the same service) on the same minion.
|
||||||
factory.RegisterPriorityConfigFactory(
|
factory.RegisterPriorityConfigFactory(
|
||||||
"ServiceSpreadingPriority",
|
"ServiceSpreadingPriority",
|
||||||
func(args factory.PluginFactoryArgs) algorithm.PriorityConfig {
|
factory.PriorityConfigFactory{
|
||||||
return algorithm.PriorityConfig{
|
Function: func(args factory.PluginFactoryArgs) algorithm.PriorityFunction {
|
||||||
Function: algorithm.NewServiceSpreadPriority(args.ServiceLister),
|
return algorithm.NewServiceSpreadPriority(args.ServiceLister)
|
||||||
|
},
|
||||||
Weight: 1,
|
Weight: 1,
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
// EqualPriority is a prioritizer function that gives an equal weight of one to all minions
|
// EqualPriority is a prioritizer function that gives an equal weight of one to all minions
|
||||||
|
@@ -40,7 +40,13 @@ type PluginFactoryArgs struct {
|
|||||||
type FitPredicateFactory func(PluginFactoryArgs) algorithm.FitPredicate
|
type FitPredicateFactory func(PluginFactoryArgs) algorithm.FitPredicate
|
||||||
|
|
||||||
// A PriorityFunctionFactory produces a PriorityConfig from the given args.
|
// A PriorityFunctionFactory produces a PriorityConfig from the given args.
|
||||||
type PriorityConfigFactory func(PluginFactoryArgs) algorithm.PriorityConfig
|
type PriorityFunctionFactory func(PluginFactoryArgs) algorithm.PriorityFunction
|
||||||
|
|
||||||
|
// A PriorityConfigFactory produces a PriorityConfig from the given function and weight
|
||||||
|
type PriorityConfigFactory struct {
|
||||||
|
Function PriorityFunctionFactory
|
||||||
|
Weight int
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
schedulerFactoryMutex sync.Mutex
|
schedulerFactoryMutex sync.Mutex
|
||||||
@@ -127,8 +133,11 @@ func IsFitPredicateRegistered(name string) bool {
|
|||||||
// Registers a priority function with the algorithm registry. Returns the name,
|
// Registers a priority function with the algorithm registry. Returns the name,
|
||||||
// with which the function was registered.
|
// with which the function was registered.
|
||||||
func RegisterPriorityFunction(name string, function algorithm.PriorityFunction, weight int) string {
|
func RegisterPriorityFunction(name string, function algorithm.PriorityFunction, weight int) string {
|
||||||
return RegisterPriorityConfigFactory(name, func(PluginFactoryArgs) algorithm.PriorityConfig {
|
return RegisterPriorityConfigFactory(name, PriorityConfigFactory{
|
||||||
return algorithm.PriorityConfig{Function: function, Weight: weight}
|
Function: func(PluginFactoryArgs) algorithm.PriorityFunction {
|
||||||
|
return function
|
||||||
|
},
|
||||||
|
Weight: 1,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,43 +152,47 @@ func RegisterPriorityConfigFactory(name string, pcf PriorityConfigFactory) strin
|
|||||||
// Registers a custom priority function with the algorithm registry.
|
// Registers a custom priority function with the algorithm registry.
|
||||||
// Returns the name, with which the priority function was registered.
|
// Returns the name, with which the priority function was registered.
|
||||||
func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string {
|
func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string {
|
||||||
var pcf PriorityConfigFactory
|
var pcf *PriorityConfigFactory
|
||||||
|
|
||||||
validatePriorityOrDie(policy)
|
validatePriorityOrDie(policy)
|
||||||
|
|
||||||
// generate the priority function, if a custom priority is requested
|
// generate the priority function, if a custom priority is requested
|
||||||
if policy.Argument != nil {
|
if policy.Argument != nil {
|
||||||
if policy.Argument.ServiceAntiAffinity != nil {
|
if policy.Argument.ServiceAntiAffinity != nil {
|
||||||
pcf = func(args PluginFactoryArgs) algorithm.PriorityConfig {
|
pcf = &PriorityConfigFactory{
|
||||||
return algorithm.PriorityConfig{
|
Function: func(args PluginFactoryArgs) algorithm.PriorityFunction {
|
||||||
Function: algorithm.NewServiceAntiAffinityPriority(
|
return algorithm.NewServiceAntiAffinityPriority(
|
||||||
args.ServiceLister,
|
args.ServiceLister,
|
||||||
policy.Argument.ServiceAntiAffinity.Label,
|
policy.Argument.ServiceAntiAffinity.Label,
|
||||||
),
|
)
|
||||||
|
},
|
||||||
Weight: policy.Weight,
|
Weight: policy.Weight,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if policy.Argument.LabelPreference != nil {
|
} else if policy.Argument.LabelPreference != nil {
|
||||||
pcf = func(args PluginFactoryArgs) algorithm.PriorityConfig {
|
pcf = &PriorityConfigFactory{
|
||||||
return algorithm.PriorityConfig{
|
Function: func(args PluginFactoryArgs) algorithm.PriorityFunction {
|
||||||
Function: algorithm.NewNodeLabelPriority(
|
return algorithm.NewNodeLabelPriority(
|
||||||
policy.Argument.LabelPreference.Label,
|
policy.Argument.LabelPreference.Label,
|
||||||
policy.Argument.LabelPreference.Presence,
|
policy.Argument.LabelPreference.Presence,
|
||||||
),
|
)
|
||||||
|
},
|
||||||
Weight: policy.Weight,
|
Weight: policy.Weight,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if existing_pcf, ok := priorityFunctionMap[policy.Name]; ok {
|
||||||
} else if _, ok := priorityFunctionMap[policy.Name]; ok {
|
|
||||||
glog.V(2).Infof("Priority type %s already registered, reusing.", policy.Name)
|
glog.V(2).Infof("Priority type %s already registered, reusing.", policy.Name)
|
||||||
return policy.Name
|
// set/update the weight based on the policy
|
||||||
|
pcf = &PriorityConfigFactory{
|
||||||
|
Function: existing_pcf.Function,
|
||||||
|
Weight: policy.Weight,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pcf == nil {
|
if pcf == nil {
|
||||||
glog.Fatalf("Invalid configuration: Priority type not found for %s", policy.Name)
|
glog.Fatalf("Invalid configuration: Priority type not found for %s", policy.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return RegisterPriorityConfigFactory(policy.Name, pcf)
|
return RegisterPriorityConfigFactory(policy.Name, *pcf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// This check is useful for testing providers.
|
// This check is useful for testing providers.
|
||||||
@@ -242,7 +255,10 @@ func getPriorityFunctionConfigs(names util.StringSet, args PluginFactoryArgs) ([
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("Invalid priority name %s specified - no corresponding function found", name)
|
return nil, fmt.Errorf("Invalid priority name %s specified - no corresponding function found", name)
|
||||||
}
|
}
|
||||||
configs = append(configs, factory(args))
|
configs = append(configs, algorithm.PriorityConfig{
|
||||||
|
Function: factory.Function(args),
|
||||||
|
Weight: factory.Weight,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return configs, nil
|
return configs, nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user