cache

package
v1.0.5 Latest Latest
Warning

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

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

Documentation

Overview

Package cache provides object caches that act as caching client.Reader instances and help drive Kubernetes-object-based event handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Cache acts as a client to objects stored in the cache.
	client.Reader

	// Cache loads informers and adds field indices.
	Informers
}

Cache knows how to load Kubernetes objects, fetch informers to request to receive events for Kubernetes objects (at a low-level), and add indices to fields on the objects stored in the cache.

func New

func New(config *rest.Config, opts Options) (Cache, error)

New initializes and returns a new Cache.

type DisableDeepCopyByObject added in v1.0.1

type DisableDeepCopyByObject map[client.Object]bool

DisableDeepCopyByObject associate a client.Object's GVK to disable DeepCopy during get or list from cache.

type ErrCacheNotStarted added in v1.0.1

type ErrCacheNotStarted struct{}

ErrCacheNotStarted is returned when trying to read from the cache that wasn't started.

func (*ErrCacheNotStarted) Error added in v1.0.1

func (*ErrCacheNotStarted) Error() string

type Informer added in v1.0.1

type Informer interface {
	// AddEventHandler adds an event handler to the shared informer using the shared informer's resync
	// period.  Events to a single handler are delivered sequentially, but there is no coordination
	// between different handlers.
	// It returns a registration handle for the handler that can be used to remove
	// the handler again.
	AddEventHandler(handler toolscache.ResourceEventHandler) (toolscache.ResourceEventHandlerRegistration, error)
	// AddEventHandlerWithResyncPeriod adds an event handler to the shared informer using the
	// specified resync period.  Events to a single handler are delivered sequentially, but there is
	// no coordination between different handlers.
	// It returns a registration handle for the handler that can be used to remove
	// the handler again and an error if the handler cannot be added.
	AddEventHandlerWithResyncPeriod(handler toolscache.ResourceEventHandler, resyncPeriod time.Duration) (toolscache.ResourceEventHandlerRegistration, error)
	// RemoveEventHandler removes a formerly added event handler given by
	// its registration handle.
	// This function is guaranteed to be idempotent, and thread-safe.
	RemoveEventHandler(handle toolscache.ResourceEventHandlerRegistration) error
	// AddIndexers adds more indexers to this store.  If you call this after you already have data
	// in the store, the results are undefined.
	AddIndexers(indexers toolscache.Indexers) error
	// HasSynced return true if the informers underlying store has synced.
	HasSynced() bool
}

Informer - informer allows you interact with the underlying informer.

type Informers

type Informers interface {
	// GetInformer fetches or constructs an informer for the given object that corresponds to a single
	// API kind and resource.
	GetInformer(ctx context.Context, obj client.Object) (Informer, error)

	// GetInformerForKind is similar to GetInformer, except that it takes a group-version-kind, instead
	// of the underlying object.
	GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind) (Informer, error)

	// Start runs all the informers known to this cache until the context is closed.
	// It blocks.
	Start(ctx context.Context) error

	// WaitForCacheSync waits for all the caches to sync.  Returns false if it could not sync a cache.
	WaitForCacheSync(ctx context.Context) bool

	// Informers knows how to add indices to the caches (informers) that it manages.
	client.FieldIndexer
}

Informers knows how to create or fetch informers for different group-version-kinds, and add indices to those informers. It's safe to call GetInformer from multiple threads.

type NewCacheFunc added in v1.0.1

type NewCacheFunc func(config *rest.Config, opts Options) (Cache, error)

NewCacheFunc - Function for creating a new cache from the options and a rest config.

func BuilderWithOptions added in v1.0.1

func BuilderWithOptions(options Options) NewCacheFunc

BuilderWithOptions returns a Cache constructor that will build a cache honoring the options argument, this is useful to specify options like SelectorsByObject WARNING: If SelectorsByObject is specified, filtered out resources are not returned. WARNING: If UnsafeDisableDeepCopy is enabled, you must DeepCopy any object returned from cache get/list before mutating it.

func MultiNamespacedCacheBuilder added in v1.0.1

func MultiNamespacedCacheBuilder(namespaces []string) NewCacheFunc

MultiNamespacedCacheBuilder - Builder function to create a new multi-namespaced cache. This will scope the cache to a list of namespaces. Listing for all namespaces will list for all the namespaces that this knows about. By default this will create a global cache for cluster scoped resource. Note that this is not intended to be used for excluding namespaces, this is better done via a Predicate. Also note that you may face performance issues when using this with a high number of namespaces.

type ObjectAll added in v1.0.1

type ObjectAll struct {
	client.Object
}

ObjectAll is the argument to represent all objects' types.

type ObjectSelector added in v1.0.1

type ObjectSelector internal.Selector

ObjectSelector is an alias name of internal.Selector.

type Options

type Options struct {
	// Scheme is the scheme to use for mapping objects to GroupVersionKinds
	Scheme *runtime.Scheme

	// Mapper is the RESTMapper to use for mapping GroupVersionKinds to Resources
	Mapper meta.RESTMapper

	// Resync is the base frequency the informers are resynced.
	// Defaults to defaultResyncTime.
	// A 10 percent jitter will be added to the Resync period between informers
	// So that all informers will not send list requests simultaneously.
	Resync *time.Duration

	// Namespace restricts the cache's ListWatch to the desired namespace
	// Default watches all namespaces
	Namespace string

	// SelectorsByObject restricts the cache's ListWatch to the desired
	// fields per GVK at the specified object, the map's value must implement
	// Selector [1] using for example a Set [2]
	// [1] https://pkg.go.dev/k8s.io/apimachinery/pkg/fields#Selector
	// [2] https://pkg.go.dev/k8s.io/apimachinery/pkg/fields#Set
	SelectorsByObject SelectorsByObject

	// DefaultSelector will be used as selectors for all object types
	// that do not have a selector in SelectorsByObject defined.
	DefaultSelector ObjectSelector

	// UnsafeDisableDeepCopyByObject indicates not to deep copy objects during get or
	// list objects per GVK at the specified object.
	// Be very careful with this, when enabled you must DeepCopy any object before mutating it,
	// otherwise you will mutate the object in the cache.
	UnsafeDisableDeepCopyByObject DisableDeepCopyByObject

	// TransformByObject is a map from GVKs to transformer functions which
	// get applied when objects of the transformation are about to be committed
	// to cache.
	//
	// This function is called both for new objects to enter the cache,
	// 	and for updated objects.
	TransformByObject TransformByObject

	// DefaultTransform is the transform used for all GVKs which do
	// not have an explicit transform func set in TransformByObject
	DefaultTransform toolscache.TransformFunc
}

Options are the optional arguments for creating a new InformersMap object.

type SelectorsByObject added in v1.0.1

type SelectorsByObject map[client.Object]ObjectSelector

SelectorsByObject associate a client.Object's GVK to a field/label selector. There is also `DefaultSelector` to set a global default (which will be overridden by a more specific setting here, if any).

type TransformByObject added in v1.0.1

type TransformByObject map[client.Object]toolscache.TransformFunc

TransformByObject associate a client.Object's GVK to a transformer function to be applied when storing the object into the cache.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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