Documentation
¶
Overview ¶
Package managedcache implements dynamic cache management to deal with RBAC separation and stopping of informers when they are no longer needed.
Index ¶
- type AccessManagerKey
- type Accessor
- type ConfigMapperFunc
- type EnqueueWatchingObjects
- func (e *EnqueueWatchingObjects) Create(_ context.Context, evt event.CreateEvent, ...)
- func (e *EnqueueWatchingObjects) Delete(_ context.Context, evt event.DeleteEvent, ...)
- func (e *EnqueueWatchingObjects) Generic(_ context.Context, evt event.GenericEvent, ...)
- func (e *EnqueueWatchingObjects) Update(_ context.Context, evt event.UpdateEvent, ...)
- type ObjectBoundAccessManager
- type ObjectsPerOwnerPerGVK
- type RefType
- type TrackingCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessManagerKey ¶ added in v0.2.0
type AccessManagerKey struct {
// UID ensures a re-created object also gets it's own cache.
UID types.UID
schema.GroupVersionKind
client.ObjectKey
}
AccessManagerKey is the key type on the ObjectBoundAccessManager's internal cache accessor map.
type Accessor ¶
type Accessor interface {
client.Writer
TrackingCache
}
Accessor provides write and cached read access to the cluster.
type ConfigMapperFunc ¶
type ConfigMapperFunc[T RefType] func( context.Context, T, *rest.Config, cache.Options) (*rest.Config, cache.Options, error)
ConfigMapperFunc applies changes to rest.Config and cache.Options based on the given object.
type EnqueueWatchingObjects ¶ added in v0.1.2
type EnqueueWatchingObjects struct {
WatcherRefGetter ownerRefGetter
// WatcherType is the type of the Owner object to look for in OwnerReferences. Only Group and Kind are compared.
WatcherType runtime.Object
// contains filtered or unexported fields
}
EnqueueWatchingObjects Enqueues all objects watching the object mentioned in the event, filtered by WatcherType.
func NewEnqueueWatchingObjects ¶ added in v0.1.2
func NewEnqueueWatchingObjects(watcherRefGetter ownerRefGetter, watcherType runtime.Object, scheme *runtime.Scheme, ) *EnqueueWatchingObjects
NewEnqueueWatchingObjects returns a new mapper putting the objects registered watching into the workqueue.
func (*EnqueueWatchingObjects) Create ¶ added in v0.1.2
func (e *EnqueueWatchingObjects) Create(_ context.Context, evt event.CreateEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request], )
Create implements handler.EventHandler.
func (*EnqueueWatchingObjects) Delete ¶ added in v0.1.2
func (e *EnqueueWatchingObjects) Delete(_ context.Context, evt event.DeleteEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request], )
Delete implements handler.EventHandler.
func (*EnqueueWatchingObjects) Generic ¶ added in v0.1.2
func (e *EnqueueWatchingObjects) Generic(_ context.Context, evt event.GenericEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request], )
Generic implements handler.EventHandler.
func (*EnqueueWatchingObjects) Update ¶ added in v0.1.2
func (e *EnqueueWatchingObjects) Update(_ context.Context, evt event.UpdateEvent, q workqueue.TypedRateLimitingInterface[reconcile.Request], )
Update implements handler.EventHandler.
type ObjectBoundAccessManager ¶
type ObjectBoundAccessManager[T RefType] interface { manager.Runnable // Get returns a TrackingCache for the provided object if one exists. // If one does not exist, a new Cache is created and returned. Get(ctx context.Context, owner T) (Accessor, error) // GetWithUser returns a TrackingCache for the provided object if one exist. // If one does not exist, a new Cache is created and returned. // The additional user and usedFor parameters are used to automatically // stop informers for objects that are no longer watched. // After all users have called .FreeWithUser(), the cache itself will be stopped. GetWithUser( ctx context.Context, owner T, user client.Object, usedFor []client.Object, ) (Accessor, error) // Free will stop and remove a TrackingCache for // the provided object, if one exists. Free(ctx context.Context, owner T) error // FreeWithUser informs the manager that the given user no longer needs // a cache scoped to owner T. If the cache has no active users, it will be stopped. FreeWithUser(ctx context.Context, owner T, user client.Object) error // Source returns a controller-runtime source to watch from a controller. Source(handler handler.EventHandler, predicates ...predicate.Predicate) source.Source GetWatchersForGVK(gvk schema.GroupVersionKind) (out []AccessManagerKey) CollectMetrics(ctx context.Context) (ObjectsPerOwnerPerGVK, error) }
ObjectBoundAccessManager manages caches and clients bound to objects. Each object instance will receive it's own cache and client instance.
func NewObjectBoundAccessManager ¶
func NewObjectBoundAccessManager[T RefType]( log logr.Logger, mapConfig ConfigMapperFunc[T], baseRestConfig *rest.Config, baseCacheOptions cache.Options, ) ObjectBoundAccessManager[T]
NewObjectBoundAccessManager returns a new ObjectBoundAccessManager for T.
type ObjectsPerOwnerPerGVK ¶ added in v0.6.0
type ObjectsPerOwnerPerGVK map[AccessManagerKey]map[schema.GroupVersionKind]int
ObjectsPerOwnerPerGVK is used to store data for collecting managed cache metrics.
type RefType ¶ added in v0.1.1
type RefType interface {
client.Object
comparable
}
RefType constrains the owner type of an ObjectBoundAccessManager.
type TrackingCache ¶
type TrackingCache interface {
cache.Cache
// Source returns a source to watch from a controller.
Source(handler handler.EventHandler, predicates ...predicate.Predicate) source.Source
// RemoveOtherInformers stops all informers that are not needed to watch the given list of object types.
RemoveOtherInformers(ctx context.Context, gvks sets.Set[schema.GroupVersionKind]) error
// GetGVKs returns a list of GVKs known by this trackingCache.
GetGVKs() []schema.GroupVersionKind
Watch(ctx context.Context, user client.Object, gvks sets.Set[schema.GroupVersionKind]) error
Free(ctx context.Context, user client.Object) error
GetObjectsPerInformer(ctx context.Context) (map[schema.GroupVersionKind]int, error)
}
TrackingCache is a cache remembering what objects are being cached and allows to stop caches/informers that are no longer needed.
func NewTrackingCache ¶
func NewTrackingCache(log logr.Logger, config *rest.Config, opts cache.Options) (TrackingCache, error)
NewTrackingCache returns a new TrackingCache instance.