Skip to content
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
2 changes: 0 additions & 2 deletions cmd/epp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import (
)

func main() {
// Register all known plugin factories
runner.RegisterAllPlugins()
// For adding out-of-tree plugins to the plugins registry, use the following:
// plugins.Register(my-out-of-tree-plugin-name, my-out-of-tree-plugin-factory-function)

Expand Down
95 changes: 0 additions & 95 deletions cmd/epp/runner/register.go

This file was deleted.

27 changes: 26 additions & 1 deletion cmd/epp/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ import (
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics/collectors"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/filter"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/scorer"
testfilter "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test/filter"
runserver "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/server"
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
"sigs.k8s.io/gateway-api-inference-extension/version"
Expand Down Expand Up @@ -335,6 +342,23 @@ func (r *Runner) Run(ctx context.Context) error {
return nil
}

// registerInTreePlugins registers the factory functions of all known plugins
func (r *Runner) registerInTreePlugins() {
plugins.Register(filter.DecisionTreeFilterType, filter.DecisionTreeFilterFactory)
plugins.Register(filter.LeastKVCacheFilterType, filter.LeastKVCacheFilterFactory)
plugins.Register(filter.LeastQueueFilterType, filter.LeastQueueFilterFactory)
plugins.Register(filter.LoraAffinityFilterType, filter.LoraAffinityFilterFactory)
plugins.Register(filter.LowQueueFilterType, filter.LowQueueFilterFactory)
plugins.Register(prefix.PrefixCachePluginType, prefix.PrefixCachePluginFactory)
plugins.Register(picker.MaxScorePickerType, picker.MaxScorePickerFactory)
plugins.Register(picker.RandomPickerType, picker.RandomPickerFactory)
plugins.Register(profile.SingleProfileHandlerType, profile.SingleProfileHandlerFactory)
plugins.Register(scorer.KvCacheScorerType, scorer.KvCacheScorerFactory)
plugins.Register(scorer.QueueScorerType, scorer.QueueScorerFactory)
// register filter for test purpose only (used in conformance tests)
plugins.Register(testfilter.HeaderBasedTestingFilterType, testfilter.HeaderBasedTestingFilterFactory)
}

func (r *Runner) parsePluginsConfiguration(ctx context.Context) error {
if *configText == "" && *configFile == "" {
return nil // configuring through code, not through file
Expand All @@ -351,7 +375,8 @@ func (r *Runner) parsePluginsConfiguration(ctx context.Context) error {
}
}

handle := newEppHandle(ctx)
r.registerInTreePlugins()
handle := plugins.NewEppHandle(ctx)
config, err := loader.LoadConfig(configBytes, handle)
if err != nil {
return fmt.Errorf("failed to load the configuration - %w", err)
Expand Down
49 changes: 49 additions & 0 deletions pkg/epp/plugins/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,55 @@ type HandlePlugins interface {
GetAllPluginsWithNames() map[string]Plugin
}

// eppHandle is an implementation of the interface plugins.Handle
type eppHandle struct {
ctx context.Context
HandlePlugins
}

// Context returns a context the plugins can use, if they need one
func (h *eppHandle) Context() context.Context {
return h.ctx
}

// eppHandlePlugins implements the set of APIs to work with instantiated plugins
type eppHandlePlugins struct {
plugins map[string]Plugin
}

// Plugin returns the named plugin instance
func (h *eppHandlePlugins) Plugin(name string) Plugin {
return h.plugins[name]
}

// AddPlugin adds a plugin to the set of known plugin instances
func (h *eppHandlePlugins) AddPlugin(name string, plugin Plugin) {
h.plugins[name] = plugin
}

// GetAllPlugins returns all of the known plugins
func (h *eppHandlePlugins) GetAllPlugins() []Plugin {
result := make([]Plugin, 0)
for _, plugin := range h.plugins {
result = append(result, plugin)
}
return result
}

// GetAllPluginsWithNames returns al of the known plugins with their names
func (h *eppHandlePlugins) GetAllPluginsWithNames() map[string]Plugin {
return h.plugins
}

func NewEppHandle(ctx context.Context) Handle {
return &eppHandle{
ctx: ctx,
HandlePlugins: &eppHandlePlugins{
plugins: map[string]Plugin{},
},
}
}

// PluginByType retrieves the specified plugin by name and verifies its type
func PluginByType[P Plugin](handlePlugins HandlePlugins, name string) (P, error) {
var zero P
Expand Down