Skip to content

Commit aa3f342

Browse files
[release-0.20] šŸ› Check to see if custom source implements fmt.Stringer when logging (#3077)
* add String() to source interface Signed-off-by: Troy Connor <[email protected]> * remove the enforcement of fmt.Stringer --------- Signed-off-by: Troy Connor <[email protected]> Co-authored-by: Troy Connor <[email protected]>
1 parent 8f7e114 commit aa3f342

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

ā€Žpkg/internal/controller/controller.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,16 @@ func (c *Controller[request]) Start(ctx context.Context) error {
175175
// caches.
176176
errGroup := &errgroup.Group{}
177177
for _, watch := range c.startWatches {
178-
log := c.LogConstructor(nil).WithValues("source", fmt.Sprintf("%s", watch))
178+
log := c.LogConstructor(nil)
179+
_, ok := watch.(interface {
180+
String() string
181+
})
182+
183+
if !ok {
184+
log = log.WithValues("source", fmt.Sprintf("%T", watch))
185+
} else {
186+
log = log.WithValues("source", fmt.Sprintf("%s", watch))
187+
}
179188
didStartSyncingSource := &atomic.Bool{}
180189
errGroup.Go(func() error {
181190
// Use a timeout for starting and syncing the source to avoid silently

0 commit comments

Comments
Ā (0)