Documentation ¶
Index ¶
- Variables
- func ContextWithOptionalTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
- func ListWatchUntil(timeout time.Duration, lw cache.ListerWatcher, conditions ...ConditionFunc) (*watch.Event, error)deprecated
- func NewIndexerInformerWatcher(lw cache.ListerWatcher, objType runtime.Object) (cache.Indexer, cache.Controller, watch.Interface)
- func UntilWithSync(ctx context.Context, lw cache.ListerWatcher, objType runtime.Object, ...) (*watch.Event, error)
- func UntilWithoutRetry(ctx context.Context, watcher watch.Interface, conditions ...ConditionFunc) (*watch.Event, error)
- type ConditionFunc
- type PreconditionFunc
Constants ¶
This section is empty.
Variables ¶
ErrWatchClosed is returned when the watch channel is closed before timeout in UntilWithoutRetry.
Functions ¶
func ContextWithOptionalTimeout ¶
func ContextWithOptionalTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
ContextWithOptionalTimeout wraps context.WithTimeout and handles infinite timeouts expressed as 0 duration.
func ListWatchUntil
deprecated
func ListWatchUntil(timeout time.Duration, lw cache.ListerWatcher, conditions ...ConditionFunc) (*watch.Event, error)
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: remove when no longer used
Deprecated: Use UntilWithSync instead.
func NewIndexerInformerWatcher ¶
func NewIndexerInformerWatcher(lw cache.ListerWatcher, objType runtime.Object) (cache.Indexer, cache.Controller, watch.Interface)
NewIndexerInformerWatcher will create an IndexerInformer and wrap it into watch.Interface so you can use it anywhere where you'd have used a regular Watcher returned from Watch method.
func UntilWithSync ¶
func UntilWithSync(ctx context.Context, lw cache.ListerWatcher, objType runtime.Object, precondition PreconditionFunc, conditions ...ConditionFunc) (*watch.Event, error)
UntilWithSync creates an informer from lw, optionally checks precondition when the store is synced, and watches the output until each provided condition succeeds, in a way that is identical to function UntilWithoutRetry. (See above.) UntilWithSync can deal with all errors like API timeout, lost connections and 'Resource version too old'. It is the only function that can recover from 'Resource version too old', Until and UntilWithoutRetry will just fail in that case. On the other hand it can't provide you with guarantees as strong as using simple Watch method with Until. It can skip some intermediate events in case of watch function failing but it will re-list to recover and you always get an event, if there has been a change, after recovery. Also with the current implementation based on DeltaFIFO, order of the events you receive is guaranteed only for particular object, not between more of them even it's the same resource. The most frequent usage would be a command that needs to watch the "state of the world" and should't fail, like: waiting for object reaching a state, "small" controllers, ...
func UntilWithoutRetry ¶
func UntilWithoutRetry(ctx context.Context, watcher watch.Interface, conditions ...ConditionFunc) (*watch.Event, error)
UntilWithoutRetry reads items from the watch until each provided condition succeeds, and then returns the last watch encountered. The first condition that returns an error terminates the watch (and the event is also returned). If no event has been received, the returned event will be nil. Conditions are satisfied sequentially so as to provide a useful primitive for higher level composition. Waits until context deadline or until context is canceled.
Warning: Unless you have a very specific use case (probably a special Watcher) don't use this function!!! Warning: This will fail e.g. on API timeouts and/or 'too old resource version' error. Warning: You are most probably looking for a function *Until* or *UntilWithSync* below, Warning: solving such issues. TODO: Consider making this function private to prevent misuse when the other occurrences in our codebase are gone.
Types ¶
type ConditionFunc ¶
ConditionFunc returns true if the condition has been reached, false if it has not been reached yet, or an error if the condition cannot be checked and should terminate. In general, it is better to define level driven conditions over edge driven conditions (pod has ready=true, vs pod modified and ready changed from false to true).