informer

package
v0.0.0-...-e1628ab Latest Latest
Warning

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

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

Documentation

Overview

This package forked from https://pkg.go.dev/k8s.io/client-go/tools/cache. This package implements cache.SharedIndexInformer in a more general approach. It's differs with cache.sharedIndexInformer in three ways. First, we generalize reflector class as reflector interface, listAndWatch becomes unnecessary, reflector can be implements by you own way. Second, we change the default keyFunc as parameter, and exampleObject could be any types. Third, we deprecated method SetWatchErrorHandler, it's coupling too much with cach.Reflector. You can add error handler in NewReflectorFunc now.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(c *Config) cache.Controller

New makes a new Controller from the given Config.

func NewSharedIndexInformer

func NewSharedIndexInformer(newReflector NewReflectorFunc, exampleObject interface{}, keyFunc cache.KeyFunc, defaultEventHandlerResyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer

NewSharedIndexInformer creates a new instance by NewReflectorFunc. The created informer will not do resyncs if the given defaultEventHandlerResyncPeriod is zero. Otherwise: for each handler that with a non-zero requested resync period, whether added before or after the informer starts, the nominal resync period is the requested resync period rounded up to a multiple of the informer's resync checking period. Such an informer's resync checking period is established when the informer starts running, and is the maximum of (a) the minimum of the resync periods requested before the informer starts and the defaultEventHandlerResyncPeriod given here and (b) the constant `minimumResyncPeriod` defined in this file.

Types

type Config

type Config struct {
	// The queue for your objects - has to be a DeltaFIFO due to
	// assumptions in the implementation. Your Process() function
	// should accept the output of this Queue's Pop() method.
	cache.Queue

	// NewReflector creates a new Reflector instance which will keep the
	// given store up to date with the server's contents for the given
	// resource.
	NewReflector NewReflectorFunc

	// Something that can process a popped Deltas.
	Process cache.ProcessFunc

	// ObjectType is an example object of the type this controller is
	// expected to handle.
	ObjectType interface{}

	// FullResyncPeriod is the period at which ShouldResync is considered.
	FullResyncPeriod time.Duration

	// ShouldResync is periodically used by the reflector to determine
	// whether to Resync the Queue. If ShouldResync is `nil` or
	// returns true, it means the reflector should proceed with the
	// resync.
	ShouldResync cache.ShouldResyncFunc

	// If true, when Process() returns an error, re-enqueue the object.
	// TODO: add interface to let you inject a delay/backoff or drop
	//       the object completely if desired. Pass the object in
	//       question to this interface as a parameter.  This is probably moot
	//       now that this functionality appears at a higher level.
	RetryOnError bool

	// WatchListPageSize is the requested chunk size of initial and relist watch lists.
	WatchListPageSize int64
}

Config contains all the settings for one of these low-level controllers.

type NewReflectorFunc

type NewReflectorFunc func(options *ReflectorOptions) Reflector

type Reflector

type Reflector interface {
	// Run repeatedly fetch all the objects and subsequent deltas.
	// Run will exit when stopCh is closed.
	Run(stopCh <-chan struct{})
	// LastSyncResourceVersion is the resource version observed when last sync with the underlying store
	// The value returned is not synchronized with access to the underlying store and is not thread-safe
	LastSyncResourceVersion() string
}

Reflector watches a specified resource and causes all changes to be reflected in the given store.

type ReflectorOptions

type ReflectorOptions struct {
	// Store is the destination to sync up with the watch source.
	Store cache.Store
	// ObjectType is an example object of the type this reflector is
	// expected to handle.
	ExpectedType interface{}
	// ResyncPeriod is the period at which ShouldResync is considered
	ResyncPeriod time.Duration
	// ShouldResync is periodically used by the reflector to determine
	// whether to Resync the Queue. If ShouldResync is `nil` or
	// returns true, it means the reflector should proceed with the
	// resync.
	ShouldResync cache.ShouldResyncFunc
	// WatchListPageSize is the requested chunk size of lists.
	WatchListPageSize int64
	// Clock allows for testability
	Clock clock.Clock
}

ReflectorOptions giving options for setup new reflector.

Jump to

Keyboard shortcuts

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