mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-12-02 19:49:13 +00:00
Use internal config types in scheduling plugin args
Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
@@ -17,13 +17,9 @@ limitations under the License.
|
||||
package plugins
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/klog"
|
||||
schedulerv1alpha2 "k8s.io/kube-scheduler/config/v1alpha2"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpodtopologyspread"
|
||||
@@ -165,15 +161,15 @@ type ConfigProducerArgs struct {
|
||||
// Weight used for priority functions.
|
||||
Weight int32
|
||||
// NodeLabelArgs is the args for the NodeLabel plugin.
|
||||
NodeLabelArgs *schedulerv1alpha2.NodeLabelArgs
|
||||
NodeLabelArgs *config.NodeLabelArgs
|
||||
// RequestedToCapacityRatioArgs is the args for the RequestedToCapacityRatio plugin.
|
||||
RequestedToCapacityRatioArgs *schedulerv1alpha2.RequestedToCapacityRatioArgs
|
||||
RequestedToCapacityRatioArgs *config.RequestedToCapacityRatioArgs
|
||||
// ServiceAffinityArgs is the args for the ServiceAffinity plugin.
|
||||
ServiceAffinityArgs *schedulerv1alpha2.ServiceAffinityArgs
|
||||
ServiceAffinityArgs *config.ServiceAffinityArgs
|
||||
// NodeResourcesFitArgs is the args for the NodeResources fit filter.
|
||||
NodeResourcesFitArgs *schedulerv1alpha2.NodeResourcesFitArgs
|
||||
NodeResourcesFitArgs *config.NodeResourcesFitArgs
|
||||
// InterPodAffinityArgs is the args for InterPodAffinity plugin
|
||||
InterPodAffinityArgs *schedulerv1alpha2.InterPodAffinityArgs
|
||||
InterPodAffinityArgs *config.InterPodAffinityArgs
|
||||
}
|
||||
|
||||
// ConfigProducer returns the set of plugins and their configuration for a
|
||||
@@ -227,7 +223,8 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
plugins.Filter = appendToPluginSet(plugins.Filter, noderesources.FitName, nil)
|
||||
plugins.PreFilter = appendToPluginSet(plugins.PreFilter, noderesources.FitName, nil)
|
||||
if args.NodeResourcesFitArgs != nil {
|
||||
pluginConfig = append(pluginConfig, NewPluginConfig(noderesources.FitName, args.NodeResourcesFitArgs))
|
||||
pluginConfig = append(pluginConfig,
|
||||
config.PluginConfig{Name: noderesources.FitName, Args: args.NodeResourcesFitArgs})
|
||||
}
|
||||
plugins.Filter = appendToPluginSet(plugins.Filter, nodename.Name, nil)
|
||||
plugins.Filter = appendToPluginSet(plugins.Filter, nodeports.Name, nil)
|
||||
@@ -245,7 +242,8 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
plugins.Filter = appendToPluginSet(plugins.Filter, noderesources.FitName, nil)
|
||||
plugins.PreFilter = appendToPluginSet(plugins.PreFilter, noderesources.FitName, nil)
|
||||
if args.NodeResourcesFitArgs != nil {
|
||||
pluginConfig = append(pluginConfig, NewPluginConfig(noderesources.FitName, args.NodeResourcesFitArgs))
|
||||
pluginConfig = append(pluginConfig,
|
||||
config.PluginConfig{Name: noderesources.FitName, Args: args.NodeResourcesFitArgs})
|
||||
}
|
||||
return
|
||||
})
|
||||
@@ -320,7 +318,8 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
|
||||
plugins.Filter = appendToPluginSet(plugins.Filter, nodelabel.Name, nil)
|
||||
if args.NodeLabelArgs != nil {
|
||||
pluginConfig = append(pluginConfig, NewPluginConfig(nodelabel.Name, args.NodeLabelArgs))
|
||||
pluginConfig = append(pluginConfig,
|
||||
config.PluginConfig{Name: nodelabel.Name, Args: args.NodeLabelArgs})
|
||||
}
|
||||
return
|
||||
})
|
||||
@@ -328,7 +327,8 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
|
||||
plugins.Filter = appendToPluginSet(plugins.Filter, serviceaffinity.Name, nil)
|
||||
if args.ServiceAffinityArgs != nil {
|
||||
pluginConfig = append(pluginConfig, NewPluginConfig(serviceaffinity.Name, args.ServiceAffinityArgs))
|
||||
pluginConfig = append(pluginConfig,
|
||||
config.PluginConfig{Name: serviceaffinity.Name, Args: args.ServiceAffinityArgs})
|
||||
}
|
||||
plugins.PreFilter = appendToPluginSet(plugins.PreFilter, serviceaffinity.Name, nil)
|
||||
return
|
||||
@@ -362,7 +362,8 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
plugins.PreScore = appendToPluginSet(plugins.PreScore, interpodaffinity.Name, nil)
|
||||
plugins.Score = appendToPluginSet(plugins.Score, interpodaffinity.Name, &args.Weight)
|
||||
if args.InterPodAffinityArgs != nil {
|
||||
pluginConfig = append(pluginConfig, NewPluginConfig(interpodaffinity.Name, args.InterPodAffinityArgs))
|
||||
pluginConfig = append(pluginConfig,
|
||||
config.PluginConfig{Name: interpodaffinity.Name, Args: args.InterPodAffinityArgs})
|
||||
}
|
||||
return
|
||||
})
|
||||
@@ -390,7 +391,8 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
func(args ConfigProducerArgs) (plugins config.Plugins, pluginConfig []config.PluginConfig) {
|
||||
plugins.Score = appendToPluginSet(plugins.Score, noderesources.RequestedToCapacityRatioName, &args.Weight)
|
||||
if args.RequestedToCapacityRatioArgs != nil {
|
||||
pluginConfig = append(pluginConfig, NewPluginConfig(noderesources.RequestedToCapacityRatioName, args.RequestedToCapacityRatioArgs))
|
||||
pluginConfig = append(pluginConfig,
|
||||
config.PluginConfig{Name: noderesources.RequestedToCapacityRatioName, Args: args.RequestedToCapacityRatioArgs})
|
||||
}
|
||||
return
|
||||
})
|
||||
@@ -403,7 +405,8 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
weight := args.Weight * int32(len(args.NodeLabelArgs.PresentLabelsPreference)+len(args.NodeLabelArgs.AbsentLabelsPreference))
|
||||
plugins.Score = appendToPluginSet(plugins.Score, nodelabel.Name, &weight)
|
||||
if args.NodeLabelArgs != nil {
|
||||
pluginConfig = append(pluginConfig, NewPluginConfig(nodelabel.Name, args.NodeLabelArgs))
|
||||
pluginConfig = append(pluginConfig,
|
||||
config.PluginConfig{Name: nodelabel.Name, Args: args.NodeLabelArgs})
|
||||
}
|
||||
return
|
||||
})
|
||||
@@ -415,7 +418,8 @@ func NewLegacyRegistry() *LegacyRegistry {
|
||||
weight := args.Weight * int32(len(args.ServiceAffinityArgs.AntiAffinityLabelsPreference))
|
||||
plugins.Score = appendToPluginSet(plugins.Score, serviceaffinity.Name, &weight)
|
||||
if args.ServiceAffinityArgs != nil {
|
||||
pluginConfig = append(pluginConfig, NewPluginConfig(serviceaffinity.Name, args.ServiceAffinityArgs))
|
||||
pluginConfig = append(pluginConfig,
|
||||
config.PluginConfig{Name: serviceaffinity.Name, Args: args.ServiceAffinityArgs})
|
||||
}
|
||||
return
|
||||
})
|
||||
@@ -487,19 +491,6 @@ func appendToPluginSet(set *config.PluginSet, name string, weight *int32) *confi
|
||||
return set
|
||||
}
|
||||
|
||||
// NewPluginConfig builds a PluginConfig with the struct of args marshaled.
|
||||
// It panics if it fails to marshal.
|
||||
func NewPluginConfig(pluginName string, args interface{}) config.PluginConfig {
|
||||
encoding, err := json.Marshal(args)
|
||||
if err != nil {
|
||||
klog.Fatalf("failed to marshal %+v: %v", args, err)
|
||||
}
|
||||
return config.PluginConfig{
|
||||
Name: pluginName,
|
||||
Args: &runtime.Unknown{Raw: encoding},
|
||||
}
|
||||
}
|
||||
|
||||
// ProcessPredicatePolicy given a PredicatePolicy, return the plugin name implementing the predicate and update
|
||||
// the ConfigProducerArgs if necessary.
|
||||
func (lr *LegacyRegistry) ProcessPredicatePolicy(policy config.PredicatePolicy, pluginArgs *ConfigProducerArgs) string {
|
||||
@@ -526,7 +517,7 @@ func (lr *LegacyRegistry) ProcessPredicatePolicy(policy config.PredicatePolicy,
|
||||
if policy.Argument.ServiceAffinity != nil {
|
||||
// map LabelsPresence policy to ConfigProducerArgs that's used to configure the ServiceAffinity plugin.
|
||||
if pluginArgs.ServiceAffinityArgs == nil {
|
||||
pluginArgs.ServiceAffinityArgs = &schedulerv1alpha2.ServiceAffinityArgs{}
|
||||
pluginArgs.ServiceAffinityArgs = &config.ServiceAffinityArgs{}
|
||||
}
|
||||
pluginArgs.ServiceAffinityArgs.AffinityLabels = append(pluginArgs.ServiceAffinityArgs.AffinityLabels, policy.Argument.ServiceAffinity.Labels...)
|
||||
|
||||
@@ -539,7 +530,7 @@ func (lr *LegacyRegistry) ProcessPredicatePolicy(policy config.PredicatePolicy,
|
||||
if policy.Argument.LabelsPresence != nil {
|
||||
// Map LabelPresence policy to ConfigProducerArgs that's used to configure the NodeLabel plugin.
|
||||
if pluginArgs.NodeLabelArgs == nil {
|
||||
pluginArgs.NodeLabelArgs = &schedulerv1alpha2.NodeLabelArgs{}
|
||||
pluginArgs.NodeLabelArgs = &config.NodeLabelArgs{}
|
||||
}
|
||||
if policy.Argument.LabelsPresence.Presence {
|
||||
pluginArgs.NodeLabelArgs.PresentLabels = append(pluginArgs.NodeLabelArgs.PresentLabels, policy.Argument.LabelsPresence.Labels...)
|
||||
@@ -587,7 +578,7 @@ func (lr *LegacyRegistry) ProcessPriorityPolicy(policy config.PriorityPolicy, co
|
||||
// This name is then used to find the registered plugin and run the plugin instead of the priority.
|
||||
priorityName = serviceaffinity.Name
|
||||
if configProducerArgs.ServiceAffinityArgs == nil {
|
||||
configProducerArgs.ServiceAffinityArgs = &schedulerv1alpha2.ServiceAffinityArgs{}
|
||||
configProducerArgs.ServiceAffinityArgs = &config.ServiceAffinityArgs{}
|
||||
}
|
||||
configProducerArgs.ServiceAffinityArgs.AntiAffinityLabelsPreference = append(
|
||||
configProducerArgs.ServiceAffinityArgs.AntiAffinityLabelsPreference,
|
||||
@@ -601,7 +592,7 @@ func (lr *LegacyRegistry) ProcessPriorityPolicy(policy config.PriorityPolicy, co
|
||||
// This name is then used to find the registered plugin and run the plugin instead of the priority.
|
||||
priorityName = nodelabel.Name
|
||||
if configProducerArgs.NodeLabelArgs == nil {
|
||||
configProducerArgs.NodeLabelArgs = &schedulerv1alpha2.NodeLabelArgs{}
|
||||
configProducerArgs.NodeLabelArgs = &config.NodeLabelArgs{}
|
||||
}
|
||||
if policy.Argument.LabelPreference.Presence {
|
||||
configProducerArgs.NodeLabelArgs.PresentLabelsPreference = append(
|
||||
@@ -618,19 +609,19 @@ func (lr *LegacyRegistry) ProcessPriorityPolicy(policy config.PriorityPolicy, co
|
||||
|
||||
if policy.Argument.RequestedToCapacityRatioArguments != nil {
|
||||
policyArgs := policy.Argument.RequestedToCapacityRatioArguments
|
||||
args := &schedulerv1alpha2.RequestedToCapacityRatioArgs{}
|
||||
args := &config.RequestedToCapacityRatioArgs{}
|
||||
|
||||
args.Shape = make([]schedulerv1alpha2.UtilizationShapePoint, len(policyArgs.Shape))
|
||||
args.Shape = make([]config.UtilizationShapePoint, len(policyArgs.Shape))
|
||||
for i, s := range policyArgs.Shape {
|
||||
args.Shape[i] = schedulerv1alpha2.UtilizationShapePoint{
|
||||
args.Shape[i] = config.UtilizationShapePoint{
|
||||
Utilization: s.Utilization,
|
||||
Score: s.Score,
|
||||
}
|
||||
}
|
||||
|
||||
args.Resources = make([]schedulerv1alpha2.ResourceSpec, len(policyArgs.Resources))
|
||||
args.Resources = make([]config.ResourceSpec, len(policyArgs.Resources))
|
||||
for i, r := range policyArgs.Resources {
|
||||
args.Resources[i] = schedulerv1alpha2.ResourceSpec{
|
||||
args.Resources[i] = config.ResourceSpec{
|
||||
Name: r.Name,
|
||||
Weight: r.Weight,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user