watch

package
v1.17.2-rc.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (

	// RESTConfigTimeout sets the REST config timeout for the remediator to 1 hour.
	//
	// RESTConfigTimeout should be longer than 2*minWatchTimeout to respect
	// the watch timeout set by `ListOptions.TimeoutSeconds` in the watch
	// create requests.
	RESTConfigTimeout = time.Hour

	// ClientWatchDecodingCause is the status cause returned for client errors during response decoding.
	// https://github.com/kubernetes/client-go/blob/v0.26.7/rest/request.go#L785
	ClientWatchDecodingCause metav1.CauseType = "ClientWatchDecoding"

	// ContextCancelledCauseMessage is the error message from the DynamicClient
	// when the Watch method errors due to context cancellation.
	// https://github.com/kubernetes/apimachinery/blob/v0.26.7/pkg/watch/streamwatcher.go#L120
	ContextCancelledCauseMessage = "unable to decode an event from the watch stream: context canceled"
)
View Source
const StatusClientError = 600

StatusClientError is a "fake" HTTP status code used to indicate a client-side error. Normal status codes go from 1xx-5xx, so using 600 should be safe, unless Kubernetes starts using it.

View Source
const StatusReasonClientError metav1.StatusReason = "ClientError"

StatusReasonClientError is the reason used for client-side errors. It's the human readable form of the `StatusClientError` status code.

Variables

This section is empty.

Functions

func DynamicResourceClient added in v1.15.1

func DynamicResourceClient(dynamicClient dynamic.Interface, mapper meta.RESTMapper, gvk schema.GroupVersionKind, namespace string) (dynamic.ResourceInterface, error)

DynamicResourceClient uses a generic dynamic.Interface to build a resource-specific client.

  • For cluster-scoped resources, namespace must be empty.
  • For namespace-scoped resources, namespace may optionally be empty, to include resources in all namespaces.

func ListAndWatch added in v1.15.1

func ListAndWatch(ctx context.Context, lw ListerWatcher, opts metav1.ListOptions) (watch.Interface, error)

ListAndWatch wraps a list and watch and returns a watch interface. This way, you can watch from "now" and get all the existing objects, not just new changes to objects.

If ResourceVersion is specified, ListAndWatch acts like a normal Watch. Otherwise, a List is performed first and `Added` events are simulated, followed by a Watch, where subsequent `Added` events for pre-existing objects are converted to `Modified` events, unless that object is deleted first.

func NewClientError added in v1.15.1

func NewClientError(err error) *apierrors.StatusError

NewClientError returns an error indicating that there was a client-side error. Unfortunately, the watch.Interface does not include a way to return client-side errors that preserves their error type. But at least this way we can tell the difference between a client-side error and a server-side error.

Types

type ListFunc added in v1.15.1

type ListFunc func(ctx context.Context, options metav1.ListOptions) (*unstructured.UnstructuredList, error)

ListFunc knows how to list resources.

type ListWatch added in v1.15.1

type ListWatch struct {
	ListFunc  ListFunc
	WatchFunc WatchFunc
}

ListWatch implements the ListerWatcher interface. ListFunc and WatchFunc must not be nil

func NewFilteredListWatchFromClient added in v1.15.1

func NewFilteredListWatchFromClient(dynamicClient dynamic.Interface, mapper meta.RESTMapper, gvk schema.GroupVersionKind, namespace string, optionsModifier func(options *metav1.ListOptions)) *ListWatch

NewFilteredListWatchFromClient creates a new ListWatch that can dynamically modify ListOptions. This allows specifying option defaults and overrides.

func NewListWatchFromClient added in v1.15.1

func NewListWatchFromClient(dynamicClient dynamic.Interface, mapper meta.RESTMapper, gvk schema.GroupVersionKind, namespace string) *ListWatch

NewListWatchFromClient creates a new ListWatch.

func (*ListWatch) List added in v1.15.1

List a set of apiserver resources

func (*ListWatch) Watch added in v1.15.1

func (lw *ListWatch) Watch(ctx context.Context, options metav1.ListOptions) (watch.Interface, error)

Watch a set of apiserver resources

type Lister added in v1.15.1

type Lister interface {
	// List returns a list of unstructured objects.
	// List can be cancelled with the input context.
	List(ctx context.Context, options metav1.ListOptions) (*unstructured.UnstructuredList, error)
}

Lister is any object that performs listing of a resource.

type ListerWatcher added in v1.15.1

type ListerWatcher interface {
	Lister
	Watcher
}

ListerWatcher is any object can perform both lists and watches. This is similar to the ListerWatcher in client-go, except it uses the dynamic client to return unstructured objects without requiring a local scheme.

type ListerWatcherFactory added in v1.15.1

type ListerWatcherFactory func(gvk schema.GroupVersionKind, namespace string) ListerWatcher

ListerWatcherFactory knows how to build ListerWatchers for the specified GroupVersionKind and Namespace.

func NewListerWatcherFactoryFromClient added in v1.15.1

func NewListerWatcherFactoryFromClient(cfg *rest.Config) (ListerWatcherFactory, error)

NewListerWatcherFactoryFromClient creates a ListerWatcherFactory using a dynamic client and mapper build from the specified REST config.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager accepts new resource lists that are parsed from Git and then updates declared resources and get GVKs.

func NewManager

func NewManager(scope declared.Scope, syncName string, cfg *rest.Config,
	q *queue.ObjectQueue, decls *declared.Resources, options *Options, ch conflict.Handler) (*Manager, error)

NewManager starts a new watch manager

func (*Manager) ManagementConflict

func (m *Manager) ManagementConflict() bool

ManagementConflict returns true if any watcher notices any management conflicts. This function is threadsafe.

func (*Manager) NeedsUpdate

func (m *Manager) NeedsUpdate() bool

NeedsUpdate returns true if the Manager's watches need to be updated. This function is threadsafe.

func (*Manager) UpdateWatches

func (m *Manager) UpdateWatches(ctx context.Context, gvkMap map[schema.GroupVersionKind]struct{}) status.MultiError

UpdateWatches accepts a map of GVKs that should be watched and takes the following actions:

  • stop watchers for any GroupVersionKind that is not present in the given map.
  • start watchers for any GroupVersionKind that is present in the given map and not present in the current watch map.

This function is threadsafe.

type Options

type Options struct {
	// contains filtered or unexported fields
}

Options contains options for creating a watch manager.

func DefaultOptions

func DefaultOptions(cfg *rest.Config) (*Options, error)

DefaultOptions return the default options with a ListerWatcherFactory built from the specified REST config.

type Runnable

type Runnable interface {
	Stop()
	Run(ctx context.Context) status.Error
	ManagementConflict() bool
	SetManagementConflict(object client.Object, commit string)
	ClearManagementConflict()
	// contains filtered or unexported methods
}

Runnable defines the custom watch interface.

func NewFiltered

func NewFiltered(cfg watcherConfig) Runnable

NewFiltered returns a new filtered watcher initialized with the given options.

type WatchFunc added in v1.15.1

type WatchFunc func(ctx context.Context, options metav1.ListOptions) (watch.Interface, error)

WatchFunc knows how to watch resources.

type Watcher added in v1.15.1

type Watcher interface {
	// Watch starts watching at the specified version.
	// List can be cancelled with the input context.
	Watch(ctx context.Context, options metav1.ListOptions) (watch.Interface, error)
}

Watcher is any object that performs watching of a resource.

Jump to

Keyboard shortcuts

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