Skip to content

Commit fb14682

Browse files
nirrozenbaumkfswain
authored andcommitted
removed cmd/registry file (kubernetes-sigs#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 397cd73 commit fb14682

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
@@ -46,9 +46,16 @@ import (
4646
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore"
4747
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics"
4848
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/metrics/collectors"
49+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
4950
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/requestcontrol"
5051
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/saturationdetector"
5152
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
53+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/filter"
54+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix"
55+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker"
56+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile"
57+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/scorer"
58+
testfilter "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/test/filter"
5259
runserver "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/server"
5360
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
5461
"sigs.k8s.io/gateway-api-inference-extension/version"
@@ -357,6 +364,23 @@ func (r *Runner) Run(ctx context.Context) error {
357364
return nil
358365
}
359366

367+
// registerInTreePlugins registers the factory functions of all known plugins
368+
func (r *Runner) registerInTreePlugins() {
369+
plugins.Register(filter.DecisionTreeFilterType, filter.DecisionTreeFilterFactory)
370+
plugins.Register(filter.LeastKVCacheFilterType, filter.LeastKVCacheFilterFactory)
371+
plugins.Register(filter.LeastQueueFilterType, filter.LeastQueueFilterFactory)
372+
plugins.Register(filter.LoraAffinityFilterType, filter.LoraAffinityFilterFactory)
373+
plugins.Register(filter.LowQueueFilterType, filter.LowQueueFilterFactory)
374+
plugins.Register(prefix.PrefixCachePluginType, prefix.PrefixCachePluginFactory)
375+
plugins.Register(picker.MaxScorePickerType, picker.MaxScorePickerFactory)
376+
plugins.Register(picker.RandomPickerType, picker.RandomPickerFactory)
377+
plugins.Register(profile.SingleProfileHandlerType, profile.SingleProfileHandlerFactory)
378+
plugins.Register(scorer.KvCacheScorerType, scorer.KvCacheScorerFactory)
379+
plugins.Register(scorer.QueueScorerType, scorer.QueueScorerFactory)
380+
// register filter for test purpose only (used in conformance tests)
381+
plugins.Register(testfilter.HeaderBasedTestingFilterType, testfilter.HeaderBasedTestingFilterFactory)
382+
}
383+
360384
func (r *Runner) parsePluginsConfiguration(ctx context.Context) error {
361385
if *configText == "" && *configFile == "" {
362386
return nil // configuring through code, not through file
@@ -373,7 +397,8 @@ func (r *Runner) parsePluginsConfiguration(ctx context.Context) error {
373397
}
374398
}
375399

376-
handle := newEppHandle(ctx)
400+
r.registerInTreePlugins()
401+
handle := plugins.NewEppHandle(ctx)
377402
config, err := loader.LoadConfig(configBytes, handle)
378403
if err != nil {
379404
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)