inmem

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package inmem provides an implementation of state.State in memory.

Index

Constants

This section is empty.

Variables

View Source
var NewState = NewStateWithOptions()

NewState creates new State with default options.

Functions

func Build

Build a local state for namespace.

func ErrAlreadyExists

func ErrAlreadyExists(r resource.Reference) error

ErrAlreadyExists generates error compatible with state.ErrConflict.

func ErrNotFound

func ErrNotFound(r resource.Pointer) error

ErrNotFound generates error compatible with state.ErrNotFound.

func ErrOwnerConflict

func ErrOwnerConflict(r resource.Reference, owner string) error

ErrOwnerConflict generates error compatible with state.ErrConflict.

func ErrPendingFinalizers

func ErrPendingFinalizers(r resource.Metadata) error

ErrPendingFinalizers generates error compatible with state.ErrConflict.

func ErrPhaseConflict

func ErrPhaseConflict(r resource.Reference, expectedPhase resource.Phase) error

ErrPhaseConflict generates error compatible with ErrConflict.

func ErrUpdateSameVersion

func ErrUpdateSameVersion(r resource.Reference, version resource.Version) error

ErrUpdateSameVersion generates error compatible with state.ErrConflict.

func ErrVersionConflict

func ErrVersionConflict(r resource.Reference, expected, found resource.Version) error

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

type LoadHandler func(resourceType resource.Type, resource resource.Resource) error

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) Get

func (collection *ResourceCollection) Get(resourceID resource.ID) (resource.Resource, error)

Get 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, singleCh chan<- state.Event, aggCh 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, _ ...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.

func (*State) Watch

func (st *State) Watch(ctx context.Context, resourcePointer resource.Pointer, ch chan<- state.Event, opts ...state.WatchOption) error

Watch a resource.

func (*State) WatchKind

func (st *State) WatchKind(ctx context.Context, resourceKind resource.Kind, ch chan<- state.Event, opts ...state.WatchKindOption) error

WatchKind all resources by type.

func (*State) WatchKindAggregated added in v0.3.0

func (st *State) WatchKindAggregated(ctx context.Context, resourceKind resource.Kind, ch chan<- []state.Event, opts ...state.WatchKindOption) error

WatchKindAggregated all resources by type.

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.

Jump to

Keyboard shortcuts

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