Documentation ¶
Overview ¶
Package cache implements resource cache.
Index ¶
- func ErrNotFound(r resource.Pointer) error
- type ResourceCache
- func (cache *ResourceCache) CacheAppend(r resource.Resource)
- func (cache *ResourceCache) CachePut(r resource.Resource)
- func (cache *ResourceCache) CacheRemove(r resource.Resource)
- func (cache *ResourceCache) ContextWithTeardown(ctx context.Context, ptr resource.Pointer) (context.Context, error)
- func (cache *ResourceCache) Get(ctx context.Context, ptr resource.Pointer, opts ...state.GetOption) (resource.Resource, error)
- func (cache *ResourceCache) IsHandled(namespace resource.Namespace, resourceType resource.Type) bool
- func (cache *ResourceCache) IsHandledBootstrapped(namespace resource.Namespace, resourceType resource.Type) (handled bool, bootstrapped bool)
- func (cache *ResourceCache) Len(namespace resource.Namespace, resourceType resource.Type) int
- func (cache *ResourceCache) List(ctx context.Context, kind resource.Kind, opts ...state.ListOption) (resource.List, error)
- func (cache *ResourceCache) MarkBootstrapped(namespace resource.Namespace, resourceType resource.Type)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrNotFound ¶
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 ¶
func (cache *ResourceCache) Get(ctx context.Context, ptr resource.Pointer, opts ...state.GetOption) (resource.Resource, error)
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) 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.