Skip to content

Commit

Permalink
Log all errors from cache.GetInformer call
Browse files Browse the repository at this point in the history
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 <hoon@linecorp.com>
  • Loading branch information
Sunghoon Kang committed Apr 7, 2022
1 parent adc9fa9 commit 8aaf7d9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
}
Expand Down

0 comments on commit 8aaf7d9

Please sign in to comment.