Skip to content

Commit

Permalink
fixed registration
Browse files Browse the repository at this point in the history
  • Loading branch information
facchettos committed Apr 8, 2024
1 parent 4061006 commit 118eb69
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

func newManager() Manager {
return &manager{
interceptors: make(map[string]http.Handler),
interceptorsHandlers: make(map[string]http.Handler),
}
}

Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 118eb69

Please sign in to comment.