File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed
Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -90,9 +90,10 @@ type controllerManager struct {
9090 // metricsListener is used to serve prometheus metrics
9191 metricsListener net.Listener
9292
93- mu sync.Mutex
94- started bool
95- errChan chan error
93+ mu sync.Mutex
94+ started bool
95+ startedLeader bool
96+ errChan chan error
9697
9798 // internalStop is the stop channel *actually* used by everything involved
9899 // with the manager as a stop channel, so that we can pass a stop channel
@@ -134,14 +135,18 @@ func (cm *controllerManager) Add(r Runnable) error {
134135 return err
135136 }
136137
138+ var shouldStart bool
139+
137140 // Add the runnable to the leader election or the non-leaderelection list
138141 if leRunnable , ok := r .(LeaderElectionRunnable ); ok && ! leRunnable .NeedLeaderElection () {
142+ shouldStart = cm .started
139143 cm .nonLeaderElectionRunnables = append (cm .nonLeaderElectionRunnables , r )
140144 } else {
145+ shouldStart = cm .startedLeader
141146 cm .leaderElectionRunnables = append (cm .leaderElectionRunnables , r )
142147 }
143148
144- if cm . started {
149+ if shouldStart {
145150 // If already started, start the controller
146151 go func () {
147152 cm .errChan <- r .Start (cm .internalStop )
@@ -314,6 +319,8 @@ func (cm *controllerManager) startLeaderElectionRunnables() {
314319 cm .errChan <- ctrl .Start (cm .internalStop )
315320 }()
316321 }
322+
323+ cm .startedLeader = true
317324}
318325
319326func (cm * controllerManager ) waitForCache () {
You can’t perform that action at this time.
0 commit comments