Skip to content

Commit 041e0ca

Browse files
committed
Added a context.Context to the plugins.Handle interface
Signed-off-by: Shmuel Kallner <[email protected]>
1 parent 8dc40a5 commit 041e0ca

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

cmd/epp/runner/register.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package runner
1818

1919
import (
20+
"context"
21+
2022
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
2123
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/filter"
2224
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/multi/prefix"
@@ -42,9 +44,15 @@ func RegisterAllPlugins() {
4244

4345
// eppHandle is an implementation of the interface plugins.Handle
4446
type eppHandle struct {
47+
ctx context.Context
4548
plugins plugins.HandlePlugins
4649
}
4750

51+
// Context returns a context the plugins can use, if they need one
52+
func (h *eppHandle) Context() context.Context {
53+
return h.ctx
54+
}
55+
4856
// Plugins returns the sub-handle for working with instantiated plugins
4957
func (h *eppHandle) Plugins() plugins.HandlePlugins {
5058
return h.plugins
@@ -79,8 +87,9 @@ func (h *eppHandlePlugins) GetAllPluginsWithNames() map[string]plugins.Plugin {
7987
return h.thePlugins
8088
}
8189

82-
func newEppHandle() *eppHandle {
90+
func newEppHandle(ctx context.Context) *eppHandle {
8391
return &eppHandle{
92+
ctx: ctx,
8493
plugins: &eppHandlePlugins{
8594
thePlugins: map[string]plugins.Plugin{},
8695
},

pkg/epp/plugins/plugins.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ limitations under the License.
1616

1717
package plugins
1818

19+
import "context"
20+
1921
// Plugin defines the interface for a plugin.
2022
// This interface should be embedded in all plugins across the code.
2123
type Plugin interface {
@@ -27,6 +29,9 @@ type Plugin interface {
2729

2830
// Handle provides plugins a set of standard data and tools to work with
2931
type Handle interface {
32+
// Context returns a context the plugins can use, if they need one
33+
Context() context.Context
34+
3035
// Plugins returns the sub-handle for working with instantiated plugins
3136
Plugins() HandlePlugins
3237
}

test/utils/handle.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,23 @@ limitations under the License.
1616

1717
package utils
1818

19-
import "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
19+
import (
20+
"context"
21+
22+
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
23+
)
2024

2125
// testHandle is an implmentation of plugins.Handle for test purposes
2226
type testHandle struct {
27+
ctx context.Context
2328
plugins plugins.HandlePlugins
2429
}
2530

31+
// Context returns a context the plugins can use, if they need one
32+
func (h *testHandle) Context() context.Context {
33+
return h.ctx
34+
}
35+
2636
func (h *testHandle) Plugins() plugins.HandlePlugins {
2737
return h.plugins
2838
}
@@ -51,8 +61,9 @@ func (h *testHandlePlugins) GetAllPluginsWithNames() map[string]plugins.Plugin {
5161
return h.thePlugins
5262
}
5363

54-
func NewTestHandle() plugins.Handle {
64+
func NewTestHandle(ctx context.Context) plugins.Handle {
5565
return &testHandle{
66+
ctx: ctx,
5667
plugins: &testHandlePlugins{
5768
thePlugins: map[string]plugins.Plugin{},
5869
},

0 commit comments

Comments
 (0)