Skip to content

Commit

Permalink
poc
Browse files Browse the repository at this point in the history
  • Loading branch information
sanposhiho committed Nov 28, 2021
1 parent e4c7951 commit 4465ad4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
33 changes: 33 additions & 0 deletions pkg/scheduler/customplugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package scheduler

import (
"plugin"

"k8s.io/klog/v2"
frameworkruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
)

func loadPlugins(files map[string]string) frameworkruntime.Registry {
registry := map[string]frameworkruntime.PluginFactory{}

for k, f := range files {
p, err := plugin.Open(f)
if err != nil {
klog.Fatalf("failed to open plugin file: %s", f)
}

newfunc, err := p.Lookup("New")
if err != nil {
klog.Fatalf("New function is not found on custom plugin file: %v", err)
}

factory, ok := newfunc.(frameworkruntime.PluginFactory)
if !ok {
klog.Fatalf("New function is not frameworkruntime.PluginFactory")
}

registry[k] = factory
}

return registry
}
14 changes: 13 additions & 1 deletion pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ type schedulerOptions struct {
kubeConfig *restclient.Config
percentageOfNodesToScore int32
podInitialBackoffSeconds int64
podMaxBackoffSeconds int64
// customPluginFiles is built by `go build -buildmode=plugin` and should have `.so` extension.
customPluginFiles map[string]string
podMaxBackoffSeconds int64
// Contains out-of-tree plugins to be merged with the in-tree registry.
frameworkOutOfTreeRegistry frameworkruntime.Registry
profiles []schedulerapi.KubeSchedulerProfile
Expand Down Expand Up @@ -165,6 +167,12 @@ func WithPodInitialBackoffSeconds(podInitialBackoffSeconds int64) Option {
}
}

func WithCustomPluginFiles(files map[string]string) Option {
return func(o *schedulerOptions) {
o.customPluginFiles = files
}
}

// WithPodMaxBackoffSeconds sets podMaxBackoffSeconds for Scheduler, the default value is 10
func WithPodMaxBackoffSeconds(podMaxBackoffSeconds int64) Option {
return func(o *schedulerOptions) {
Expand Down Expand Up @@ -235,6 +243,10 @@ func New(client clientset.Interface,
return nil, err
}

if err := registry.Merge(loadPlugins(options.customPluginFiles)); err != nil {
return nil, err
}

snapshot := internalcache.NewEmptySnapshot()
clusterEventMap := make(map[framework.ClusterEvent]sets.String)

Expand Down

0 comments on commit 4465ad4

Please sign in to comment.