Skip to content

Commit

Permalink
make sure all hooks have a hook controller set (#455)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Scherba <[email protected]>
  • Loading branch information
miklezzzz authored Mar 5, 2024
1 parent 763eb62 commit e2dec78
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
10 changes: 10 additions & 0 deletions pkg/module_manager/models/modules/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ func (bm *BasicModule) DeregisterHooks() {
bm.hooks.clean()
}

// HooksControllersReady returns controllersReady status of the hook storage
func (bm *BasicModule) HooksControllersReady() bool {
return bm.hooks.controllersReady
}

// SetHooksControllersReady sets controllersReady status of the hook storage to true
func (bm *BasicModule) SetHooksControllersReady() {
bm.hooks.controllersReady = true
}

// ResetState drops the module state
func (bm *BasicModule) ResetState() {
bm.state = &moduleState{
Expand Down
9 changes: 5 additions & 4 deletions pkg/module_manager/models/modules/hook_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (

// HooksStorage keep module hooks in order
type HooksStorage struct {
registered bool
lock sync.RWMutex
byBinding map[sh_op_types.BindingType][]*hooks.ModuleHook
byName map[string]*hooks.ModuleHook
registered bool
controllersReady bool
lock sync.RWMutex
byBinding map[sh_op_types.BindingType][]*hooks.ModuleHook
byName map[string]*hooks.ModuleHook
}

func newHooksStorage() *HooksStorage {
Expand Down
5 changes: 5 additions & 0 deletions pkg/module_manager/module_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,11 @@ func (mm *ModuleManager) LoopByBinding(binding BindingType, fn func(gh *hooks.Gl

for _, moduleName := range mm.enabledModules.GetAll() {
m := mm.GetModule(moduleName)
// skip module if its hooks don't have hook controllers set
if !m.HooksControllersReady() {
continue
}

moduleHooks := m.GetHooks(binding)
for _, mh := range moduleHooks {
fn(nil, m, mh)
Expand Down
3 changes: 3 additions & 0 deletions pkg/module_manager/module_manager_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func (mm *ModuleManager) RegisterModuleHooks(ml *modules.BasicModule, logLabels
})
}

// set controllersReady to true
ml.SetHooksControllersReady()

return nil
}

Expand Down

0 comments on commit e2dec78

Please sign in to comment.