Skip to content

Commit 00f2ffa

Browse files
committed
Add back runnables change and call to nginx provisioner enable
1 parent 740ab42 commit 00f2ffa

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

internal/framework/runnables/runnables.go

+17-12
Original file line numberDiff line numberDiff line change
@@ -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

4343
var (
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
}

internal/framework/runnables/runnables_test.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,22 @@ func TestLeaderOrNonLeader(t *testing.T) {
2323
g.Expect(leaderOrNonLeader.NeedLeaderElection()).To(BeFalse())
2424
}
2525

26-
func TestEnableAfterBecameLeader(t *testing.T) {
26+
func TestCallFunctionsAfterBecameLeader(t *testing.T) {
2727
t.Parallel()
28-
enabled := false
29-
enableAfterBecameLeader := NewEnableAfterBecameLeader(func(_ context.Context) {
30-
enabled = true
28+
statusUpdaterEnabled := false
29+
provisionerEnabled := false
30+
31+
callFunctionsAfterBecameLeader := NewCallFunctionsAfterBecameLeader([]func(ctx context.Context){
32+
func(_ context.Context) { statusUpdaterEnabled = true },
33+
func(_ context.Context) { provisionerEnabled = true },
3134
})
3235

3336
g := NewWithT(t)
34-
g.Expect(enableAfterBecameLeader.NeedLeaderElection()).To(BeTrue())
35-
g.Expect(enabled).To(BeFalse())
37+
g.Expect(callFunctionsAfterBecameLeader.NeedLeaderElection()).To(BeTrue())
3638

37-
err := enableAfterBecameLeader.Start(context.Background())
39+
err := callFunctionsAfterBecameLeader.Start(context.Background())
3840
g.Expect(err).ToNot(HaveOccurred())
3941

40-
g.Expect(enabled).To(BeTrue())
42+
g.Expect(statusUpdaterEnabled).To(BeTrue())
43+
g.Expect(provisionerEnabled).To(BeTrue())
4144
}

internal/mode/static/manager.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,11 @@ func StartManager(cfg config.Config) error {
262262
return fmt.Errorf("cannot register event loop: %w", err)
263263
}
264264

265-
if err = mgr.Add(runnables.NewEnableAfterBecameLeader(groupStatusUpdater.Enable)); err != nil {
266-
return fmt.Errorf("cannot register status updater: %w", err)
265+
if err = mgr.Add(runnables.NewCallFunctionsAfterBecameLeader([]func(context.Context){
266+
groupStatusUpdater.Enable,
267+
nginxProvisioner.Enable,
268+
})); err != nil {
269+
return fmt.Errorf("cannot register functions that get called after Pod becomes leader: %w", err)
267270
}
268271

269272
if cfg.ProductTelemetryConfig.Enabled {

0 commit comments

Comments
 (0)