From 118eb6925301054a24812d6ba646ca53e31d1679 Mon Sep 17 00:00:00 2001 From: Jeremy Facchetti Date: Mon, 8 Apr 2024 15:45:05 +0200 Subject: [PATCH] fixed registration --- plugin/manager.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/plugin/manager.go b/plugin/manager.go index 1db97c6a..802305f2 100644 --- a/plugin/manager.go +++ b/plugin/manager.go @@ -34,7 +34,7 @@ import ( func newManager() Manager { return &manager{ - interceptors: make(map[string]http.Handler), + interceptorsHandlers: make(map[string]http.Handler), } } @@ -52,8 +52,9 @@ type manager struct { syncers []syncertypes.Base - interceptors map[string]http.Handler - interceptorsPort int + interceptorsHandlers map[string]http.Handler + interceptors []Interceptor + interceptorsPort int proConfig v2.InitConfigPro @@ -198,10 +199,11 @@ func (m *manager) Register(syncer syncertypes.Base) error { if int, ok := syncer.(Interceptor); ok { for _, rule := range int.InterceptedRequests() { - if _, ok := m.interceptors[rule.HandlerName]; ok { + if _, ok := m.interceptorsHandlers[rule.HandlerName]; ok { return fmt.Errorf("could not add the interceptor %s because the handler name %s is already in use", int.Name(), rule.HandlerName) } - m.interceptors[rule.HandlerName] = int + m.interceptorsHandlers[rule.HandlerName] = int + m.interceptors = append(m.interceptors, int) } } else { m.syncers = append(m.syncers, syncer) @@ -226,7 +228,7 @@ func (m *manager) startInterceptors() error { responsewriters.InternalError(w, r, errors.New("header VCluster-Plugin-Handler-Name wasn't set")) return } - interceptorHandler, ok := m.interceptors[handlerName] + interceptorHandler, ok := m.interceptorsHandlers[handlerName] if !ok { responsewriters.InternalError(w, r, errors.New("header VCluster-Plugin-Handler-Name had no match")) return @@ -355,16 +357,8 @@ func (m *manager) start() error { } func (m *manager) findAllInterceptors() []Interceptor { - interceptors := make([]Interceptor, 0) - for _, s := range m.syncers { - interceptor, ok := s.(Interceptor) - if !ok { - continue - } - interceptors = append(interceptors, interceptor) - } - - return interceptors + klog.Info("len of m.interceptor is : ", len(m.interceptors)) + return m.interceptors } func (m *manager) findAllHooks() (map[types.VersionKindType][]ClientHook, error) {