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
This commit is contained in:
Karl Isenberg 2022-05-16 16:33:30 -07:00 committed by Kubernetes Publisher
parent ef63e495ba
commit 876406445a

View File

@ -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.