Documentation ¶
Overview ¶
Package inmem provides an implementation of state.State in memory.
Index ¶
- Variables
- func Build(ns resource.Namespace) state.CoreState
- func ErrAlreadyExists(r resource.Reference) error
- func ErrNotFound(r resource.Pointer) error
- func ErrOwnerConflict(r resource.Reference, owner string) error
- func ErrPendingFinalizers(r resource.Metadata) error
- func ErrPhaseConflict(r resource.Reference, expectedPhase resource.Phase) error
- func ErrUpdateSameVersion(r resource.Reference, version resource.Version) error
- func ErrVersionConflict(r resource.Reference, expected, found resource.Version) error
- func NewStateWithOptions(opts ...StateOption) func(ns resource.Namespace) *State
- type BackingStore
- type LoadHandler
- type ResourceCollection
- func (collection *ResourceCollection) Create(ctx context.Context, res resource.Resource, owner string) error
- func (collection *ResourceCollection) Destroy(ctx context.Context, ptr resource.Pointer, owner string) error
- func (collection *ResourceCollection) Get(resourceID resource.ID) (resource.Resource, error)
- func (collection *ResourceCollection) List(options *state.ListOptions) (resource.List, error)
- func (collection *ResourceCollection) Update(ctx context.Context, newResource resource.Resource, ...) error
- func (collection *ResourceCollection) Watch(ctx context.Context, id resource.ID, ch chan<- state.Event, ...) error
- func (collection *ResourceCollection) WatchAll(ctx context.Context, ch chan<- state.Event, opts ...state.WatchKindOption) error
- type State
- func (st *State) Create(ctx context.Context, resource resource.Resource, opts ...state.CreateOption) error
- func (st *State) Destroy(ctx context.Context, resourcePointer resource.Pointer, ...) error
- func (st *State) Get(ctx context.Context, resourcePointer resource.Pointer, opts ...state.GetOption) (resource.Resource, error)
- func (st *State) List(ctx context.Context, resourceKind resource.Kind, opts ...state.ListOption) (resource.List, error)
- func (st *State) Update(ctx context.Context, newResource resource.Resource, opts ...state.UpdateOption) error
- func (st *State) Watch(ctx context.Context, resourcePointer resource.Pointer, ch chan<- state.Event, ...) error
- func (st *State) WatchKind(ctx context.Context, resourceKind resource.Kind, ch chan<- state.Event, ...) error
- type StateOption
- type StateOptions
Constants ¶
This section is empty.
Variables ¶
var NewState = NewStateWithOptions()
NewState creates new State with default options.
Functions ¶
func ErrAlreadyExists ¶
ErrAlreadyExists generates error compatible with state.ErrConflict.
func ErrNotFound ¶
ErrNotFound generates error compatible with state.ErrNotFound.
func ErrOwnerConflict ¶
ErrOwnerConflict generates error compatible with state.ErrConflict.
func ErrPendingFinalizers ¶
ErrPendingFinalizers generates error compatible with state.ErrConflict.
func ErrPhaseConflict ¶
ErrPhaseConflict generates error compatible with ErrConflict.
func ErrUpdateSameVersion ¶
ErrUpdateSameVersion generates error compatible with state.ErrConflict.
func ErrVersionConflict ¶
ErrVersionConflict generates error compatible with state.ErrConflict.
func NewStateWithOptions ¶
func NewStateWithOptions(opts ...StateOption) func(ns resource.Namespace) *State
NewStateWithOptions returns state builder function with options.
Types ¶
type BackingStore ¶
type BackingStore interface { // Load contents of the backing store into the in-memory resource collection. // // Handler should be called for each resource in the backing store. Load(ctx context.Context, handler LoadHandler) error // Put the resource to the backing store. Put(ctx context.Context, resourceType resource.Type, resource resource.Resource) error // Destroy the resource from the backing store. Destroy(ctx context.Context, resourceType resource.Type, resourcePointer resource.Pointer) error }
BackingStore provides a way to persist contents of in-memory resource collection.
All resources are still kept in memory, but the backing store is used to persist the resources across process restarts.
BackingStore is responsible for marshaling/unmarshaling of resources.
BackingStore is optional for in-memory resource collection.
type LoadHandler ¶
LoadHandler is called for each resource loaded from the backing store.
type ResourceCollection ¶
type ResourceCollection struct {
// contains filtered or unexported fields
}
ResourceCollection implements slice of State (by resource type).
func NewResourceCollection ¶
func NewResourceCollection(ns resource.Namespace, typ resource.Type, initialCapacity, maxCapacity, gap int, store BackingStore) *ResourceCollection
NewResourceCollection returns new ResourceCollection.
func (*ResourceCollection) Create ¶
func (collection *ResourceCollection) Create(ctx context.Context, res resource.Resource, owner string) error
Create a resource.
func (*ResourceCollection) Destroy ¶
func (collection *ResourceCollection) Destroy(ctx context.Context, ptr resource.Pointer, owner string) error
Destroy a resource.
func (*ResourceCollection) List ¶
func (collection *ResourceCollection) List(options *state.ListOptions) (resource.List, error)
List resources.
func (*ResourceCollection) Update ¶
func (collection *ResourceCollection) Update(ctx context.Context, newResource resource.Resource, options *state.UpdateOptions) error
Update a resource.
func (*ResourceCollection) Watch ¶
func (collection *ResourceCollection) Watch(ctx context.Context, id resource.ID, ch chan<- state.Event, opts ...state.WatchOption) error
Watch for specific resource changes.
func (*ResourceCollection) WatchAll ¶
func (collection *ResourceCollection) WatchAll(ctx context.Context, ch chan<- state.Event, opts ...state.WatchKindOption) error
WatchAll for any resource change stored in this collection.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State implements state.CoreState.
func (*State) Create ¶
func (st *State) Create(ctx context.Context, resource resource.Resource, opts ...state.CreateOption) error
Create a resource.
func (*State) Destroy ¶
func (st *State) Destroy(ctx context.Context, resourcePointer resource.Pointer, opts ...state.DestroyOption) error
Destroy a resource.
func (*State) Get ¶
func (st *State) Get(ctx context.Context, resourcePointer resource.Pointer, opts ...state.GetOption) (resource.Resource, error)
Get a resource.
func (*State) List ¶
func (st *State) List(ctx context.Context, resourceKind resource.Kind, opts ...state.ListOption) (resource.List, error)
List resources.
func (*State) Update ¶
func (st *State) Update(ctx context.Context, newResource resource.Resource, opts ...state.UpdateOption) error
Update a resource.
type StateOption ¶
type StateOption func(options *StateOptions)
StateOption applies settings to StateOptions.
func WithBackingStore ¶
func WithBackingStore(store BackingStore) StateOption
WithBackingStore sets a BackingStore for a in-memory resource collection.
Default value is nil (no backing store).
func WithHistoryCapacity
deprecated
func WithHistoryCapacity(capacity int) StateOption
WithHistoryCapacity sets history depth for a given namspace and resource.
Deprecated: use WithHistoryMaxCapacity and WithHistoryInitialCapacity instead.
func WithHistoryGap ¶
func WithHistoryGap(gap int) StateOption
WithHistoryGap sets a safety gap between watch events consumers and events producers.
Bigger gap reduces effective history depth (HistoryCapacity - HistoryGap). Smaller gap might result in buffer overruns if consumer can't keep up with the events. It's recommended to have gap 5% of the capacity.
func WithHistoryInitialCapacity ¶ added in v0.3.0
func WithHistoryInitialCapacity(initialCapacity int) StateOption
WithHistoryInitialCapacity sets initial history depth for a given namspace and resource.
Deep history requires more memory, but allows Watch request to return more historical entries, and also acts like a buffer if watch consumer can't keep up with events.
Initial capacity of the history buffer is used at the creation time and grows to the max capacity based on the number of events.
func WithHistoryMaxCapacity ¶ added in v0.3.0
func WithHistoryMaxCapacity(maxCapacity int) StateOption
WithHistoryMaxCapacity sets history depth for a given namspace and resource.
Deep history requires more memory, but allows Watch request to return more historical entries, and also acts like a buffer if watch consumer can't keep up with events.
Max capacity limits the maximum depth of the history buffer.
type StateOptions ¶
type StateOptions struct { BackingStore BackingStore HistoryMaxCapacity int HistoryInitialCapacity int HistoryGap int }
StateOptions configure inmem.State.
func DefaultStateOptions ¶
func DefaultStateOptions() StateOptions
DefaultStateOptions returns default value of StateOptions.