Skip to content

Commit dc5e05c

Browse files
committed
[chore] converge callbacks
Signed-off-by: Stepan Paksashvili <[email protected]>
1 parent a94a8e5 commit dc5e05c

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

pkg/addon-operator/converge/converge.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ type ConvergeState struct {
1616
Activation string
1717
CRDsEnsured bool
1818

19+
onConvergeStart func()
20+
onConvergeFinish func()
21+
1922
phaseMu sync.RWMutex
2023
phase ConvergePhase
2124
firstRunPhase FirstConvergePhase
@@ -29,6 +32,7 @@ const (
2932
WaitBeforeAll ConvergePhase = "WaitBeforeAll"
3033
WaitDeleteAndRunModules ConvergePhase = "WaitDeleteAndRunModules"
3134
WaitAfterAll ConvergePhase = "WaitAfterAll"
35+
Finished ConvergePhase = "Finished"
3236
)
3337

3438
type FirstConvergePhase int
@@ -47,6 +51,14 @@ func NewConvergeState() *ConvergeState {
4751
}
4852
}
4953

54+
func (cs *ConvergeState) SetOnConvergeStart(callback func()) {
55+
cs.onConvergeStart = callback
56+
}
57+
58+
func (cs *ConvergeState) SetOnConvergeFinish(callback func()) {
59+
cs.onConvergeFinish = callback
60+
}
61+
5062
func (cs *ConvergeState) SetFirstRunPhase(ph FirstConvergePhase) {
5163
cs.phaseMu.Lock()
5264
defer cs.phaseMu.Unlock()
@@ -66,6 +78,14 @@ func (cs *ConvergeState) SetPhase(ph ConvergePhase) {
6678
cs.phaseMu.Lock()
6779
defer cs.phaseMu.Unlock()
6880
cs.phase = ph
81+
82+
if ph == RunBeforeAll && cs.onConvergeStart != nil {
83+
cs.onConvergeStart()
84+
}
85+
86+
if ph == StandBy && cs.onConvergeFinish != nil {
87+
cs.onConvergeFinish()
88+
}
6989
}
7090

7191
func (cs *ConvergeState) GetPhase() ConvergePhase {

pkg/addon-operator/operator.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@ func WithLogger(logger *log.Logger) Option {
105105
}
106106
}
107107

108+
func WithOnConvergeStart(callback func()) Option {
109+
return func(operator *AddonOperator) {
110+
operator.ConvergeState.SetOnConvergeStart(callback)
111+
}
112+
}
113+
114+
func WithOnConvergeFinish(callback func()) Option {
115+
return func(operator *AddonOperator) {
116+
operator.ConvergeState.SetOnConvergeFinish(callback)
117+
}
118+
}
119+
108120
func NewAddonOperator(ctx context.Context, opts ...Option) *AddonOperator {
109121
cctx, cancel := context.WithCancel(ctx)
110122

@@ -657,7 +669,7 @@ func (op *AddonOperator) CreateAndStartQueuesForModuleHooks(moduleName string) {
657669
// log.Debugf("Queue '%s' started for module 'kubernetes' hook %s", hookBinding.Queue, hookName)
658670
// }
659671
// }
660-
//}
672+
// }
661673
}
662674

663675
func (op *AddonOperator) CreateReloadModulesTasks(moduleNames []string, logLabels map[string]string, eventDescription string) []sh_task.Task {

0 commit comments

Comments
 (0)