mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-12-25 01:07:45 +00:00
Move Plugin Args defaults to versioned packages
Signed-off-by: Aldo Culquicondor <acondor@google.com>
This commit is contained in:
@@ -29,8 +29,10 @@ import (
|
||||
"k8s.io/client-go/informers"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/klog"
|
||||
"k8s.io/kube-scheduler/config/v1alpha2"
|
||||
"k8s.io/kubernetes/pkg/controller/volume/scheduling"
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config/scheme"
|
||||
"k8s.io/kubernetes/pkg/scheduler/internal/parallelize"
|
||||
"k8s.io/kubernetes/pkg/scheduler/metrics"
|
||||
)
|
||||
@@ -54,6 +56,8 @@ const (
|
||||
permit = "Permit"
|
||||
)
|
||||
|
||||
var configDecoder = scheme.Codecs.UniversalDecoder()
|
||||
|
||||
// framework is the component responsible for initializing and running scheduler
|
||||
// plugins.
|
||||
type framework struct {
|
||||
@@ -197,7 +201,7 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
|
||||
// get needed plugins from config
|
||||
pg := f.pluginsNeeded(plugins)
|
||||
|
||||
pluginConfig := make(map[string]runtime.Object, 0)
|
||||
pluginConfig := make(map[string]runtime.Object, len(args))
|
||||
for i := range args {
|
||||
name := args[i].Name
|
||||
if _, ok := pluginConfig[name]; ok {
|
||||
@@ -214,7 +218,11 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
|
||||
continue
|
||||
}
|
||||
|
||||
p, err := factory(pluginConfig[name], f)
|
||||
args, err := getPluginArgsOrDefault(pluginConfig, name)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("getting args for Plugin %q: %w", name, err)
|
||||
}
|
||||
p, err := factory(args, f)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error initializing plugin %q: %v", name, err)
|
||||
}
|
||||
@@ -260,6 +268,25 @@ func NewFramework(r Registry, plugins *config.Plugins, args []config.PluginConfi
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// getPluginArgsOrDefault returns a configuration provided by the user or builds
|
||||
// a default from the scheme. Returns `nil, nil` if the plugin does not have a
|
||||
// defined arg types, such as in-tree plugins that don't require configuration
|
||||
// or out-of-tree plugins.
|
||||
func getPluginArgsOrDefault(pluginConfig map[string]runtime.Object, name string) (runtime.Object, error) {
|
||||
res, ok := pluginConfig[name]
|
||||
if ok {
|
||||
return res, nil
|
||||
}
|
||||
// Use defaults from latest config API version.
|
||||
gvk := v1alpha2.SchemeGroupVersion.WithKind(name + "Args")
|
||||
obj, _, err := configDecoder.Decode(nil, &gvk, nil)
|
||||
if runtime.IsNotRegisteredError(err) {
|
||||
// This plugin is out-of-tree or doesn't require configuration.
|
||||
return nil, nil
|
||||
}
|
||||
return obj, err
|
||||
}
|
||||
|
||||
func updatePluginList(pluginList interface{}, pluginSet *config.PluginSet, pluginsMap map[string]Plugin) error {
|
||||
if pluginSet == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user