cache

package
v0.4.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package cache implements resource cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrNotFound

func ErrNotFound(r resource.Pointer) error

ErrNotFound generates error compatible with state.ErrNotFound.

Types

type ResourceCache

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

ResourceCache provides a read-only view of resources which implements controller.Reader interface.

ResourceCache is populated by controller runtime based on Watch events.

ResourceCache is supposed to be used with WatchKind with BootstrapContents: - before the Bootstrapped event, Get/List will block, and Watch handler should call CacheAppend to populate the cache - on the Bootstrapped event, Watch handler should call MarkBootstrapped, and Get/List operations will be unblocked - after the Bootstrapped event, CachePut/CacheRemove should be called to update the cache.

Get/List operations will always return date from the cache without blocking once the cache is bootstrapped.

func NewResourceCache

func NewResourceCache(resources []options.CachedResource) *ResourceCache

NewResourceCache creates new resource cache.

func (*ResourceCache) CacheAppend

func (cache *ResourceCache) CacheAppend(r resource.Resource)

CacheAppend appends the value to the cached list.

CacheAppend should be called in the bootstrapped phase, with resources coming in sorted by ID order.

func (*ResourceCache) CachePut

func (cache *ResourceCache) CachePut(r resource.Resource)

CachePut handles updated/created objects.

It is called once the bootstrap is done.

func (*ResourceCache) CacheRemove

func (cache *ResourceCache) CacheRemove(r resource.Resource)

CacheRemove handles deleted objects.

func (*ResourceCache) ContextWithTeardown

func (cache *ResourceCache) ContextWithTeardown(ctx context.Context, ptr resource.Pointer) (context.Context, error)

ContextWithTeardown implements controller.Reader interface.

func (*ResourceCache) Get

Get implements controller.Reader interface.

func (*ResourceCache) IsHandled

func (cache *ResourceCache) IsHandled(namespace resource.Namespace, resourceType resource.Type) bool

IsHandled returns true if cache is handling given resource type.

func (*ResourceCache) IsHandledBootstrapped

func (cache *ResourceCache) IsHandledBootstrapped(namespace resource.Namespace, resourceType resource.Type) (handled bool, bootstrapped bool)

IsHandledBootstrapped returns true if cache is handling given resource type and whether it is bootstrapped.

func (*ResourceCache) Len

func (cache *ResourceCache) Len(namespace resource.Namespace, resourceType resource.Type) int

Len returns number of cached resources.

func (*ResourceCache) List

func (cache *ResourceCache) List(ctx context.Context, kind resource.Kind, opts ...state.ListOption) (resource.List, error)

List implements controller.Reader interface.

func (*ResourceCache) MarkBootstrapped

func (cache *ResourceCache) MarkBootstrapped(namespace resource.Namespace, resourceType resource.Type)

MarkBootstrapped marks cache as bootstrapped.

Jump to

Keyboard shortcuts

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