From 876406445a9beed191d699bbe8ae9fac2e677a72 Mon Sep 17 00:00:00 2001 From: Karl Isenberg Date: Mon, 16 May 2022 16:33:30 -0700 Subject: [PATCH] fix: reflector to return wrapped list errors This fix allows Reflector/Informer callers to detect API errors using the standard Go errors.As unwrapping methods used by the apimachinery helper methods. Combined with a custom WatchErrorHandler, this can be used to stop an informer that encounters specific errors, like resource not found or forbidden. Kubernetes-commit: 9ace604b63045ebbb066cab5e8508b51d0900a05 --- tools/cache/reflector.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/cache/reflector.go b/tools/cache/reflector.go index 84f24211..7274d727 100644 --- a/tools/cache/reflector.go +++ b/tools/cache/reflector.go @@ -322,7 +322,7 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error { initTrace.Step("Objects listed", trace.Field{Key: "error", Value: err}) if err != nil { klog.Warningf("%s: failed to list %v: %v", r.name, r.expectedTypeName, err) - return fmt.Errorf("failed to list %v: %v", r.expectedTypeName, err) + return fmt.Errorf("failed to list %v: %w", r.expectedTypeName, err) } // We check if the list was paginated and if so set the paginatedResult based on that.