Skip to content

Commit 061a7ad

Browse files
committed
🌱 Fixups to error when source.Start never returns
Addresses the comments on #2997
1 parent b031a06 commit 061a7ad

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

pkg/internal/controller/controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,15 @@ func (c *Controller[request]) Start(ctx context.Context) error {
171171
defer utilruntime.HandleCrash()
172172

173173
// NB(directxman12): launch the sources *before* trying to wait for the
174-
// caches to sync so that they have a chance to register their intendeded
174+
// caches to sync so that they have a chance to register their intended
175175
// caches.
176176
errGroup := &errgroup.Group{}
177177
for _, watch := range c.startWatches {
178178
log := c.LogConstructor(nil).WithValues("source", fmt.Sprintf("%s", watch))
179179
didStartSyncingSource := &atomic.Bool{}
180180
errGroup.Go(func() error {
181-
// use a context with timeout for launching sources and syncing caches.
181+
// Use a timeout for starting and syncing the source to avoid silently
182+
// blocking startup indefinitely if it doesn't come up.
182183
sourceStartCtx, cancel := context.WithTimeout(ctx, c.CacheSyncTimeout)
183184
defer cancel()
184185

@@ -220,7 +221,6 @@ func (c *Controller[request]) Start(ctx context.Context) error {
220221
return err
221222
}
222223

223-
// Start the SharedIndexInformer factories to begin populating the SharedIndexInformer caches
224224
c.LogConstructor(nil).Info("Starting Controller")
225225

226226
// All the watches have been started, we can reset the local slice.

pkg/internal/controller/controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ var _ = Describe("controller", func() {
201201
})
202202

203203
It("should error when Start() is blocking forever", func() {
204-
ctrl.CacheSyncTimeout = 0
204+
ctrl.CacheSyncTimeout = time.Second
205205

206206
controllerDone := make(chan struct{})
207207
ctrl.startWatches = []source.TypedSource[reconcile.Request]{
@@ -304,7 +304,7 @@ var _ = Describe("controller", func() {
304304
Expect(q).To(Equal(ctrl.Queue))
305305

306306
started = true
307-
cancel()
307+
cancel() // Cancel the context so ctrl.Start() doesn't block forever
308308
return nil
309309
})
310310
Expect(ctrl.Watch(src)).NotTo(HaveOccurred())

0 commit comments

Comments
 (0)