Skip to content

Commit 893c494

Browse files
committed
Rename unmanaged controller concepts
Signed-off-by: Nic Cope <[email protected]>
1 parent ea049a7 commit 893c494

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

pkg/controller/controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type Controller interface {
6767
// New returns a new Controller registered with the Manager. The Manager will ensure that shared Caches have
6868
// been synced before the Controller is Started.
6969
func New(name string, mgr manager.Manager, options Options) (Controller, error) {
70-
c, err := Configure(name, mgr, options)
70+
c, err := NewUnmanaged(name, mgr, options)
7171
if err != nil {
7272
return nil, err
7373
}
@@ -76,8 +76,9 @@ func New(name string, mgr manager.Manager, options Options) (Controller, error)
7676
return c, mgr.Add(c)
7777
}
7878

79-
// Configure a new controller without starting it or adding it to the manager.
80-
func Configure(name string, mgr manager.Manager, options Options) (Controller, error) {
79+
// NewUnmanaged returns a new controller without adding it to the manager. The
80+
// caller is responsible for starting the returned controller.
81+
func NewUnmanaged(name string, mgr manager.Manager, options Options) (Controller, error) {
8182
if options.Reconciler == nil {
8283
return nil, fmt.Errorf("must specify Reconciler")
8384
}

pkg/manager/internal.go

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

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

135138
startCache func(stop <-chan struct{}) error
136139

@@ -425,8 +428,8 @@ func (cm *controllerManager) Start(stop <-chan struct{}) error {
425428
return err
426429
}
427430
} else {
428-
// Treat not having an election the same as being elected.
429-
close(cm.elected)
431+
// Treat not having leader election enabled the same as being elected.
432+
close(cm.leading)
430433
go cm.startLeaderElectionRunnables()
431434
}
432435

@@ -515,7 +518,7 @@ func (cm *controllerManager) startLeaderElection() (err error) {
515518
RetryPeriod: cm.retryPeriod,
516519
Callbacks: leaderelection.LeaderCallbacks{
517520
OnStartedLeading: func(_ context.Context) {
518-
close(cm.elected)
521+
close(cm.leading)
519522
cm.startLeaderElectionRunnables()
520523
},
521524
OnStoppedLeading: func() {
@@ -544,6 +547,6 @@ func (cm *controllerManager) startLeaderElection() (err error) {
544547
return nil
545548
}
546549

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

pkg/manager/manager.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +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-
// Elected is closed when this manager is elected the leader, or when no
54-
// election is configured.
55-
Elected() <-chan struct{}
53+
// Leading is closed when this manager becomes the leader of a group of
54+
// managers, either because it won a leader election or because no leader
55+
// election was configured.
56+
Leading() <-chan struct{}
5657

5758
// SetFields will set any dependencies on an object for which the object has implemented the inject
5859
// interface - e.g. inject.Client.
@@ -317,7 +318,7 @@ func New(config *rest.Config, options Options) (Manager, error) {
317318
metricsListener: metricsListener,
318319
internalStop: stop,
319320
internalStopper: stop,
320-
elected: make(chan struct{}),
321+
leading: make(chan struct{}),
321322
port: options.Port,
322323
host: options.Host,
323324
certDir: options.CertDir,

0 commit comments

Comments
 (0)