mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-25 22:51:40 +00:00
cache.ListWatchUntil should return err.ErrWaitTimeout
Clients shouldn't have to know about watch.ErrWatchClosed, which is typically a server side decision to close and always means "Timeout" in this conetxt. Kubernetes-commit: cbecf177274e6f6924d6ca756eccf0a55e2933c0
This commit is contained in:
parent
bb96050dfb
commit
8c1471aeda
10
tools/cache/listwatch.go
vendored
10
tools/cache/listwatch.go
vendored
@ -25,6 +25,7 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
"k8s.io/client-go/tools/pager"
|
"k8s.io/client-go/tools/pager"
|
||||||
@ -103,6 +104,8 @@ func (lw *ListWatch) Watch(options metav1.ListOptions) (watch.Interface, error)
|
|||||||
return lw.WatchFunc(options)
|
return lw.WatchFunc(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListWatchUntil checks the provided conditions against the items returned by the list watcher, returning wait.ErrWaitTimeout
|
||||||
|
// if timeout is exceeded without all conditions returning true, or an error if an error occurs.
|
||||||
// TODO: check for watch expired error and retry watch from latest point? Same issue exists for Until.
|
// TODO: check for watch expired error and retry watch from latest point? Same issue exists for Until.
|
||||||
func ListWatchUntil(timeout time.Duration, lw ListerWatcher, conditions ...watch.ConditionFunc) (*watch.Event, error) {
|
func ListWatchUntil(timeout time.Duration, lw ListerWatcher, conditions ...watch.ConditionFunc) (*watch.Event, error) {
|
||||||
if len(conditions) == 0 {
|
if len(conditions) == 0 {
|
||||||
@ -166,5 +169,10 @@ func ListWatchUntil(timeout time.Duration, lw ListerWatcher, conditions ...watch
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return watch.Until(timeout, watchInterface, remainingConditions...)
|
evt, err := watch.Until(timeout, watchInterface, remainingConditions...)
|
||||||
|
if err == watch.ErrWatchClosed {
|
||||||
|
// present a consistent error interface to callers
|
||||||
|
err = wait.ErrWaitTimeout
|
||||||
|
}
|
||||||
|
return evt, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user