forked from kubernetes-sigs/kube-scheduler-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.go
62 lines (51 loc) · 2.06 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package config
import (
"golang.org/x/xerrors"
configv1 "k8s.io/kube-scheduler/config/v1"
"k8s.io/kubernetes/pkg/scheduler/framework/plugins"
"k8s.io/kubernetes/pkg/scheduler/framework/runtime"
)
var (
outOfTreeRegistries = runtime.Registry{
// TODO(user): add your plugins registries here.
}
registeredOutOfTreeMultiPointName = []string{}
)
// RegisteredMultiPointPluginNames returns all registered multipoint plugin names.
// in-tree plugins and your original plugins listed in outOfTreeRegistries above.
func RegisteredMultiPointPluginNames() ([]string, error) {
def, err := InTreeMultiPointPluginSet()
if err != nil {
return nil, xerrors.Errorf("get default multi point plugins: %w", err)
}
enabledPls := make([]string, 0, len(def.Enabled))
for _, e := range def.Enabled {
enabledPls = append(enabledPls, e.Name)
}
return append(enabledPls, OutOfTreeMultiPointPluginNames()...), nil
}
// InTreeMultiPointPluginSet returns default multipoint plugins.
// See also: https://github.com/kubernetes/kubernetes/blob/475f9010f5faa7bdd439944a6f5f1ec206297602/pkg/scheduler/apis/config/v1/default_plugins.go#L30https://github.com/kubernetes/kubernetes/blob/475f9010f5faa7bdd439944a6f5f1ec206297602/pkg/scheduler/apis/config/v1/default_plugins.go#L30
func InTreeMultiPointPluginSet() (configv1.PluginSet, error) {
defaultConfig, err := DefaultSchedulerConfig()
if err != nil || len(defaultConfig.Profiles) != 1 {
// default Config should only have default-scheduler configuration.
return configv1.PluginSet{}, xerrors.Errorf("get default scheduler configuration: %w", err)
}
return defaultConfig.Profiles[0].Plugins.MultiPoint, nil
}
func OutOfTreeMultiPointPluginNames() []string {
return registeredOutOfTreeMultiPointName
}
func InTreeRegistries() runtime.Registry {
return plugins.NewInTreeRegistry()
}
func OutOfTreeRegistries() runtime.Registry {
return outOfTreeRegistries
}
func SetOutOfTreeRegistries(r runtime.Registry) {
for k, v := range r {
outOfTreeRegistries[k] = v
registeredOutOfTreeMultiPointName = append(registeredOutOfTreeMultiPointName, k)
}
}