cacher

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: Apache-2.0 Imports: 47 Imported by: 21

Documentation

Index

Constants

View Source
const (
	Pending status = iota
	Ready
	Stopped
)
View Source
const (

	// DefaultEventFreshDuration is the default time duration of events
	// we want to keep.
	// We set it to defaultBookmarkFrequency plus epsilon to maximize
	// chances that last bookmark was sent within kept history, at the
	// same time, minimizing the needed memory usage.
	DefaultEventFreshDuration = defaultBookmarkFrequency + 15*time.Second
)

Variables

View Source
var (
	// ConsistencyCheckPeriod is the period of checking consistency between etcd and cache.
	// 5 minutes were proposed to match the default compaction period. It's magnitute higher than
	// List latency SLO (30 seconds) and timeout (1 minute).
	ConsistencyCheckPeriod = 5 * time.Minute
	// ConsistencyCheckerEnabled enables the consistency checking mechanism for cache.
	// Based on KUBE_WATCHCACHE_CONSISTENCY_CHECKER environment variable.
	ConsistencyCheckerEnabled = false
)

Functions

func NewListerWatcher added in v0.28.0

func NewListerWatcher(storage storage.Interface, resourcePrefix string, newListFunc func() runtime.Object, contextMetadata metadata.MD) cache.ListerWatcher

NewListerWatcher returns a storage.Interface backed ListerWatcher.

Types

type CacheDelegator added in v0.33.0

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

func NewCacheDelegator added in v0.33.0

func NewCacheDelegator(cacher *Cacher, storage storage.Interface) *CacheDelegator

func (*CacheDelegator) Count added in v0.33.0

func (c *CacheDelegator) Count(pathPrefix string) (int64, error)

func (*CacheDelegator) Create added in v0.33.0

func (c *CacheDelegator) Create(ctx context.Context, key string, obj, out runtime.Object, ttl uint64) error

func (*CacheDelegator) Delete added in v0.33.0

func (c *CacheDelegator) Delete(ctx context.Context, key string, out runtime.Object, preconditions *storage.Preconditions, validateDeletion storage.ValidateObjectFunc, cachedExistingObject runtime.Object, opts storage.DeleteOptions) error

func (*CacheDelegator) Get added in v0.33.0

func (c *CacheDelegator) Get(ctx context.Context, key string, opts storage.GetOptions, objPtr runtime.Object) error

func (*CacheDelegator) GetCurrentResourceVersion added in v0.33.0

func (c *CacheDelegator) GetCurrentResourceVersion(ctx context.Context) (uint64, error)

func (*CacheDelegator) GetList added in v0.33.0

func (c *CacheDelegator) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error

func (*CacheDelegator) GuaranteedUpdate added in v0.33.0

func (c *CacheDelegator) GuaranteedUpdate(ctx context.Context, key string, destination runtime.Object, ignoreNotFound bool, preconditions *storage.Preconditions, tryUpdate storage.UpdateFunc, cachedExistingObject runtime.Object) error

func (*CacheDelegator) ReadinessCheck added in v0.33.0

func (c *CacheDelegator) ReadinessCheck() error

func (*CacheDelegator) RequestWatchProgress added in v0.33.0

func (c *CacheDelegator) RequestWatchProgress(ctx context.Context) error

func (*CacheDelegator) Stop added in v0.33.0

func (c *CacheDelegator) Stop()

func (*CacheDelegator) Versioner added in v0.33.0

func (c *CacheDelegator) Versioner() storage.Versioner

func (*CacheDelegator) Watch added in v0.33.0

type Cacher

type Cacher struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Cacher is responsible for serving WATCH and LIST requests for a given resource from its internal cache and updating its cache in the background based on the underlying storage contents. Cacher implements storage.Interface (although most of the calls are just delegated to the underlying storage).

func NewCacherFromConfig

func NewCacherFromConfig(config Config) (*Cacher, error)

NewCacherFromConfig creates a new Cacher responsible for servicing WATCH and LIST requests from its internal cache and updating its cache in the background based on the given configuration.

func (*Cacher) Get

func (c *Cacher) Get(ctx context.Context, key string, opts storage.GetOptions, objPtr runtime.Object) error

func (*Cacher) GetList added in v0.24.0

func (c *Cacher) GetList(ctx context.Context, key string, opts storage.ListOptions, listObj runtime.Object) error

GetList implements storage.Interface

func (*Cacher) LastSyncResourceVersion

func (c *Cacher) LastSyncResourceVersion() (uint64, error)

LastSyncResourceVersion returns resource version to which the underlying cache is synced.

func (*Cacher) Ready added in v0.33.0

func (c *Cacher) Ready() bool

func (*Cacher) ShouldDelegateConsistentRead added in v0.33.0

func (c *Cacher) ShouldDelegateConsistentRead() (delegator.Result, error)

func (*Cacher) ShouldDelegateContinue added in v0.33.0

func (c *Cacher) ShouldDelegateContinue(continueToken string, recursive bool) (delegator.Result, error)

func (*Cacher) ShouldDelegateExactRV added in v0.33.0

func (c *Cacher) ShouldDelegateExactRV(resourceVersion string, recursive bool) (delegator.Result, error)

func (*Cacher) Stop

func (c *Cacher) Stop()

Stop implements the graceful termination.

func (*Cacher) Wait added in v0.31.0

func (c *Cacher) Wait(ctx context.Context) error

Wait blocks until the cacher is Ready or Stopped, it returns an error if Stopped.

func (*Cacher) Watch

func (c *Cacher) Watch(ctx context.Context, key string, opts storage.ListOptions) (watch.Interface, error)

type Config

type Config struct {
	// An underlying storage.Interface.
	Storage storage.Interface

	// An underlying storage.Versioner.
	Versioner storage.Versioner

	// The GroupResource the cacher is caching. Used for disambiguating *unstructured.Unstructured (CRDs) in logging
	// and metrics.
	GroupResource schema.GroupResource

	// EventsHistoryWindow specifies minimum history duration that storage is keeping.
	// If lower than DefaultEventFreshDuration, the cache creation will fail.
	EventsHistoryWindow time.Duration

	// The Cache will be caching objects of a given Type and assumes that they
	// are all stored under ResourcePrefix directory in the underlying database.
	ResourcePrefix string

	// KeyFunc is used to get a key in the underlying storage for a given object.
	KeyFunc func(runtime.Object) (string, error)

	// GetAttrsFunc is used to get object labels, fields
	GetAttrsFunc func(runtime.Object) (label labels.Set, field fields.Set, err error)

	// IndexerFuncs is used for optimizing amount of watchers that
	// needs to process an incoming event.
	IndexerFuncs storage.IndexerFuncs

	// Indexers is used to accelerate the list operation, falls back to regular list
	// operation if no indexer found.
	Indexers *cache.Indexers

	// NewFunc is a function that creates new empty object storing a object of type Type.
	NewFunc func() runtime.Object

	// NewList is a function that creates new empty object storing a list of
	// objects of type Type.
	NewListFunc func() runtime.Object

	Codec runtime.Codec

	Clock clock.WithTicker
}

Config contains the configuration for a given Cache.

type Snapshotter added in v0.33.0

type Snapshotter interface {
	Reset()
	GetLessOrEqual(rv uint64) (orderedLister, bool)
	Add(rv uint64, indexer orderedLister)
	RemoveLess(rv uint64)
	Len() int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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