@@ -34,29 +34,34 @@ func (r *LeaderOrNonLeader) NeedLeaderElection() bool {
34
34
return false
35
35
}
36
36
37
- // EnableAfterBecameLeader is a Runnable that will call the enable function when the current instance becomes
37
+ // CallFunctionsAfterBecameLeader is a Runnable that will call the given functions when the current instance becomes
38
38
// the leader.
39
- type EnableAfterBecameLeader struct {
40
- enable func (context.Context )
39
+ type CallFunctionsAfterBecameLeader struct {
40
+ enableFunctions [] func (context.Context )
41
41
}
42
42
43
43
var (
44
- _ manager.LeaderElectionRunnable = & EnableAfterBecameLeader {}
45
- _ manager.Runnable = & EnableAfterBecameLeader {}
44
+ _ manager.LeaderElectionRunnable = & CallFunctionsAfterBecameLeader {}
45
+ _ manager.Runnable = & CallFunctionsAfterBecameLeader {}
46
46
)
47
47
48
- // NewEnableAfterBecameLeader creates a new EnableAfterBecameLeader Runnable.
49
- func NewEnableAfterBecameLeader (enable func (context.Context )) * EnableAfterBecameLeader {
50
- return & EnableAfterBecameLeader {
51
- enable : enable ,
48
+ // NewCallFunctionsAfterBecameLeader creates a new CallFunctionsAfterBecameLeader Runnable.
49
+ func NewCallFunctionsAfterBecameLeader (
50
+ enableFunctions []func (context.Context ),
51
+ ) * CallFunctionsAfterBecameLeader {
52
+ return & CallFunctionsAfterBecameLeader {
53
+ enableFunctions : enableFunctions ,
52
54
}
53
55
}
54
56
55
- func (j * EnableAfterBecameLeader ) Start (ctx context.Context ) error {
56
- j .enable (ctx )
57
+ func (j * CallFunctionsAfterBecameLeader ) Start (ctx context.Context ) error {
58
+ for _ , f := range j .enableFunctions {
59
+ f (ctx )
60
+ }
61
+
57
62
return nil
58
63
}
59
64
60
- func (j * EnableAfterBecameLeader ) NeedLeaderElection () bool {
65
+ func (j * CallFunctionsAfterBecameLeader ) NeedLeaderElection () bool {
61
66
return true
62
67
}
0 commit comments