From cfd59336233381151bbdb7474a7bfbc1aa0633d4 Mon Sep 17 00:00:00 2001 From: Jeremy Facchetti Date: Tue, 9 Apr 2024 14:10:28 +0200 Subject: [PATCH] corrected breaking changes --- e2e/test_plugin/syncers/interceptor.go | 5 ++--- plugin/manager.go | 4 ++-- plugin/server.go | 13 +++++++------ plugin/types.go | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/e2e/test_plugin/syncers/interceptor.go b/e2e/test_plugin/syncers/interceptor.go index 02e53bf3..15bf3d00 100644 --- a/e2e/test_plugin/syncers/interceptor.go +++ b/e2e/test_plugin/syncers/interceptor.go @@ -43,10 +43,9 @@ func (d DummyInterceptor) Name() string { return "testinterceptor" } -func (d DummyInterceptor) InterceptedRequests() []v2.Interceptor { - return []v2.Interceptor{ +func (d DummyInterceptor) InterceptionRules() []v2.InterceptorRule { + return []v2.InterceptorRule{ { - HandlerName: "testhandler", APIGroups: []string{"*"}, Resources: []string{"pods"}, ResourceNames: []string{"*"}, diff --git a/plugin/manager.go b/plugin/manager.go index 63f75d3c..3a4f0e23 100644 --- a/plugin/manager.go +++ b/plugin/manager.go @@ -53,7 +53,7 @@ type manager struct { syncers []syncertypes.Base interceptorsHandlers map[string]http.Handler - interceptors map[string][]Interceptor + interceptors []Interceptor interceptorsPort int proConfig v2.InitConfigPro @@ -202,7 +202,7 @@ func (m *manager) Register(syncer syncertypes.Base) error { return fmt.Errorf("could not add the interceptor %s because its name is already in use", int.Name()) } m.interceptorsHandlers[int.Name()] = int - m.interceptors[int.Name()] = append(m.interceptors[int.Name()], int) + m.interceptors = append(m.interceptors, int) } else { m.syncers = append(m.syncers, syncer) } diff --git a/plugin/server.go b/plugin/server.go index 63758152..9564bfd7 100644 --- a/plugin/server.go +++ b/plugin/server.go @@ -21,7 +21,7 @@ type server interface { Serve() // SetReady signals the plugin server the plugin is ready to start - SetReady(hooks map[types.VersionKindType][]ClientHook, interceptors map[string][]Interceptor, port int) + SetReady(hooks map[types.VersionKindType][]ClientHook, interceptors []Interceptor, port int) // Initialized retrieves the initialize request Initialized() <-chan *pluginv2.Initialize_Request @@ -44,7 +44,7 @@ type pluginServer struct { pluginv2.UnimplementedPluginServer hooks map[types.VersionKindType][]ClientHook - interceptors map[string][]Interceptor + interceptors []Interceptor interceptorsPort int initialized chan *pluginv2.Initialize_Request @@ -90,7 +90,7 @@ func (p *pluginServer) IsLeader() <-chan struct{} { return p.isLeader } -func (p *pluginServer) SetReady(hooks map[types.VersionKindType][]ClientHook, interceptors map[string][]Interceptor, port int) { +func (p *pluginServer) SetReady(hooks map[types.VersionKindType][]ClientHook, interceptors []Interceptor, port int) { p.hooks = hooks p.interceptors = interceptors p.interceptorsPort = port @@ -271,12 +271,13 @@ func (p *pluginServer) getClientHooks() ([]*v2.ClientHook, error) { return registeredHooks, nil } -func (p *pluginServer) getInterceptorConfig() map[string]v2.Interceptor { +func (p *pluginServer) getInterceptorConfig() map[string][]v2.InterceptorRule { + res := make(map[string][]v2.InterceptorRule) for _, interceptor := range p.interceptors { - interceptorConfig.Interceptors = append(interceptorConfig.Interceptors, interceptor.InterceptedRequests()...) + res[interceptor.Name()] = interceptor.InterceptionRules() } - return interceptorConfig + return res } var _ plugin.Plugin = &pluginServer{} diff --git a/plugin/types.go b/plugin/types.go index f0d55fff..696ae96c 100644 --- a/plugin/types.go +++ b/plugin/types.go @@ -65,8 +65,8 @@ type Interceptor interface { // Handler is the handler that will handle the requests delegated by the syncer http.Handler - // InterceptedRequests returns an rbac style struct which defines what to intercept - InterceptedRequests() []v2.Interceptor + // InterceptionRules returns an rbac style struct which defines what to intercept + InterceptionRules() []v2.InterceptorRule } type MutateCreateVirtual interface {