watch

package
v1.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package watch includes a RestartableManager for dynamically watching resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertListOptions added in v1.16.0

func ConvertListOptions(mOpts *metav1.ListOptions) (*client.ListOptions, error)

ConvertListOptions converts from `metav1.ListOptions` to `client.ListOptions`.

For the reverse, see `client.ListOptions.AsListOptions()`.

func DeleteAndWait added in v1.16.0

func DeleteAndWait(ctx context.Context, c client.WithWatch, obj client.Object, reconcileTimeout time.Duration) error

DeleteAndWait deletes the object (if not already deleted) and blocks until it is fully deleted (NotFound, not just deleteTimestamp). This allows for any finalizers to complete.

Exits early if the object is already deleted or doesn't exist.

The Object contents will be replaced with updated state for each new event received while waiting for deletion.

If you want to time out the full function, use a context.WithTimeout. If you want to time out just the waiting after the delete, use reconcileTimeout.

func MergeListOptions added in v1.16.0

func MergeListOptions(a, b *client.ListOptions) (*client.ListOptions, error)

MergeListOptions merges two sets of ListOptions. - For Namespace, Limit, and Continue, at most one may be specified, unless they're the same - For FieldSelector and LabelSelector, the result requires both filters to match (AND) - For Raw, at most one may be specified

func NewTypedListerWatcher added in v1.16.0

func NewTypedListerWatcher(ctx context.Context, c client.WithWatch, exampleList client.ObjectList, opts *client.ListOptions) cache.ListerWatcher

NewTypedListerWatcher constructs a new TypedListerWatcher for the specified list type with default options.

func SingleObjectListOptions added in v1.16.0

func SingleObjectListOptions(obj client.Object) *client.ListOptions

SingleObjectListOptions builds a set of List options that filter down to one specific object.

func UnrollListOptions added in v1.16.0

func UnrollListOptions(in *client.ListOptions) []client.ListOption

UnrollListOptions converts from ListOptions to a slice of ListOption.

For the reverse, see `client.ListOptions.ApplyOptions([]client.ListOption)`.

func UntilDeleted added in v1.18.0

func UntilDeleted(ctx context.Context, c client.WithWatch, obj client.Object) error

UntilDeleted watches the specified object and blocks until it is fully deleted (NotFound, not just deleteTimestamp). This allows for any finalizers to complete.

Unlike client-go's watch.Until, this function uses an informer, which means it does a ListAndWatch, not just a Watch. So it will return immediately if the object was already deleted.

For timeout, use: watchCtx, cancel := context.WithTimeout(ctx, 1*time.Minute) defer cancel()

func UntilDeletedWithSync added in v1.16.0

func UntilDeletedWithSync(ctx context.Context, c client.WithWatch, obj client.Object, precondition watchtools.PreconditionFunc) error

UntilDeletedWithSync watches the specified object and blocks until it is fully deleted (NotFound, not just deleteTimestamp). This allows for any finalizers to complete.

The optional Precondition will be called after the Informer is Synced, meaning that both the List and Watch call have been made, after which it's safe to Delete the object and assume the watch will receive the delete event.

The Precondition Store argument uses "<namespace>/<name>" or "<name>" keys and returns either a cache.DeletedFinalStateUnknown or an object of the type specified by the `items` field of the provided ObjectList (Kind without the "List" suffix). For example, UnstructuredList caches Unstructured objects.

The Object ResourceVersion of the input object is ignored, because a new Informer is created which will do a ListAndWatch to determine which ResourceVersion to start watching from.

The Object contents will be replaced with updated state for each new event received while waiting for deletion.

For timeout, use: watchCtx, cancel := context.WithTimeout(ctx, 1*time.Minute) defer cancel()

If you want to make sure something is deleted, delete it if it's not yet deleted, and then wait for it to be fully deleted, use DeleteAndWait instead.

Types

type ControllerBuilder

type ControllerBuilder interface {
	// StartControllers starts the relevant controllers using the RestartableManager to manage them.
	StartControllers(mgr manager.Manager, gvks map[schema.GroupVersionKind]bool, mgrInitTime metav1.Time) error
}

ControllerBuilder builds controllers. It is managed by RestartableManager, which is managed by a higher-level controller.

type DynamicListerWatcher added in v1.16.0

type DynamicListerWatcher struct {
	// Context to pass to client list and watch methods
	Context context.Context

	// DynamicClient to list and watch with
	DynamicClient dynamic.Interface

	// RESTMapper to map from kind to resource
	RESTMapper meta.RESTMapper

	// ItemGVK is the kind of resource to list & watch
	ItemGVK schema.GroupVersionKind

	// DefaultListOptions are merged into the specified ListOptions on each
	// List and Watch call.
	// See MergeListOptions for details and limitations.
	DefaultListOptions *client.ListOptions
}

DynamicListerWatcher wraps a dynamic.Interface and implements the cache.ListerWatcher interface with optional default ListOptions.

func (*DynamicListerWatcher) List added in v1.16.0

List satisfies the cache.Lister interface. The ListOptions specified here are merged with the ClientListerWatcher

func (*DynamicListerWatcher) Watch added in v1.16.0

Watch satisfies the cache.Watcher interface

type RawListOptions added in v1.16.0

type RawListOptions struct {
	Raw *metav1.ListOptions
}

RawListOptions wraps a `metav1.ListOptions` to allow passing as `client.ListOption` to controller-runtime clients.

func (*RawListOptions) ApplyToList added in v1.16.0

func (rlo *RawListOptions) ApplyToList(lo *client.ListOptions)

ApplyToList sets the Raw metav1.ListOptions on the specified client.ListOptions.

type RestartableManager

type RestartableManager interface {
	// Restart restarts the Manager and all the controllers it manages to watch the given GroupVersionKinds.
	// Returns if a restart actually happened and if there were any errors while doing it.
	Restart(gvks map[schema.GroupVersionKind]bool, force bool) (bool, error)
}

RestartableManager is a controller manager that can be restarted based on the resources it syncs.

func NewManager

func NewManager(mgr manager.Manager, builder ControllerBuilder) (RestartableManager, error)

NewManager returns a new RestartableManager

type TypedInformerFactory added in v1.16.0

type TypedInformerFactory struct {
	Client       client.WithWatch
	ResyncPeriod time.Duration
	Indexers     cache.Indexers
}

TypedInformerFactory is a factory that constructs new SharedIndexInformers.

func NewTypedInformerFactory added in v1.16.0

func NewTypedInformerFactory(client client.WithWatch, resyncPeriod time.Duration) *TypedInformerFactory

NewTypedInformerFactory constructs a new TypedInformerFactory

func (*TypedInformerFactory) NewInformer added in v1.16.0

func (f *TypedInformerFactory) NewInformer(ctx context.Context, mapping *meta.RESTMapping, namespace string) (cache.SharedIndexInformer, error)

NewInformer constructs a new SharedIndexInformer for the specified resource.

type TypedListerWatcher added in v1.16.0

type TypedListerWatcher struct {
	// Context to pass to client list and watch methods
	Context context.Context

	// Client to list and watch with
	Client client.WithWatch

	// ExampleList is an example of the list type of resource to list & watch
	ExampleList client.ObjectList

	// DefaultListOptions are merged into the specified ListOptions on each
	// List and Watch call.
	// See MergeListOptions for details and limitations.
	DefaultListOptions *client.ListOptions
}

TypedListerWatcher wraps a client.WithWatch and implements the cache.ListerWatcher interface with optional default ListOptions.

func (*TypedListerWatcher) List added in v1.16.0

List satisfies the cache.Lister interface. The ListOptions specified here are merged with the ClientListerWatcher

func (*TypedListerWatcher) Watch added in v1.16.0

func (fw *TypedListerWatcher) Watch(options metav1.ListOptions) (watch.Interface, error)

Watch satisfies the cache.Watcher interface

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL