Skip to content

🌱 Fixups to error when source.Start never returns #3008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,15 @@ func (c *Controller[request]) Start(ctx context.Context) error {
defer utilruntime.HandleCrash()

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

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

// Start the SharedIndexInformer factories to begin populating the SharedIndexInformer caches
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mentioned that the comment is in the wrong place and I ended up removing it entirely, as a source doesn't really necessitate a SharedIndexInformer at this point and I found it to be mostly just confusing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely makes sense!

c.LogConstructor(nil).Info("Starting Controller")

// All the watches have been started, we can reset the local slice.
Expand Down
4 changes: 2 additions & 2 deletions pkg/internal/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ var _ = Describe("controller", func() {
})

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

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

started = true
cancel()
cancel() // Cancel the context so ctrl.Start() doesn't block forever
return nil
})
Expect(ctrl.Watch(src)).NotTo(HaveOccurred())
Expand Down