Skip to content

Commit b50ee68

Browse files
authored
removed cmd/registry file (#1206)
* removed cmd/registry file Signed-off-by: Nir Rozenbaum <[email protected]> * register Signed-off-by: Nir Rozenbaum <[email protected]> --------- Signed-off-by: Nir Rozenbaum <[email protected]>
1 parent 72db6f6 commit b50ee68

File tree

4 files changed

+75
-98
lines changed

4 files changed

+75
-98
lines changed

cmd/epp/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
)
2626

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

cmd/epp/runner/register.go

Lines changed: 0 additions & 95 deletions
This file was deleted.

cmd/epp/runner/runner.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,16 @@ import (
4444
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore"
4545
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics"
4646
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics/collectors"
47+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
4748
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol"
4849
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
4950
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
51+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/filter"
52+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix"
53+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
54+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
55+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/scorer"
56+
testfilter "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test/filter"
5057
runserver "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/server"
5158
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
5259
"sigs.k8s.io/gateway-api-inference-extension/version"
@@ -335,6 +342,23 @@ func (r *Runner) Run(ctx context.Context) error {
335342
return nil
336343
}
337344

345+
// registerInTreePlugins registers the factory functions of all known plugins
346+
func (r *Runner) registerInTreePlugins() {
347+
plugins.Register(filter.DecisionTreeFilterType, filter.DecisionTreeFilterFactory)
348+
plugins.Register(filter.LeastKVCacheFilterType, filter.LeastKVCacheFilterFactory)
349+
plugins.Register(filter.LeastQueueFilterType, filter.LeastQueueFilterFactory)
350+
plugins.Register(filter.LoraAffinityFilterType, filter.LoraAffinityFilterFactory)
351+
plugins.Register(filter.LowQueueFilterType, filter.LowQueueFilterFactory)
352+
plugins.Register(prefix.PrefixCachePluginType, prefix.PrefixCachePluginFactory)
353+
plugins.Register(picker.MaxScorePickerType, picker.MaxScorePickerFactory)
354+
plugins.Register(picker.RandomPickerType, picker.RandomPickerFactory)
355+
plugins.Register(profile.SingleProfileHandlerType, profile.SingleProfileHandlerFactory)
356+
plugins.Register(scorer.KvCacheScorerType, scorer.KvCacheScorerFactory)
357+
plugins.Register(scorer.QueueScorerType, scorer.QueueScorerFactory)
358+
// register filter for test purpose only (used in conformance tests)
359+
plugins.Register(testfilter.HeaderBasedTestingFilterType, testfilter.HeaderBasedTestingFilterFactory)
360+
}
361+
338362
func (r *Runner) parsePluginsConfiguration(ctx context.Context) error {
339363
if *configText == "" && *configFile == "" {
340364
return nil // configuring through code, not through file
@@ -351,7 +375,8 @@ func (r *Runner) parsePluginsConfiguration(ctx context.Context) error {
351375
}
352376
}
353377

354-
handle := newEppHandle(ctx)
378+
r.registerInTreePlugins()
379+
handle := plugins.NewEppHandle(ctx)
355380
config, err := loader.LoadConfig(configBytes, handle)
356381
if err != nil {
357382
return fmt.Errorf("failed to load the configuration - %w", err)

pkg/epp/plugins/handle.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,55 @@ type HandlePlugins interface {
4444
GetAllPluginsWithNames() map[string]Plugin
4545
}
4646

47+
// eppHandle is an implementation of the interface plugins.Handle
48+
type eppHandle struct {
49+
ctx context.Context
50+
HandlePlugins
51+
}
52+
53+
// Context returns a context the plugins can use, if they need one
54+
func (h *eppHandle) Context() context.Context {
55+
return h.ctx
56+
}
57+
58+
// eppHandlePlugins implements the set of APIs to work with instantiated plugins
59+
type eppHandlePlugins struct {
60+
plugins map[string]Plugin
61+
}
62+
63+
// Plugin returns the named plugin instance
64+
func (h *eppHandlePlugins) Plugin(name string) Plugin {
65+
return h.plugins[name]
66+
}
67+
68+
// AddPlugin adds a plugin to the set of known plugin instances
69+
func (h *eppHandlePlugins) AddPlugin(name string, plugin Plugin) {
70+
h.plugins[name] = plugin
71+
}
72+
73+
// GetAllPlugins returns all of the known plugins
74+
func (h *eppHandlePlugins) GetAllPlugins() []Plugin {
75+
result := make([]Plugin, 0)
76+
for _, plugin := range h.plugins {
77+
result = append(result, plugin)
78+
}
79+
return result
80+
}
81+
82+
// GetAllPluginsWithNames returns al of the known plugins with their names
83+
func (h *eppHandlePlugins) GetAllPluginsWithNames() map[string]Plugin {
84+
return h.plugins
85+
}
86+
87+
func NewEppHandle(ctx context.Context) Handle {
88+
return &eppHandle{
89+
ctx: ctx,
90+
HandlePlugins: &eppHandlePlugins{
91+
plugins: map[string]Plugin{},
92+
},
93+
}
94+
}
95+
4796
// PluginByType retrieves the specified plugin by name and verifies its type
4897
func PluginByType[P Plugin](handlePlugins HandlePlugins, name string) (P, error) {
4998
var zero P

0 commit comments

Comments
 (0)