Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support extra registry #75

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ func NewServer(kubeconfig, master string) (*Server, error) {
}, nil
}

func (server *Server) Start() {
r := server.setupRouter()
func (server *Server) Start(opts ...simulator.Option) {
r := server.setupRouter(opts...)

// listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
if err := r.Run(); err != nil {
panic(err)
}
}

func (server *Server) setupRouter() *gin.Engine {
func (server *Server) setupRouter(opts ...simulator.Option) *gin.Engine {
defer utilruntime.HandleCrash()
r := gin.Default()

Expand Down Expand Up @@ -176,7 +176,7 @@ func (server *Server) setupRouter() *gin.Engine {
AppResources[0].Resource.Pods = append(AppResources[0].Resource.Pods, pendingPods...)

// simulate
result, err := simulator.Simulate(ClusterResource, AppResources)
result, err := simulator.Simulate(ClusterResource, AppResources, opts...)
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return
Expand Down Expand Up @@ -252,7 +252,7 @@ func (server *Server) setupRouter() *gin.Engine {
AppResources[0].Resource.Pods = append(AppResources[0].Resource.Pods, pendingPods...)

// simulate
result, err := simulator.Simulate(ClusterResource, AppResources)
result, err := simulator.Simulate(ClusterResource, AppResources, opts...)
if err != nil {
c.JSON(http.StatusInternalServerError, err.Error())
return
Expand Down
12 changes: 11 additions & 1 deletion pkg/simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type simulatorOptions struct {
kubeconfig string
schedulerConfig string
writeToFile bool
extraRegistry frameworkruntime.Registry
}

// Option configures a Simulator
Expand All @@ -67,6 +68,7 @@ var defaultSimulatorOptions = simulatorOptions{
kubeconfig: "",
schedulerConfig: "",
writeToFile: false,
extraRegistry: make(map[string]frameworkruntime.PluginFactory),
}

// NewSimulator generates all components that will be needed to simulate scheduling and returns a complete simulator
Expand Down Expand Up @@ -143,6 +145,9 @@ func NewSimulator(opts ...Option) (*Simulator, error) {
return simonplugin.NewGpuSharePlugin(fakeClient, configuration, f)
},
}
for name, plugin := range options.extraRegistry {
bindRegistry[name] = plugin
}
sim.scheduler, err = scheduler.New(
sim.fakeclient,
sim.informerFactory,
Expand Down Expand Up @@ -384,7 +389,12 @@ func WithSchedulerConfig(schedulerConfig string) Option {
}
}

// WithSchedulerConfig sets schedulerConfig for Simulator, the default value is ""
func WithExtraRegistry(extraRegistry frameworkruntime.Registry) Option {
return func(o *simulatorOptions) {
o.extraRegistry = extraRegistry
}
}

func WriteToFile(writeToFile bool) Option {
return func(o *simulatorOptions) {
o.writeToFile = writeToFile
Expand Down