From 8aaf7d90c02a33d778dbe3d79e7e10e8a019c80d Mon Sep 17 00:00:00 2001 From: Sunghoon Kang Date: Thu, 7 Apr 2022 11:11:54 +0900 Subject: [PATCH] Log all errors from cache.GetInformer call Currently, `kind.Start` prints the last error from the polling process, except for the NoKindMatchError. This behavior makes it users hard to debug the cause of the `getInformer` call failure since it always returns the context timeout error, which is the last error while polling. This commit logs all returned errors while calling `getInformer` in the polling process. Signed-off-by: Sunghoon Kang --- pkg/source/source.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/source/source.go b/pkg/source/source.go index 8e5f966da7..ad18c9eedb 100644 --- a/pkg/source/source.go +++ b/pkg/source/source.go @@ -24,6 +24,7 @@ import ( "time" "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/util/workqueue" "sigs.k8s.io/controller-runtime/pkg/client" @@ -133,9 +134,14 @@ func (ks *Kind) Start(ctx context.Context, handler handler.EventHandler, queue w i, lastErr = ks.cache.GetInformer(ctx, ks.Type) if lastErr != nil { kindMatchErr := &meta.NoKindMatchError{} - if errors.As(lastErr, &kindMatchErr) { + switch { + case errors.As(lastErr, &kindMatchErr): log.Error(lastErr, "if kind is a CRD, it should be installed before calling Start", "kind", kindMatchErr.GroupKind) + case runtime.IsNotRegisteredError(lastErr): + log.Error(lastErr, "kind must be registered to the Scheme") + default: + log.Error(lastErr, "failed to get informer from cache") } return false, nil // Retry. }