Documentation ¶
Index ¶
- func IsRetryable(err error) (time.Duration, error)
- type Condition
- type ErrorCallback
- type Provider
- type VersionedResource
- type Watcher
- func DaemonSets(client Provider[*appsv1.DaemonSetList]) *Watcher[appsv1.DaemonSet]
- func Deployments(client Provider[*appsv1.DeploymentList]) *Watcher[appsv1.Deployment]
- func FromClient[L metav1.ListInterface, I any](client Provider[L]) *Watcher[I]
- func FromProvider[L VersionedResource, I any](provider Provider[L], itemsFromList func(L) []I) *Watcher[I]
- func Nodes(client Provider[*corev1.NodeList]) *Watcher[corev1.Node]
- func StatefulSets(client Provider[*appsv1.StatefulSetList]) *Watcher[appsv1.StatefulSet]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Condition ¶
Condition is a func that gets called by Watcher for each updated item. The watch will terminate successfully if it returns true, continue if it returns false or terminate with the returned error.
type ErrorCallback ¶
ErrorCallback is a func that, if specified, will be called by the Watcher whenever it encounters some error. Whenever the returned error is nil, the Watcher will wait for the specified duration and retry the last call. Otherwise the Watcher will return the returned error.
type Provider ¶
type Provider[L any] interface { List(ctx context.Context, opts metav1.ListOptions) (L, error) Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) }
Provider represents the backend for Watcher. It is compatible with client-go's typed interfaces.
type VersionedResource ¶
type VersionedResource interface {
GetResourceVersion() string
}
type Watcher ¶
type Watcher[T any] struct { List func(ctx context.Context, opts metav1.ListOptions) (resourceVersion string, items []T, err error) Watch func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error) // contains filtered or unexported fields }
Watcher offers a convenient way of watching Kubernetes resources. An ephemeral alternative to Reflectors and Indexers, useful for one-shot tasks when no caching is required. It performs an initial list of all the resources and then starts watching them. In case the watch needs to be restarted (a.k.a. resource version too old), Watcher will re-list all the resources. The Watcher will restart the watch API call from time to time at the last seen resource version, so that stale HTTP connections won't make the watch go stale, too.
func DaemonSets ¶
func Deployments ¶
func Deployments(client Provider[*appsv1.DeploymentList]) *Watcher[appsv1.Deployment]
func FromClient ¶
func FromClient[L metav1.ListInterface, I any](client Provider[L]) *Watcher[I]
FromClient creates a Watcher from the given client-go client. Note that the types L and I need to be connected in a way that L is a pointer type to a struct that has an `Items` field of type []I. This function will panic if this is not the case. Refer to FromProvider in order to provide a custom way of obtaining items from the list type.
func FromProvider ¶
func FromProvider[L VersionedResource, I any](provider Provider[L], itemsFromList func(L) []I) *Watcher[I]
FromProvider creates a Watcher from the given Provider and the corresponding itemsFromList function.
func StatefulSets ¶
func StatefulSets(client Provider[*appsv1.StatefulSetList]) *Watcher[appsv1.StatefulSet]
func (*Watcher[T]) Until ¶
Until runs a watch until condition returns true. It will error out in case the context gets canceled or the condition returns an error.
func (*Watcher[T]) WithErrorCallback ¶
func (w *Watcher[T]) WithErrorCallback(callback ErrorCallback) *Watcher[T]
WithErrorCallback sets this Watcher's error callback. It's invoked every time an error occurs and determines if the watch should continue or terminate:
- The returned error is nil: continue watching
- The returned error is not nil: terminate watch with that error
If the error callback is not set or nil, the default behavior is to terminate.
func (*Watcher[T]) WithFieldSelector ¶
WithFieldSelector sets the given field selector for this Watcher. The default is to match everything:
watcher.FromClient(...).WithFieldSelector(fields.Everything())
Refer to the concept for a general introduction to field selectors. To gain an overview of the supported values, have a look at the usages of k8s.io/apimachinery/pkg/runtime.Scheme.AddFieldLabelConversionFunc in the Kubernetes codebase.
func (*Watcher[T]) WithObjectName ¶
WithObjectName sets this Watcher's field selector in a way to only match objects with the given name.