Skip to content

Commit a32d65c

Browse files
authored
Don't disable monitors before after delete hook run (#675)
Signed-off-by: Timur Tuktamyshev <timur.tuktamyshev@flant.com>
1 parent 01ecddb commit a32d65c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

pkg/module_manager/module_manager.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,8 @@ func (mm *ModuleManager) DeleteModule(ctx context.Context, moduleName string, lo
652652

653653
ml := mm.GetModule(moduleName)
654654

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

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

714+
// Now it is safe to stop kubernetes informers and remove scheduled functions
715+
mm.DisableModuleHooks(moduleName)
716+
714717
// Cleanup state.
715718
ml.ResetState()
716719
}
@@ -891,6 +894,18 @@ func (mm *ModuleManager) EnableModuleScheduleBindings(moduleName string) {
891894
}
892895
}
893896

897+
// DisableModuleScheduleBindings disables schedule bindings of the module's hooks
898+
func (mm *ModuleManager) DisableModuleScheduleBindings(moduleName string) {
899+
ml := mm.GetModule(moduleName)
900+
if !ml.HooksControllersReady() {
901+
return
902+
}
903+
schHooks := ml.GetHooks(Schedule)
904+
for _, mh := range schHooks {
905+
mh.GetHookController().DisableScheduleBindings()
906+
}
907+
}
908+
894909
// DisableModuleHooks disables monitors/bindings of the module's hooks
895910
// It's advisable to use this method only if next step is to completely disable the module (as a short-term commitment).
896911
// Otherwise, as hooks are rather stateless, their confiuration may get overwritten, resulting in unexpected consequences.

pkg/task/tasks/converge-modules/task.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ func (s *Task) Handle(ctx context.Context) queue.TaskResult {
147147
// TODO disable hooks before was done in DiscoverModulesStateRefresh. Should we stick to this solution or disable events later during the handling each ModuleDelete task?
148148
// Disable events for disabled modules.
149149
for _, moduleName := range state.ModulesToDisable {
150-
s.moduleManager.DisableModuleHooks(moduleName)
150+
s.moduleManager.DisableModuleScheduleBindings(moduleName)
151+
// s.moduleManager.DisableModuleHooks(moduleName)
151152
// op.DrainModuleQueues(moduleName)
152153
}
153154
// Set ModulesToEnable list to properly run onStartup hooks for first converge.

0 commit comments

Comments
 (0)