assumecache

package
v1.32.0-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongType  = errors.New("object has wrong type")
	ErrNotFound   = errors.New("object not found")
	ErrObjectName = errors.New("cannot determine object name")
)

Sentinel errors that can be checked for with errors.Is.

Functions

func AddTestObject

func AddTestObject(cache *AssumeCache, obj interface{})

AddTestObject adds an object to the assume cache. Only use this for unit testing!

func DeleteTestObject

func DeleteTestObject(cache *AssumeCache, obj interface{})

DeleteTestObject deletes object in the assume cache. Only use this for unit testing!

func UpdateTestObject

func UpdateTestObject(cache *AssumeCache, obj interface{})

UpdateTestObject updates an object in the assume cache. Only use this for unit testing!

Types

type AssumeCache

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

AssumeCache is a cache on top of the informer that allows for updating objects outside of informer events and also restoring the informer cache's version of the object. Objects are assumed to be Kubernetes API objects that are supported by meta.Accessor.

Objects can referenced via their key, with cache.MetaNamespaceKeyFunc as key function.

AssumeCache stores two pointers to represent a single object:

  • The pointer to the informer object.
  • The pointer to the latest object, which could be the same as the informer object, or an in-memory object.

An informer update always overrides the latest object pointer.

Assume() only updates the latest object pointer. Restore() sets the latest object pointer back to the informer object. Get/List() always returns the latest object pointer.

func NewAssumeCache

func NewAssumeCache(logger klog.Logger, informer Informer, description, indexName string, indexFunc cache.IndexFunc) *AssumeCache

NewAssumeCache creates an assume cache for general objects.

func (*AssumeCache) AddEventHandler

AddEventHandler adds an event handler to the cache. Events to a single handler are delivered sequentially, but there is no coordination between different handlers. A handler may use the cache.

The return value can be used to wait for cache synchronization.

func (*AssumeCache) Assume

func (c *AssumeCache) Assume(obj interface{}) error

Assume updates the object in-memory only.

The version of the object must be greater or equal to the current object, otherwise an error is returned.

Storing an object with the same version is supported by the assume cache, but suffers from a race: if an update is received via the informer while such an object is assumed, it gets dropped in favor of the newer object from the apiserver.

Only assuming objects that were returned by an apiserver operation (Update, Patch) is safe.

func (*AssumeCache) Get

func (c *AssumeCache) Get(key string) (interface{}, error)

Get the object by its key.

func (*AssumeCache) GetAPIObj

func (c *AssumeCache) GetAPIObj(key string) (interface{}, error)

GetAPIObj gets the informer cache's version by its key.

func (*AssumeCache) List

func (c *AssumeCache) List(indexObj interface{}) []interface{}

List all the objects in the cache.

func (*AssumeCache) Restore

func (c *AssumeCache) Restore(objName string)

Restore the informer cache's version of the object.

type Informer

type Informer interface {
	AddEventHandler(handler cache.ResourceEventHandler) (cache.ResourceEventHandlerRegistration, error)
}

Informer is the subset of cache.SharedInformer that NewAssumeCache depends upon.

type NotFoundError

type NotFoundError struct {
	TypeName  string
	ObjectKey string
}

func (NotFoundError) Error

func (e NotFoundError) Error() string

func (NotFoundError) Is

func (e NotFoundError) Is(err error) bool

type ObjectNameError

type ObjectNameError struct {
	DetailedErr error
}

func (ObjectNameError) Error

func (e ObjectNameError) Error() string

func (ObjectNameError) Is

func (e ObjectNameError) Is(err error) bool

type WrongTypeError

type WrongTypeError struct {
	TypeName string
	Object   interface{}
}

func (WrongTypeError) Error

func (e WrongTypeError) Error() string

func (WrongTypeError) Is

func (e WrongTypeError) Is(err error) bool

Jump to

Keyboard shortcuts

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