From bc669b15b4c34f94711be41ceb7c9b8ca83dd450 Mon Sep 17 00:00:00 2001 From: Haiyan Meng Date: Wed, 20 Nov 2024 14:44:27 +0000 Subject: [PATCH] Log the syncing source when WaitForSync fails A controller may watch several sources. This change makes it easier to debug which source fails to be synced. --- pkg/internal/controller/controller.go | 2 +- pkg/internal/controller/controller_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/internal/controller/controller.go b/pkg/internal/controller/controller.go index 6b84d8caed..fda25e0641 100644 --- a/pkg/internal/controller/controller.go +++ b/pkg/internal/controller/controller.go @@ -197,7 +197,7 @@ func (c *Controller[request]) Start(ctx context.Context) error { } didStartSyncingSource.Store(true) if err := syncingSource.WaitForSync(sourceStartCtx); err != nil { - err := fmt.Errorf("failed to wait for %s caches to sync: %w", c.Name, err) + err := fmt.Errorf("failed to wait for %s caches to sync %v: %w", c.Name, syncingSource, err) log.Error(err, "Could not wait for Cache to sync") sourceStartErrChan <- err } diff --git a/pkg/internal/controller/controller_test.go b/pkg/internal/controller/controller_test.go index ec48d5d338..52f45612f2 100644 --- a/pkg/internal/controller/controller_test.go +++ b/pkg/internal/controller/controller_test.go @@ -171,7 +171,7 @@ var _ = Describe("controller", func() { err = ctrl.Start(context.TODO()) Expect(err).To(HaveOccurred()) - Expect(err.Error()).To(ContainSubstring("failed to wait for testcontroller caches to sync: timed out waiting for cache to be synced")) + Expect(err.Error()).To(ContainSubstring("failed to wait for testcontroller caches to sync kind source: *v1.Deployment: timed out waiting for cache to be synced")) }) It("should not error when controller Start context is cancelled during Sources WaitForSync", func() {