@@ -34,29 +34,34 @@ func (r *LeaderOrNonLeader) NeedLeaderElection() bool {
3434 return false
3535}
3636
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
3838// the leader.
39- type EnableAfterBecameLeader struct {
40- enable func (context.Context )
39+ type CallFunctionsAfterBecameLeader struct {
40+ enableFunctions [] func (context.Context )
4141}
4242
4343var (
44- _ manager.LeaderElectionRunnable = & EnableAfterBecameLeader {}
45- _ manager.Runnable = & EnableAfterBecameLeader {}
44+ _ manager.LeaderElectionRunnable = & CallFunctionsAfterBecameLeader {}
45+ _ manager.Runnable = & CallFunctionsAfterBecameLeader {}
4646)
4747
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 ,
5254 }
5355}
5456
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+
5762 return nil
5863}
5964
60- func (j * EnableAfterBecameLeader ) NeedLeaderElection () bool {
65+ func (j * CallFunctionsAfterBecameLeader ) NeedLeaderElection () bool {
6166 return true
6267}
0 commit comments