Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions pkg/module_manager/module_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,8 @@ func (mm *ModuleManager) DeleteModule(ctx context.Context, moduleName string, lo

ml := mm.GetModule(moduleName)

// Stop kubernetes informers and remove scheduled functions
mm.DisableModuleHooks(moduleName)
// Note: keep kubernetes monitors alive until afterDeleteHelm runs,
// so hooks can access snapshots. We'll disable hooks after running them.

// DELETE
{
Expand Down Expand Up @@ -711,6 +711,9 @@ func (mm *ModuleManager) DeleteModule(ctx context.Context, moduleName string, lo
return fmt.Errorf("run hooks by bindng: %w", err)
}

// Now it is safe to stop kubernetes informers and remove scheduled functions
mm.DisableModuleHooks(moduleName)

// Cleanup state.
ml.ResetState()
}
Expand Down Expand Up @@ -891,6 +894,18 @@ func (mm *ModuleManager) EnableModuleScheduleBindings(moduleName string) {
}
}

// DisableModuleScheduleBindings disables schedule bindings of the module's hooks
func (mm *ModuleManager) DisableModuleScheduleBindings(moduleName string) {
ml := mm.GetModule(moduleName)
if !ml.HooksControllersReady() {
return
}
schHooks := ml.GetHooks(Schedule)
for _, mh := range schHooks {
mh.GetHookController().DisableScheduleBindings()
}
}

// DisableModuleHooks disables monitors/bindings of the module's hooks
// It's advisable to use this method only if next step is to completely disable the module (as a short-term commitment).
// Otherwise, as hooks are rather stateless, their confiuration may get overwritten, resulting in unexpected consequences.
Expand Down
3 changes: 2 additions & 1 deletion pkg/task/tasks/converge-modules/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ func (s *Task) Handle(ctx context.Context) queue.TaskResult {
// TODO disable hooks before was done in DiscoverModulesStateRefresh. Should we stick to this solution or disable events later during the handling each ModuleDelete task?
// Disable events for disabled modules.
for _, moduleName := range state.ModulesToDisable {
s.moduleManager.DisableModuleHooks(moduleName)
s.moduleManager.DisableModuleScheduleBindings(moduleName)
// s.moduleManager.DisableModuleHooks(moduleName)
// op.DrainModuleQueues(moduleName)
}
// Set ModulesToEnable list to properly run onStartup hooks for first converge.
Expand Down
Loading