@@ -52,7 +52,11 @@ type controllerManager struct {
52
52
scheme * runtime.Scheme
53
53
54
54
// runnables is the set of Controllers that the controllerManager injects deps into and Starts.
55
+ // These Runnables are managed by lead election.
55
56
runnables []Runnable
57
+ // haRunnables is the set of webhook servers that the controllerManager injects deps into and Starts.
58
+ // These Runnables are in HA mode (not blocked by lead election)
59
+ haRunnables []Runnable
56
60
57
61
cache cache.Cache
58
62
@@ -114,8 +118,13 @@ func (cm *controllerManager) Add(r Runnable) error {
114
118
return err
115
119
}
116
120
117
- // Add the runnable to the list
118
- cm .runnables = append (cm .runnables , r )
121
+ // Add the runnable to the HA or the leader election list
122
+ if haRunable , ok := r .(HARunnable ); ok && haRunable .IsHARunnable () {
123
+ cm .haRunnables = append (cm .haRunnables , r )
124
+ } else {
125
+ cm .runnables = append (cm .runnables , r )
126
+ }
127
+
119
128
if cm .started {
120
129
// If already started, start the controller
121
130
go func () {
@@ -237,6 +246,8 @@ func (cm *controllerManager) Start(stop <-chan struct{}) error {
237
246
go cm .serveMetrics (cm .internalStop )
238
247
}
239
248
249
+ go cm .startHA ()
250
+
240
251
if cm .resourceLock != nil {
241
252
err := cm .startLeaderElection ()
242
253
if err != nil {
@@ -256,7 +267,7 @@ func (cm *controllerManager) Start(stop <-chan struct{}) error {
256
267
}
257
268
}
258
269
259
- func (cm * controllerManager ) start () {
270
+ func (cm * controllerManager ) startHA () {
260
271
cm .mu .Lock ()
261
272
defer cm .mu .Unlock ()
262
273
@@ -274,6 +285,24 @@ func (cm *controllerManager) start() {
274
285
// TODO(community): Check the return value and write a test
275
286
cm .cache .WaitForCacheSync (cm .internalStop )
276
287
288
+ // Start the HA runnables after the cache has synced
289
+ for _ , c := range cm .haRunnables {
290
+ // Controllers block, but we want to return an error if any have an error starting.
291
+ // Write any Start errors to a channel so we can return them
292
+ ctrl := c
293
+ go func () {
294
+ cm .errChan <- ctrl .Start (cm .internalStop )
295
+ }()
296
+ }
297
+
298
+ cm .started = true
299
+ }
300
+
301
+ func (cm * controllerManager ) start () {
302
+ // Wait for the caches to sync.
303
+ // TODO(community): Check the return value and write a test
304
+ cm .cache .WaitForCacheSync (cm .internalStop )
305
+
277
306
// Start the runnables after the cache has synced
278
307
for _ , c := range cm .runnables {
279
308
// Controllers block, but we want to return an error if any have an error starting.
0 commit comments