Move scheduler plugin set and configuration defaulting to component config
This commit is contained in:
@@ -17,28 +17,32 @@ limitations under the License.
|
||||
package testing
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/kube-scheduler/config/v1beta2"
|
||||
schedulerapi "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
"k8s.io/kubernetes/pkg/scheduler/apis/config/scheme"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework"
|
||||
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
|
||||
)
|
||||
|
||||
var configDecoder = scheme.Codecs.UniversalDecoder()
|
||||
|
||||
// NewFramework creates a Framework from the register functions and options.
|
||||
func NewFramework(fns []RegisterPluginFunc, profileName string, opts ...runtime.Option) (framework.Framework, error) {
|
||||
registry := runtime.Registry{}
|
||||
plugins := &schedulerapi.Plugins{}
|
||||
for _, f := range fns {
|
||||
f(®istry, plugins)
|
||||
}
|
||||
profile := &schedulerapi.KubeSchedulerProfile{
|
||||
SchedulerName: profileName,
|
||||
Plugins: plugins,
|
||||
Plugins: &schedulerapi.Plugins{},
|
||||
}
|
||||
for _, f := range fns {
|
||||
f(®istry, profile)
|
||||
}
|
||||
return runtime.NewFramework(registry, profile, opts...)
|
||||
}
|
||||
|
||||
// RegisterPluginFunc is a function signature used in method RegisterFilterPlugin()
|
||||
// to register a Filter Plugin to a given registry.
|
||||
type RegisterPluginFunc func(reg *runtime.Registry, plugins *schedulerapi.Plugins)
|
||||
type RegisterPluginFunc func(reg *runtime.Registry, profile *schedulerapi.KubeSchedulerProfile)
|
||||
|
||||
// RegisterQueueSortPlugin returns a function to register a QueueSort Plugin to a given registry.
|
||||
func RegisterQueueSortPlugin(pluginName string, pluginNewFunc runtime.PluginFactory) RegisterPluginFunc {
|
||||
@@ -92,15 +96,24 @@ func RegisterPluginAsExtensions(pluginName string, pluginNewFunc runtime.PluginF
|
||||
|
||||
// RegisterPluginAsExtensionsWithWeight returns a function to register a Plugin as given extensionPoints with weight to a given registry.
|
||||
func RegisterPluginAsExtensionsWithWeight(pluginName string, weight int32, pluginNewFunc runtime.PluginFactory, extensions ...string) RegisterPluginFunc {
|
||||
return func(reg *runtime.Registry, plugins *schedulerapi.Plugins) {
|
||||
return func(reg *runtime.Registry, profile *schedulerapi.KubeSchedulerProfile) {
|
||||
reg.Register(pluginName, pluginNewFunc)
|
||||
for _, extension := range extensions {
|
||||
ps := getPluginSetByExtension(plugins, extension)
|
||||
ps := getPluginSetByExtension(profile.Plugins, extension)
|
||||
if ps == nil {
|
||||
continue
|
||||
}
|
||||
ps.Enabled = append(ps.Enabled, schedulerapi.Plugin{Name: pluginName, Weight: weight})
|
||||
}
|
||||
// Use defaults from latest config API version.
|
||||
var gvk schema.GroupVersionKind
|
||||
gvk = v1beta2.SchemeGroupVersion.WithKind(pluginName + "Args")
|
||||
if args, _, err := configDecoder.Decode(nil, &gvk, nil); err == nil {
|
||||
profile.PluginConfig = append(profile.PluginConfig, schedulerapi.PluginConfig{
|
||||
Name: pluginName,
|
||||
Args: args,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user