mirror of
https://github.com/kubernetes/client-go.git
synced 2025-06-29 16:36:54 +00:00
Avoid going back in time in reflector framework
Kubernetes-commit: b2b285a766540278a768dc9e6bd07a3a676ae543
This commit is contained in:
parent
6f1579c35d
commit
7d13a606b3
17
tools/cache/reflector.go
vendored
17
tools/cache/reflector.go
vendored
@ -114,6 +114,9 @@ func NewNamedReflector(name string, lw ListerWatcher, expectedType interface{},
|
|||||||
period: time.Second,
|
period: time.Second,
|
||||||
resyncPeriod: resyncPeriod,
|
resyncPeriod: resyncPeriod,
|
||||||
clock: &clock.RealClock{},
|
clock: &clock.RealClock{},
|
||||||
|
// We set lastSyncResourceVersion to "0", because it's the value which
|
||||||
|
// we set as ResourceVersion to the first List() request.
|
||||||
|
lastSyncResourceVersion: "0",
|
||||||
}
|
}
|
||||||
r.setExpectedType(expectedType)
|
r.setExpectedType(expectedType)
|
||||||
return r
|
return r
|
||||||
@ -185,10 +188,16 @@ func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error {
|
|||||||
klog.V(3).Infof("Listing and watching %v from %s", r.expectedTypeName, r.name)
|
klog.V(3).Infof("Listing and watching %v from %s", r.expectedTypeName, r.name)
|
||||||
var resourceVersion string
|
var resourceVersion string
|
||||||
|
|
||||||
// Explicitly set "0" as resource version - it's fine for the List()
|
// Explicitly set resource version to have it list from cache for
|
||||||
// to be served from cache and potentially be delayed relative to
|
// performance reasons.
|
||||||
// etcd contents. Reflector framework will catch up via Watch() eventually.
|
// It's fine for the returned state to be stale (we will catch up via
|
||||||
options := metav1.ListOptions{ResourceVersion: "0"}
|
// Watch() eventually), but can't set "0" to avoid going back in time
|
||||||
|
// if we hit apiserver that is significantly delayed compared to the
|
||||||
|
// state we already had.
|
||||||
|
// TODO: There is still a potential to go back in time after component
|
||||||
|
// restart when we set ResourceVersion: "0". For more details see:
|
||||||
|
// https://github.com/kubernetes/kubernetes/issues/59848
|
||||||
|
options := metav1.ListOptions{ResourceVersion: r.LastSyncResourceVersion()}
|
||||||
|
|
||||||
if err := func() error {
|
if err := func() error {
|
||||||
initTrace := trace.New("Reflector ListAndWatch", trace.Field{"name", r.name})
|
initTrace := trace.New("Reflector ListAndWatch", trace.Field{"name", r.name})
|
||||||
|
Loading…
Reference in New Issue
Block a user