watcher

package
v0.19.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 12 Imported by: 12

Documentation

Overview

Package watcher provides an interface that allows clients to watch for change events on Kubernetes resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// RestConfig the REST config used to access the resources to watch.
	RestConfig *rest.Config

	// RestMapper used to obtain GroupVersionResources. This is optional and is provided for unit testing in lieu of the
	// RestConfig. If not specified, one is created from the RestConfig.
	RestMapper meta.RESTMapper

	// Client used to access the resources to watch. This is optional and is provided for unit testing in lieu
	// of the RestConfig. If not specified, one is created from the RestConfig.
	Client dynamic.Interface

	// WaitForCacheSync if true, waits for the informer cache to sync on Start. Default is true.
	WaitForCacheSync *bool

	// Scheme used to convert resource objects. By default the global k8s Scheme is used.
	Scheme *runtime.Scheme

	// ResyncPeriod if non-zero, the period at which resources will be re-synced regardless if anything changed. Default is 0.
	ResyncPeriod time.Duration

	// ResourceConfigs the configurations for the resources to watch.
	ResourceConfigs []ResourceConfig
}

type EventHandler

type EventHandler interface {
	OnCreate(obj runtime.Object, numRequeues int) bool
	OnUpdate(obj runtime.Object, numRequeues int) bool
	OnDelete(obj runtime.Object, numRequeues int) bool
}

EventHandler can handle notifications of events that happen to a resource. The bool return value from each event notification method indicates whether or not the resource should be re-queued to be retried later, typically in case of an error.

type EventHandlerFuncs

type EventHandlerFuncs struct {
	OnCreateFunc func(obj runtime.Object, numRequeues int) bool
	OnUpdateFunc func(obj runtime.Object, numRequeues int) bool
	OnDeleteFunc func(obj runtime.Object, numRequeues int) bool
}

EventHandlerFuncs is an adaptor to let you easily specify as many or as few of the notification functions as you want while still implementing EventHandler.

func (EventHandlerFuncs) OnCreate

func (r EventHandlerFuncs) OnCreate(obj runtime.Object, numRequeues int) bool

func (EventHandlerFuncs) OnDelete

func (r EventHandlerFuncs) OnDelete(obj runtime.Object, numRequeues int) bool

func (EventHandlerFuncs) OnUpdate

func (r EventHandlerFuncs) OnUpdate(obj runtime.Object, numRequeues int) bool

type Interface

type Interface interface {
	Start(stopCh <-chan struct{}) error
	ListResources(ofType runtime.Object, bySelector labels.Selector) []runtime.Object
}

func New

func New(config *Config) (Interface, error)

type ResourceConfig

type ResourceConfig struct {
	// Name of this watcher used for logging.
	Name string

	// ResourceType the types of the resources to watch.
	ResourceType runtime.Object

	// Handler that is notified of create, update, and delete events.
	Handler EventHandler

	// ResourcesEquivalent function to compare two resources for equivalence. This is invoked on an update notification
	// to compare the old and new resources. If true is returned, the update is ignored, otherwise the update is processed.
	// By default all updates are processed.
	ResourcesEquivalent syncer.ResourceEquivalenceFunc

	// ShouldProcess function invoked to determine if a resource should be processed.
	ShouldProcess syncer.ShouldProcessFunc

	// SourceNamespace the namespace of the resources to watch.
	SourceNamespace string

	// SourceLabelSelector optional selector to restrict the resources to watch by their labels.
	SourceLabelSelector string

	// SourceFieldSelector optional selector to restrict the resources to watch by their fields.
	SourceFieldSelector string
}

Jump to

Keyboard shortcuts

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