mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-14 22:28:58 +00:00
chore: Add VeryShortWatchError typed error
- Add a new VeryShortWatchError struct for error matching, returned by `handleAnyWatch`, up through `Reflector.ListAndWatch`. - Update test expectations to match exact errors. Kubernetes-commit: 6eff9db0f10db72f2c64390e106a80621d136439
This commit is contained in:
committed by
Kubernetes Publisher
parent
1601be3d14
commit
921628ecd6
15
tools/cache/reflector.go
vendored
15
tools/cache/reflector.go
vendored
@@ -960,7 +960,7 @@ loop:
|
||||
|
||||
watchDuration := clock.Since(start)
|
||||
if watchDuration < 1*time.Second && eventCount == 0 {
|
||||
return watchListBookmarkReceived, fmt.Errorf("very short watch: %s: Unexpected watch close - watch lasted less than a second and no items received", name)
|
||||
return watchListBookmarkReceived, &VeryShortWatchError{Name: name}
|
||||
}
|
||||
klog.FromContext(ctx).V(4).Info("Watch close", "reflector", name, "type", expectedTypeName, "totalItems", eventCount)
|
||||
return watchListBookmarkReceived, nil
|
||||
@@ -1162,3 +1162,16 @@ type noopTicker struct{}
|
||||
func (t *noopTicker) C() <-chan time.Time { return nil }
|
||||
|
||||
func (t *noopTicker) Stop() {}
|
||||
|
||||
// VeryShortWatchError is returned when the watch result channel is closed
|
||||
// within one second, without having sent any events.
|
||||
type VeryShortWatchError struct {
|
||||
// Name of the Reflector
|
||||
Name string
|
||||
}
|
||||
|
||||
// Error implements the error interface
|
||||
func (e *VeryShortWatchError) Error() string {
|
||||
return fmt.Sprintf("very short watch: %s: Unexpected watch close - "+
|
||||
"watch lasted less than a second and no items received", e.Name)
|
||||
}
|
||||
|
Reference in New Issue
Block a user