1
0
mirror of https://github.com/kubernetes-sigs/descheduler.git synced 2026-01-26 21:31:18 +01:00
Files
descheduler/pkg/framework/pluginregistry/pluginregistry.go
Jan Chaloupka 3510aba01d Detect individual extension points from plugin types
- Populate extension points automatically from plugin types
- Make a list of enabled extension points based on a profile
  configuration
- Populate filter and pre-eviction filter handles from their
  corresponding extension points
2023-04-03 17:04:31 +02:00

72 lines
1.9 KiB
Go

/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package pluginregistry
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2"
frameworktypes "sigs.k8s.io/descheduler/pkg/framework/types"
)
var PluginRegistry Registry
type PluginUtilities struct {
PluginBuilder PluginBuilder
PluginType interface{}
// Just an example instance of this PluginArg so we can avoid having
// to deal with reflect Types
PluginArgInstance runtime.Object
PluginArgValidator PluginArgValidator
PluginArgDefaulter PluginArgDefaulter
}
type PluginBuilder = func(args runtime.Object, handle frameworktypes.Handle) (frameworktypes.Plugin, error)
type (
PluginArgValidator = func(args runtime.Object) error
PluginArgDefaulter = func(args runtime.Object)
)
type Registry map[string]PluginUtilities
func NewRegistry() Registry {
return Registry{}
}
func Register(
name string,
builderFunc PluginBuilder,
pluginType interface{},
exampleArg runtime.Object,
pluginArgValidator PluginArgValidator,
pluginArgDefaulter PluginArgDefaulter,
registry Registry,
) {
if _, ok := registry[name]; ok {
klog.V(10).InfoS("Plugin already registered", "plugin", name)
} else {
registry[name] = PluginUtilities{
PluginBuilder: builderFunc,
PluginType: pluginType,
PluginArgInstance: exampleArg,
PluginArgValidator: pluginArgValidator,
PluginArgDefaulter: pluginArgDefaulter,
}
}
}