cache

package
v0.0.0-...-bfef3a7 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Added    = DeltaType(toolscache.Added)
	Deleted  = DeltaType(toolscache.Deleted)
	Updated  = DeltaType(toolscache.Updated)
	Replaced = DeltaType(toolscache.Replaced)
	Sync     = DeltaType(toolscache.Sync)
	Upserted = DeltaType("Upserted") // for events that are either an update/replace or an add
)
View Source
const DefaultWatchChannelBuffer = 256

Variables

View Source
var NilDelta = Delta{Object: nil}

NilDelta is a placeholder for a delta that means no change.

Functions

This section is empty.

Types

type CompositeCache

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

func NewCompositeCache

func NewCompositeCache(config *rest.Config, opts Options) (*CompositeCache, error)

func (*CompositeCache) Get

func (cc *CompositeCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error

func (*CompositeCache) GetDefaultCache

func (cc *CompositeCache) GetDefaultCache() cache.Cache

func (*CompositeCache) GetInformer

func (cc *CompositeCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)

func (*CompositeCache) GetInformerForKind

func (cc *CompositeCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, opts ...cache.InformerGetOption) (cache.Informer, error)

func (*CompositeCache) GetLogger

func (cc *CompositeCache) GetLogger() logr.Logger

func (*CompositeCache) GetViewCache

func (cc *CompositeCache) GetViewCache() *ViewCache

func (*CompositeCache) IndexField

func (cc *CompositeCache) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error

func (*CompositeCache) List

func (cc *CompositeCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

func (*CompositeCache) RemoveInformer

func (cc *CompositeCache) RemoveInformer(ctx context.Context, obj client.Object) error

func (*CompositeCache) Start

func (cc *CompositeCache) Start(ctx context.Context) error

func (*CompositeCache) WaitForCacheSync

func (cc *CompositeCache) WaitForCacheSync(ctx context.Context) bool

type Delta

type Delta struct {
	Object object.Object
	Type   DeltaType
}

Delta registers a change (addition, deletion, etc) on an object. By convention, Object is nil if no change occurs.

func (Delta) IsUnchanged

func (d Delta) IsUnchanged() bool

func (Delta) String

func (d Delta) String() string

type DeltaType

type DeltaType string

type FakeInformer

type FakeInformer struct {
	// Synced is returned by the HasSynced functions to implement the Informer interface
	Synced bool

	// RunCount is incremented each time RunInformersAndControllers is called
	RunCount int

	Indexer Lister
	// contains filtered or unexported fields
}

FakeInformer provides fake Informer functionality for testing.

func (*FakeInformer) Add

func (f *FakeInformer) Add(obj metav1.Object)

Add fakes an Add event for obj.

func (*FakeInformer) AddEventHandler

AddEventHandler implements the Informer interface. Adds an EventHandler to the fake Informers. TODO(community): Implement Registration.

func (*FakeInformer) AddEventHandlerWithResyncPeriod

AddEventHandlerWithResyncPeriod does nothing. TODO(community): Implement this.

func (*FakeInformer) AddIndexers

func (f *FakeInformer) AddIndexers(indexers toolscache.Indexers) error

AddIndexers does nothing. TODO(community): Implement this.

func (*FakeInformer) Delete

func (f *FakeInformer) Delete(obj metav1.Object)

Delete fakes an Delete event for obj.

func (*FakeInformer) GetController

func (f *FakeInformer) GetController() toolscache.Controller

GetController does nothing. TODO(community): Implement this.

func (*FakeInformer) GetIndexer

func (f *FakeInformer) GetIndexer() toolscache.Indexer

GetIndexer does nothing. TODO(community): Implement this.

func (*FakeInformer) GetStore

func (f *FakeInformer) GetStore() toolscache.Store

GetStore does nothing. TODO(community): Implement this.

func (*FakeInformer) HasSynced

func (f *FakeInformer) HasSynced() bool

HasSynced implements the Informer interface. Returns f.Synced.

func (*FakeInformer) Informer

Informer returns the fake Informer.

func (*FakeInformer) IsStopped

func (f *FakeInformer) IsStopped() bool

IsStopped does nothing. TODO(community): Implement this.

func (*FakeInformer) LastSyncResourceVersion

func (f *FakeInformer) LastSyncResourceVersion() string

LastSyncResourceVersion does nothing. TODO(community): Implement this.

func (*FakeInformer) RemoveEventHandler

func (f *FakeInformer) RemoveEventHandler(handle toolscache.ResourceEventHandlerRegistration) error

RemoveEventHandler does nothing. TODO(community): Implement this.

func (*FakeInformer) Run

func (f *FakeInformer) Run(<-chan struct{})

Run implements the Informer interface. Increments f.RunCount.

func (*FakeInformer) SetTransform

func (f *FakeInformer) SetTransform(t toolscache.TransformFunc) error

SetTransform does nothing. TODO(community): Implement this.

func (*FakeInformer) SetWatchErrorHandler

func (f *FakeInformer) SetWatchErrorHandler(toolscache.WatchErrorHandler) error

SetWatchErrorHandler does nothing. TODO(community): Implement this.

func (*FakeInformer) Update

func (f *FakeInformer) Update(oldObj, newObj metav1.Object)

Update fakes an Update event for obj.

type FakeRuntimeCache

type FakeRuntimeCache struct {
	InformersByGVK map[schema.GroupVersionKind]toolscache.SharedIndexInformer
	Error          error
	Synced         *bool
	Store          *Store
}

FakeRuntimeCache is a fake implementation of Informers. Client can store only a single object. Source: sigs.k8s.io/controller-runtime/pkg/cache/informertest/fake_cache.go.

func NewFakeRuntimeCache

func NewFakeRuntimeCache(s *runtime.Scheme) *FakeRuntimeCache

func (*FakeRuntimeCache) Add

func (c *FakeRuntimeCache) Add(obj any) error

func (*FakeRuntimeCache) Delete

func (c *FakeRuntimeCache) Delete(obj any) error

func (*FakeRuntimeCache) Get

func (*FakeRuntimeCache) GetInformer

func (c *FakeRuntimeCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)

GetInformer implements Informers.

func (*FakeRuntimeCache) GetInformerForKind

func (c *FakeRuntimeCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, opts ...cache.InformerGetOption) (cache.Informer, error)

GetInformerForKind implements Informers.

func (*FakeRuntimeCache) IndexField

func (c *FakeRuntimeCache) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error

IndexField implements Cache.

func (*FakeRuntimeCache) List

func (*FakeRuntimeCache) RemoveInformer

func (c *FakeRuntimeCache) RemoveInformer(ctx context.Context, obj client.Object) error

RemoveInformer implements Informers.

func (*FakeRuntimeCache) Start

func (c *FakeRuntimeCache) Start(ctx context.Context) error

Start implements Informers.

func (*FakeRuntimeCache) Update

func (c *FakeRuntimeCache) Update(oldObj, newObj any) error

func (*FakeRuntimeCache) WaitForCacheSync

func (c *FakeRuntimeCache) WaitForCacheSync(ctx context.Context) bool

WaitForCacheSync implements Informers.

type Lister

type Lister interface {
	List() []object.Object
}

type Options

type Options struct {
	cache.Options
	// DefaultCache is the controller-runtime cache used for anything that is not a view.
	DefaultCache cache.Cache
	// Logger is for logging. Currently only the viewcache generates log messages.
	Logger logr.Logger
}

Options are generic caching options

type Store

type Store struct {
	Store toolscache.Store
}

Store is like toolscache.Store but it also deep-copies objects

func NewStore

func NewStore() *Store

func (*Store) Add

func (s *Store) Add(obj object.Object) error

Add adds the given object to the database associated with the given object's key

func (*Store) Delete

func (s *Store) Delete(obj object.Object) error

Delete deletes the given object from the database associated with the given object's key

func (*Store) Get

func (s *Store) Get(obj object.Object) (object.Object, bool, error)

Get returns the database associated with the given object's key

func (*Store) GetByKey

func (s *Store) GetByKey(key string) (object.Object, bool, error)

GetByKey returns the database associated with the given key

func (*Store) List

func (s *Store) List() []object.Object

List returns a list of all the currently non-empty databases

func (*Store) ListKeys

func (s *Store) ListKeys() []string

ListKeys returns a list of all the keys currently associated with non-empty databases

func (*Store) Replace

func (s *Store) Replace(objs []object.Object, arg string) error

Replace will delete the contents of the store, using instead the given list. Store takes ownership of the list, you should not reference it after calling this function.

func (*Store) Resync

func (s *Store) Resync() error

Resync is meaningless in the terms appearing here but has meaning in some implementations that have non-trivial additional behavior (e.g., DeltaFIFO).

func (*Store) Update

func (s *Store) Update(obj object.Object) error

Update updates the given object in the database associated with the given object's key

type ViewCache

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

func NewViewCache

func NewViewCache(opts Options) *ViewCache

func (*ViewCache) Add

func (c *ViewCache) Add(obj object.Object) error

Add can manually insert objects into the cache.

func (*ViewCache) Delete

func (c *ViewCache) Delete(obj object.Object) error

Delete can manually remove objects from the cache.

func (*ViewCache) Dump

func (c *ViewCache) Dump(ctx context.Context, gvk schema.GroupVersionKind) []string

func (*ViewCache) Get

func (c *ViewCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error

func (*ViewCache) GetCacheForKind

func (c *ViewCache) GetCacheForKind(gvk schema.GroupVersionKind) (toolscache.Indexer, error)

func (*ViewCache) GetInformer

func (c *ViewCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)

func (*ViewCache) GetInformerForKind

func (c *ViewCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, _ ...cache.InformerGetOption) (cache.Informer, error)

func (*ViewCache) IndexField

func (c *ViewCache) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error

func (*ViewCache) List

func (c *ViewCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

func (*ViewCache) RegisterCacheForKind

func (c *ViewCache) RegisterCacheForKind(gvk schema.GroupVersionKind) error

func (*ViewCache) RegisterInformerForKind

func (c *ViewCache) RegisterInformerForKind(gvk schema.GroupVersionKind) error

func (*ViewCache) RemoveInformer

func (c *ViewCache) RemoveInformer(ctx context.Context, obj client.Object) error

func (*ViewCache) Start

func (c *ViewCache) Start(ctx context.Context) error

Start runs all the informers known to this cache until the context is closed. It blocks.

func (*ViewCache) Update

func (c *ViewCache) Update(oldObj, newObj object.Object) error

Update can manually modify objects in the cache.

func (*ViewCache) WaitForCacheSync

func (c *ViewCache) WaitForCacheSync(_ context.Context) bool

func (*ViewCache) Watch

func (c *ViewCache) Watch(ctx context.Context, list client.ObjectList, opts ...client.ListOption) (watch.Interface, error)

type ViewCacheInformer

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

func NewViewCacheInformer

func NewViewCacheInformer(gvk schema.GroupVersionKind, indexer toolscache.Indexer, logger logr.Logger) *ViewCacheInformer

func (*ViewCacheInformer) AddEventHandlerWithResyncPeriod

func (c *ViewCacheInformer) AddEventHandlerWithResyncPeriod(handler toolscache.ResourceEventHandler, resyncPeriod time.Duration) (toolscache.ResourceEventHandlerRegistration, error)

func (*ViewCacheInformer) AddIndexers

func (c *ViewCacheInformer) AddIndexers(indexers toolscache.Indexers) error

func (*ViewCacheInformer) GetController

func (c *ViewCacheInformer) GetController() toolscache.Controller

func (*ViewCacheInformer) GetIndexer

func (c *ViewCacheInformer) GetIndexer() toolscache.Indexer

func (*ViewCacheInformer) GetStore

func (c *ViewCacheInformer) GetStore() toolscache.Store

func (*ViewCacheInformer) HasSynced

func (c *ViewCacheInformer) HasSynced() bool

func (*ViewCacheInformer) IsStopped

func (c *ViewCacheInformer) IsStopped() bool

func (*ViewCacheInformer) LastSyncResourceVersion

func (c *ViewCacheInformer) LastSyncResourceVersion() string

func (*ViewCacheInformer) RemoveEventHandler

func (c *ViewCacheInformer) RemoveEventHandler(registration toolscache.ResourceEventHandlerRegistration) error

func (*ViewCacheInformer) Run

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

func (*ViewCacheInformer) SetTransform

func (c *ViewCacheInformer) SetTransform(transform toolscache.TransformFunc) error

func (*ViewCacheInformer) SetWatchErrorHandler

func (c *ViewCacheInformer) SetWatchErrorHandler(handler toolscache.WatchErrorHandler) error

func (*ViewCacheInformer) TriggerEvent

func (c *ViewCacheInformer) TriggerEvent(eventType toolscache.DeltaType, oldObj, newObj object.Object, isInitialList bool)

TriggerEvent will send an event on newObj of eventType to all registered handlers. Set isInitialList to true if event is an Added as a part of the initial object list. For all event types except Update events the oldObj must not be nil.

type ViewCacheWatcher

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

func (*ViewCacheWatcher) ResultChan

func (w *ViewCacheWatcher) ResultChan() <-chan watch.Event

func (*ViewCacheWatcher) Stop

func (w *ViewCacheWatcher) Stop()

Jump to

Keyboard shortcuts

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