From 707562c7b513025f787c57187aff4330764bb30f Mon Sep 17 00:00:00 2001 From: Troy Connor Date: Mon, 13 Jan 2025 13:12:35 -0500 Subject: [PATCH 1/2] add String() to source interface Signed-off-by: Troy Connor --- pkg/internal/controller/controller.go | 2 +- pkg/source/source.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/internal/controller/controller.go b/pkg/internal/controller/controller.go index fda25e0641..8feed0744f 100644 --- a/pkg/internal/controller/controller.go +++ b/pkg/internal/controller/controller.go @@ -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()) didStartSyncingSource := &atomic.Bool{} errGroup.Go(func() error { // Use a timeout for starting and syncing the source to avoid silently diff --git a/pkg/source/source.go b/pkg/source/source.go index 267a6470b8..130dcb3d27 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -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 From 57a711c523de30dc8014602dc8704ac09dfce284 Mon Sep 17 00:00:00 2001 From: Troy Connor Date: Sun, 19 Jan 2025 14:19:26 -0500 Subject: [PATCH 2/2] remove the enforcement of fmt.Stringer --- pkg/internal/controller/controller.go | 11 ++++++++++- pkg/source/source.go | 4 ---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/internal/controller/controller.go b/pkg/internal/controller/controller.go index 8feed0744f..25575cca7c 100644 --- a/pkg/internal/controller/controller.go +++ b/pkg/internal/controller/controller.go @@ -175,7 +175,16 @@ func (c *Controller[request]) Start(ctx context.Context) error { // caches. errGroup := &errgroup.Group{} for _, watch := range c.startWatches { - log := c.LogConstructor(nil).WithValues("source", watch.String()) + log := c.LogConstructor(nil) + _, ok := watch.(interface { + String() string + }) + + if !ok { + log = log.WithValues("source", fmt.Sprintf("%T", watch)) + } else { + log = log.WithValues("source", fmt.Sprintf("%s", watch)) + } didStartSyncingSource := &atomic.Bool{} errGroup.Go(func() error { // Use a timeout for starting and syncing the source to avoid silently diff --git a/pkg/source/source.go b/pkg/source/source.go index 130dcb3d27..267a6470b8 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -56,10 +56,6 @@ 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