Skip to content

Commit 61a5fda

Browse files
committed
Rename manager.Leading to manager.Elected
It's more intuitive to close the channel when a process (i.e. election) has completed, rather than when a state (i.e. leading) has been entered. Signed-off-by: Nic Cope <[email protected]>
1 parent 94b920b commit 61a5fda

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

pkg/controller/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func ExampleNewUnmanaged() {
152152
// Block until our controller manager is elected leader. We presume our
153153
// entire process will terminate if we lose leadership, so we don't need
154154
// to handle that.
155-
<-mgr.Leading()
155+
<-mgr.Elected()
156156

157157
// Start our controller. This will block until the stop channel is
158158
// closed, or the controller returns an error.

pkg/manager/internal.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ type controllerManager struct {
130130
// It and `internalStop` should point to the same channel.
131131
internalStopper chan<- struct{}
132132

133-
// leading is closed when this manager becomes the leader of a group of
133+
// elected is closed when this manager becomes the leader of a group of
134134
// managers, either because it won a leader election or because no leader
135135
// election was configured.
136-
leading chan struct{}
136+
elected chan struct{}
137137

138138
startCache func(stop <-chan struct{}) error
139139

@@ -429,7 +429,7 @@ func (cm *controllerManager) Start(stop <-chan struct{}) error {
429429
}
430430
} else {
431431
// Treat not having leader election enabled the same as being elected.
432-
close(cm.leading)
432+
close(cm.elected)
433433
go cm.startLeaderElectionRunnables()
434434
}
435435

@@ -518,7 +518,7 @@ func (cm *controllerManager) startLeaderElection() (err error) {
518518
RetryPeriod: cm.retryPeriod,
519519
Callbacks: leaderelection.LeaderCallbacks{
520520
OnStartedLeading: func(_ context.Context) {
521-
close(cm.leading)
521+
close(cm.elected)
522522
cm.startLeaderElectionRunnables()
523523
},
524524
OnStoppedLeading: func() {
@@ -547,6 +547,6 @@ func (cm *controllerManager) startLeaderElection() (err error) {
547547
return nil
548548
}
549549

550-
func (cm *controllerManager) Leading() <-chan struct{} {
551-
return cm.leading
550+
func (cm *controllerManager) Elected() <-chan struct{} {
551+
return cm.elected
552552
}

pkg/manager/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ type Manager interface {
5050
// non-leaderelection mode (always running) or leader election mode (managed by leader election if enabled).
5151
Add(Runnable) error
5252

53-
// Leading is closed when this manager becomes the leader of a group of
53+
// Elected is closed when this manager is elected leader of a group of
5454
// managers, either because it won a leader election or because no leader
5555
// election was configured.
56-
Leading() <-chan struct{}
56+
Elected() <-chan struct{}
5757

5858
// SetFields will set any dependencies on an object for which the object has implemented the inject
5959
// interface - e.g. inject.Client.
@@ -318,7 +318,7 @@ func New(config *rest.Config, options Options) (Manager, error) {
318318
metricsListener: metricsListener,
319319
internalStop: stop,
320320
internalStopper: stop,
321-
leading: make(chan struct{}),
321+
elected: make(chan struct{}),
322322
port: options.Port,
323323
host: options.Host,
324324
certDir: options.CertDir,

0 commit comments

Comments
 (0)