Skip to content
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

🐛 Check to see if custom source implements fmt.Stringer when logging #3068

Merged
Merged
Changes from 1 commit
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
Next Next commit
add String() to source interface
Signed-off-by: Troy Connor <[email protected]>
troy0820 committed Jan 13, 2025

Verified

This commit was signed with the committer’s verified signature.
troy0820 Troy Connor
commit 707562c7b513025f787c57187aff4330764bb30f
2 changes: 1 addition & 1 deletion pkg/internal/controller/controller.go
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ func (c *Controller[request]) Start(ctx context.Context) error {
// caches.
errGroup := &errgroup.Group{}
for _, watch := range c.startWatches {
log := c.LogConstructor(nil).WithValues("source", fmt.Sprintf("%s", watch))
log := c.LogConstructor(nil).WithValues("source", watch.String())
Copy link
Member

Choose a reason for hiding this comment

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

It is an interesting issue - How about rather then requiring the implementation of fmt.Stringer, we check if it is implemented and if yes use that, otherwise use the Type (i.E. fmt.Sprintf("%T", watch))? That way we avoid the breaking change

didStartSyncingSource := &atomic.Bool{}
errGroup.Go(func() error {
// Use a timeout for starting and syncing the source to avoid silently
4 changes: 4 additions & 0 deletions pkg/source/source.go
Original file line number Diff line number Diff line change
@@ -56,6 +56,10 @@ type TypedSource[request comparable] interface {
// Start is internal and should be called only by the Controller to start the source.
// Start must be non-blocking.
Start(context.Context, workqueue.TypedRateLimitingInterface[request]) error

// String enforces the custom source to adhere to the fmt.Stringer interface
// to print when being logged.
String() string
}

// SyncingSource is a source that needs syncing prior to being usable. The controller