Skip to content

Commit 121e474

Browse files
committed
Made the comment on SharedInformer give a complete description
This comment formerly contained only a contrast with "standard informer", but there is no longer such a thing so the comment lacked much important information.
1 parent 548bf0a commit 121e474

File tree

1 file changed

+66
-14
lines changed

1 file changed

+66
-14
lines changed

staging/src/k8s.io/client-go/tools/cache/shared_informer.go

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,83 @@ import (
3131
"k8s.io/klog"
3232
)
3333

34-
// SharedInformer has a shared data cache and is capable of distributing notifications for changes
35-
// to the cache to multiple listeners who registered via AddEventHandler. If you use this, there is
36-
// one behavior change compared to a standard Informer. When you receive a notification, the cache
37-
// will be AT LEAST as fresh as the notification, but it MAY be more fresh. You should NOT depend
38-
// on the contents of the cache exactly matching the notification you've received in handler
39-
// functions. If there was a create, followed by a delete, the cache may NOT have your item. This
40-
// has advantages over the broadcaster since it allows us to share a common cache across many
41-
// controllers. Extending the broadcaster would have required us keep duplicate caches for each
42-
// watch.
34+
// SharedInformer provides eventually consistent linkage of its
35+
// clients to the authoritative state of a given collection of
36+
// objects. An object is identified by its API group, kind/resource,
37+
// namespace, and name. One SharedInfomer provides linkage to objects
38+
// of a particular API group and kind/resource. The linked object
39+
// collection of a SharedInformer may be further restricted to one
40+
// namespace and/or by label selector and/or field selector.
41+
//
42+
// The authoritative state of an object is what apiservers provide
43+
// access to, and an object goes through a strict sequence of states.
44+
// A state is either "absent" or present with a ResourceVersion and
45+
// other appropriate content.
46+
//
47+
// A SharedInformer maintains a local cache, exposed by Store(), of
48+
// the state of each relevant object. This cache is eventually
49+
// consistent with the authoritative state. This means that, unless
50+
// prevented by persistent communication problems, if ever a
51+
// particular object ID X is authoritatively associated with a state S
52+
// then for every SharedInformer I whose collection includes (X, S)
53+
// eventually either (1) I's cache associates X with S or a later
54+
// state of X, (2) I is stopped, or (3) the authoritative state
55+
// service for X terminates. To be formally complete, we say that the
56+
// absent state meets any restriction by label selector or field
57+
// selector.
58+
//
59+
// As a simple example, if a collection of objects is henceforeth
60+
// unchanging and a SharedInformer is created that links to that
61+
// collection then that SharedInformer's cache eventually holds an
62+
// exact copy of that collection (unless it is stopped too soon, the
63+
// authoritative state service ends, or communication problems between
64+
// the two persistently thwart achievement).
65+
//
66+
// As another simple example, if the local cache ever holds a
67+
// non-absent state for some object ID and the object is eventually
68+
// removed from the authoritative state then eventually the object is
69+
// removed from the local cache (unless the SharedInformer is stopped
70+
// too soon, the authoritative state service emnds, or communication
71+
// problems persistently thwart the desired result).
72+
//
73+
// The keys in Store() are of the form namespace/name for namespaced
74+
// objects, and are simply the name for non-namespaced objects.
75+
//
76+
// A client is identified here by a ResourceEventHandler. For every
77+
// update to the SharedInformer's local cache and for every client,
78+
// eventually either the SharedInformer is stopped or the client is
79+
// notified of the update. These notifications happen after the
80+
// corresponding cache update and, in the case of a
81+
// SharedIndexInformer, after the corresponding index updates. It is
82+
// possible that additional cache and index updates happen before such
83+
// a prescribed notification. For a given SharedInformer and client,
84+
// all notifications are delivered sequentially. For a given
85+
// SharedInformer, client, and object ID, the notifications are
86+
// delivered in order.
87+
//
88+
// A delete notification exposes the last locally known non-absent
89+
// state, except that its ResourceVersion is replaced with a
90+
// ResourceVersion in which the object is actually absent.
4391
type SharedInformer interface {
4492
// AddEventHandler adds an event handler to the shared informer using the shared informer's resync
4593
// period. Events to a single handler are delivered sequentially, but there is no coordination
4694
// between different handlers.
4795
AddEventHandler(handler ResourceEventHandler)
48-
// AddEventHandlerWithResyncPeriod adds an event handler to the shared informer using the
49-
// specified resync period. Events to a single handler are delivered sequentially, but there is
50-
// no coordination between different handlers.
96+
// AddEventHandlerWithResyncPeriod adds an event handler to the
97+
// shared informer using the specified resync period. The resync
98+
// operation consists of delivering to the handler a create
99+
// notification for every object in the informer's local cache; it
100+
// does not add any interactions with the authoritative storage.
51101
AddEventHandlerWithResyncPeriod(handler ResourceEventHandler, resyncPeriod time.Duration)
52-
// GetStore returns the Store.
102+
// GetStore returns the informer's local cache as a Store.
53103
GetStore() Store
54104
// GetController gives back a synthetic interface that "votes" to start the informer
55105
GetController() Controller
56106
// Run starts the shared informer, which will be stopped when stopCh is closed.
57107
Run(stopCh <-chan struct{})
58-
// HasSynced returns true if the shared informer's store has synced.
108+
// HasSynced returns true if the shared informer's store has been
109+
// informed by at least one full LIST of the authoritative state
110+
// of the informer's object collection. This is unrelated to "resync".
59111
HasSynced() bool
60112
// LastSyncResourceVersion is the resource version observed when last synced with the underlying
61113
// store. The value returned is not synchronized with access to the underlying store and is not

0 commit comments

Comments
 (0)