cache

package
v0.48.6 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller struct {

	// UseWatchList if turned on instructs the reflector to open a stream to bring data from the API server.
	// Defaults to false.
	UseWatchList bool
	// WatchListPageSize is the requested chunk size for paginated LIST operations.
	// An empty value (0) will use client-go's default pagination behavior.
	WatchListPageSize int64
	// contains filtered or unexported fields
}

Controller is a controller that uses a reflector to watch a resource and update a queue. It is copied over from k8s.io/client-go/tools/cache/controller.go.

func NewController

func NewController(c *cache.Config) *Controller

NewController makes a new Controller from the given Config.

func (*Controller) HasSynced

func (c *Controller) HasSynced() bool

HasSynced returns true once this cache has completed an initial resource listing.

func (*Controller) LastSyncResourceVersion

func (c *Controller) LastSyncResourceVersion() string

LastSyncResourceVersion returns the last sync resource version of the cache.

func (*Controller) Run

func (c *Controller) Run(stopCh <-chan struct{})

Run implements Controller.Run.

func (*Controller) RunWithContext

func (c *Controller) RunWithContext(ctx context.Context)

RunWithContext implements Controller.RunWithContext.

type Reflector

type Reflector struct {

	// WatchListPageSize is the requested chunk size of initial and resync watch lists.
	// If unset, for consistent reads (RV="") or reads that opt-into arbitrarily old data
	// (RV="0") it will default to pager.PageSize, for the rest (RV != "" && RV != "0")
	// it will turn off pagination to allow serving them from watch cache.
	// NOTE: It should be used carefully as paginated lists are always served directly from
	// etcd, which is significantly less efficient and may lead to serious performance and
	// scalability problems.
	WatchListPageSize int64
	// ShouldResync is invoked periodically and whenever it returns `true` the Store's Resync operation is invoked
	ShouldResync func() bool
	// MaxInternalErrorRetryDuration defines how long we should retry internal errors returned by watch.
	MaxInternalErrorRetryDuration time.Duration
	// UseWatchList if turned on instructs the reflector to open a stream to bring data from the API server.
	// Streaming has the primary advantage of using fewer server's resources to fetch data.
	//
	// The old behaviour establishes a LIST request which gets data in chunks.
	// Paginated list is less efficient and depending on the actual size of objects
	// might result in an increased memory consumption of the APIServer.
	//
	// See https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/3157-watch-list#design-details
	//
	// TODO(#115478): Consider making reflector.UseWatchList a private field. Since we implemented "api streaming" on the etcd storage layer it should work.
	UseWatchList *bool
	// contains filtered or unexported fields
}

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

func NewReflectorWithOptions

func NewReflectorWithOptions(
	lw cache.ListerWatcherWithContext, expectedType any, store cache.ReflectorStore, options ReflectorOptions,
) *Reflector

NewReflectorWithOptions creates a new Reflector object which will keep the given store up to date with the server's contents for the given resource. Reflector promises to only put things in the store that have the type of expectedType, unless expectedType is nil. If resyncPeriod is non-zero, then the reflector will periodically consult its ShouldResync function to determine whether to invoke the Store's Resync operation; `ShouldResync==nil` means always "yes". This enables you to use reflectors to periodically process everything as well as incrementally processing the things that change.

func (*Reflector) LastSyncResourceVersion

func (r *Reflector) LastSyncResourceVersion() string

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

func (*Reflector) ListAndWatch

func (r *Reflector) ListAndWatch(stopCh <-chan struct{}) error

ListAndWatch first lists all items and get the resource version at the moment of call, and then use the resource version to watch. It returns error if ListAndWatch didn't even try to initialize watch.

Contextual logging: ListAndWatchWithContext should be used instead of ListAndWatch in code which supports contextual logging.

func (*Reflector) ListAndWatchWithContext

func (r *Reflector) ListAndWatchWithContext(ctx context.Context) error

ListAndWatchWithContext first lists all items and get the resource version at the moment of call, and then use the resource version to watch. It returns error if ListAndWatchWithContext didn't even try to initialize watch.

func (*Reflector) Name

func (r *Reflector) Name() string

Name returns the name of the reflector.

func (*Reflector) Run

func (r *Reflector) Run(stopCh <-chan struct{})

Run repeatedly uses the reflector's ListAndWatch to fetch all the objects and subsequent deltas. Run will exit when stopCh is closed.

Contextual logging: RunWithContext should be used instead of Run in code which supports contextual logging.

func (*Reflector) RunWithContext

func (r *Reflector) RunWithContext(ctx context.Context)

RunWithContext repeatedly uses the reflector's ListAndWatch to fetch all the objects and subsequent deltas. Run will exit when the context is canceled.

func (*Reflector) TypeDescription

func (r *Reflector) TypeDescription() string

TypeDescription returns the type description of the reflector.

type ReflectorOptions

type ReflectorOptions struct {
	// Name is the Reflector's name. If unset/unspecified, the name defaults to the closest source_file.go:line
	// in the call stack that is outside this package.
	Name string

	// TypeDescription is the Reflector's type description. If unset/unspecified, the type description is defaulted
	// using the following rules: if the expectedType passed to NewReflectorWithOptions was nil, the type description is
	// "<unspecified>". If the expectedType is an instance of *unstructured.Unstructured and its apiVersion and kind fields
	// are set, the type description is the string encoding of those. Otherwise, the type description is set to the
	// go type of expectedType..
	TypeDescription string

	// ResyncPeriod is the Reflector's resync period. If unset/unspecified, the resync period defaults to 0
	// (do not resync).
	ResyncPeriod time.Duration

	// MinWatchTimeout, if non-zero, defines the minimum timeout for watch requests send to kube-apiserver.
	// However, values lower than 5m will not be honored to avoid negative performance impact on controlplane.
	MinWatchTimeout time.Duration

	// Clock allows tests to control time. If unset defaults to clock.RealClock{}
	Clock clock.Clock

	// UseWatchList if turned on instructs the reflector to open a stream to bring data from the API server.
	// Streaming has the primary advantage of using fewer server's resources to fetch data.
	//
	// The old behaviour establishes a LIST request which gets data in chunks.
	// Paginated list is less efficient and depending on the actual size of objects
	// might result in an increased memory consumption of the APIServer.
	//
	// If nil, defaults to the feature gate WatchListClient from client-go.
	// See https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/3157-watch-list#design-details
	UseWatchList *bool
}

ReflectorOptions configures a Reflector.

Jump to

Keyboard shortcuts

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