storage

package
v0.11.2-rc2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEventChannelClosed = errors.New("event channel closed")
	ErrObjectDeleted      = errors.New("object deleted")
)
View Source
var ErrAlreadyExists = &AlreadyExistsError{}
View Source
var ErrNotFound = &NotFoundError{}

Functions

func ApplyRoleBindingTaints

func ApplyRoleBindingTaints(ctx context.Context, store RBACStore, rb *corev1.RoleBinding) error

func GetStoreBuilder added in v0.9.2

func GetStoreBuilder[T ~string](name T) func(...any) (any, error)

func IgnoreErrNotFound added in v0.10.0

func IgnoreErrNotFound(err error) error

func NewRBACProvider

func NewRBACProvider(store SubjectAccessCapableStore) rbac.Provider

func NewWatchContext added in v0.6.0

func NewWatchContext[T any](
	base context.Context,
	eventC <-chan WatchEvent[T],
) context.Context

Returns a context that listens on a watch event channel and closes its Done channel when the object is deleted. This context should have exclusive read access to the event channel to avoid missing events.

func RegisterStoreBuilder added in v0.9.2

func RegisterStoreBuilder[T ~string](name T, builder func(...any) (any, error))

Types

type AlertFilterOptions added in v0.5.4

type AlertFilterOptions struct {
	Labels map[string]string
	Range  *corev1.TimeRange
}

type AlreadyExistsError added in v0.7.0

type AlreadyExistsError struct{}

func (*AlreadyExistsError) Error added in v0.7.0

func (e *AlreadyExistsError) Error() string

func (*AlreadyExistsError) GRPCStatus added in v0.7.0

func (e *AlreadyExistsError) GRPCStatus() *status.Status

type ClusterMutator

type ClusterMutator = MutatorFunc[*corev1.Cluster]

type ClusterStore

type ClusterStore interface {
	CreateCluster(ctx context.Context, cluster *corev1.Cluster) error
	DeleteCluster(ctx context.Context, ref *corev1.Reference) error
	GetCluster(ctx context.Context, ref *corev1.Reference) (*corev1.Cluster, error)
	UpdateCluster(ctx context.Context, ref *corev1.Reference, mutator ClusterMutator) (*corev1.Cluster, error)
	WatchCluster(ctx context.Context, cluster *corev1.Cluster) (<-chan WatchEvent[*corev1.Cluster], error)
	WatchClusters(ctx context.Context, known []*corev1.Cluster) (<-chan WatchEvent[*corev1.Cluster], error)
	ListClusters(ctx context.Context, matchLabels *corev1.LabelSelector, matchOptions corev1.MatchOptions) (*corev1.ClusterList, error)
}

type CompositeBackend

func (*CompositeBackend) IsValid

func (cb *CompositeBackend) IsValid() bool

func (*CompositeBackend) Use

func (cb *CompositeBackend) Use(store any)

type GrpcTtlCache added in v0.9.2

type GrpcTtlCache[T any] interface {
	// getter for default cache's configuration
	MaxAge() time.Duration

	Get(key string) (resp T, ok bool)
	// If 0 is passed as ttl, the default cache's configuration will be used
	Set(key string, resp T, ttl time.Duration)
	Delete(key string)
}

type HttpTtlCache added in v0.8.3

type HttpTtlCache[T any] interface {
	// getter for default cache's configuration
	MaxAge() time.Duration

	Get(key string) (resp T, ok bool)
	// If 0 is passed as ttl, the default cache's configuration will be used
	Set(key string, resp T)
	Delete(key string)
}

type KeyValueStore

type KeyValueStore KeyValueStoreT[[]byte]

type KeyValueStoreBroker

type KeyValueStoreBroker interface {
	KeyValueStore(namespace string) KeyValueStore
}

type KeyValueStoreLocker added in v0.6.0

type KeyValueStoreLocker[T any] interface {
	KeyValueStoreT[T]
	sync.Locker
}

func NewKeyValueStoreLocker added in v0.6.0

func NewKeyValueStoreLocker[T any](s KeyValueStoreT[T]) KeyValueStoreLocker[T]

type KeyValueStoreT added in v0.6.0

type KeyValueStoreT[T any] interface {
	Put(ctx context.Context, key string, value T) error
	Get(ctx context.Context, key string) (T, error)
	Delete(ctx context.Context, key string) error
	ListKeys(ctx context.Context, prefix string) ([]string, error)
}

func NewKeyValueStoreWithPrefix added in v0.6.0

func NewKeyValueStoreWithPrefix[T any](base KeyValueStoreT[T], prefix string) KeyValueStoreT[T]

type KeyringStore

type KeyringStore interface {
	Put(ctx context.Context, keyring keyring.Keyring) error
	Get(ctx context.Context) (keyring.Keyring, error)
	Delete(ctx context.Context) error
}

type KeyringStoreBroker

type KeyringStoreBroker interface {
	KeyringStore(namespace string, ref *corev1.Reference) KeyringStore
}

type Lock added in v0.11.2

type Lock interface {
	// Lock acquires a lock on the key. If the lock is already held, it will block until the lock is released.\
	//
	// Lock returns an error when acquiring the lock fails.
	Lock() error
	// Unlock releases the lock on the key. If the lock was never held, it will return an error.
	Unlock() error
}

Lock is a distributed lock that can be used to coordinate access to a resource.

Locks are single use, and return errors when used more than once. Retry mechanisms are built into\ the Lock and can be configured with LockOptions.

type LockManager added in v0.11.2

type LockManager interface {
	// Instantiates a new Lock instance for the given key, with the given options.
	//
	// Defaults to lock.DefaultOptions if no options are provided.
	Locker(key string, opts ...lock.LockOption) Lock
}

LockManager replaces sync.Mutex when a distributed locking mechanism is required.

Usage

## Transient lock (transactions, tasks, ...) ```

	func distributedTransation(lm stores.LockManager, key string) error {
		keyMu := lm.Locker(key, lock.WithKeepalive(false), lock.WithExpireDuration(1 * time.Second))
		if err := keyMu.Lock(); err != nil {
		return err
		}
		defer keyMu.Unlock()
     // do some work
	}

```

## Persistent lock (leader election)

```

func serve(lm stores.LockManager, key string, done chan struct{}) error {
	keyMu := lm.Locker(key, lock.WithKeepalive(true))
	if err := keyMu.Lock(); err != nil {
		return err
	}
	go func() {
		<-done
		keyMu.Unlock()
	}()
	// serve a service...
}

```

type MutatorFunc

type MutatorFunc[T any] func(T)

func NewAddCapabilityMutator

func NewAddCapabilityMutator[O corev1.MetadataAccessor[T], T corev1.Capability[T]](capability T) MutatorFunc[O]

func NewCompositeMutator

func NewCompositeMutator[T any](mutators ...MutatorFunc[T]) MutatorFunc[T]

func NewIncrementUsageCountMutator

func NewIncrementUsageCountMutator() MutatorFunc[*corev1.BootstrapToken]

func NewRemoveCapabilityMutator

func NewRemoveCapabilityMutator[O corev1.MetadataAccessor[T], T corev1.Capability[T]](capability T) MutatorFunc[O]

type NotFoundError

type NotFoundError struct{}

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

func (*NotFoundError) GRPCStatus

func (e *NotFoundError) GRPCStatus() *status.Status

type RBACStore

type RBACStore interface {
	CreateRole(context.Context, *corev1.Role) error
	UpdateRole(ctx context.Context, ref *corev1.Reference, mutator RoleMutator) (*corev1.Role, error)
	DeleteRole(context.Context, *corev1.Reference) error
	GetRole(context.Context, *corev1.Reference) (*corev1.Role, error)
	CreateRoleBinding(context.Context, *corev1.RoleBinding) error
	UpdateRoleBinding(ctx context.Context, ref *corev1.Reference, mutator RoleBindingMutator) (*corev1.RoleBinding, error)
	DeleteRoleBinding(context.Context, *corev1.Reference) error
	GetRoleBinding(context.Context, *corev1.Reference) (*corev1.RoleBinding, error)
	ListRoles(context.Context) (*corev1.RoleList, error)
	ListRoleBindings(context.Context) (*corev1.RoleBindingList, error)
}

type RoleBindingMutator added in v0.11.0

type RoleBindingMutator = MutatorFunc[*corev1.RoleBinding]

type RoleMutator added in v0.11.0

type RoleMutator = MutatorFunc[*corev1.Role]

type SelectorPredicate

type SelectorPredicate[T corev1.IdLabelReader] func(T) bool

func NewSelectorPredicate added in v0.6.1

func NewSelectorPredicate[T corev1.IdLabelReader](s *corev1.ClusterSelector) SelectorPredicate[T]

type SubjectAccessCapableStore

type SubjectAccessCapableStore interface {
	ListClusters(ctx context.Context, matchLabels *corev1.LabelSelector, matchOptions corev1.MatchOptions) (*corev1.ClusterList, error)
	GetRole(ctx context.Context, ref *corev1.Reference) (*corev1.Role, error)
	ListRoleBindings(ctx context.Context) (*corev1.RoleBindingList, error)
}

A store that can be used to compute subject access rules

type TokenCreateOption

type TokenCreateOption func(*TokenCreateOptions)

func WithCapabilities

func WithCapabilities(capabilities []*corev1.TokenCapability) TokenCreateOption

func WithLabels

func WithLabels(labels map[string]string) TokenCreateOption

func WithMaxUsages added in v0.10.0

func WithMaxUsages(usages int64) TokenCreateOption

type TokenCreateOptions

type TokenCreateOptions struct {
	Labels       map[string]string
	Capabilities []*corev1.TokenCapability
	MaxUsages    int64
}

func NewTokenCreateOptions

func NewTokenCreateOptions() TokenCreateOptions

func (*TokenCreateOptions) Apply

func (o *TokenCreateOptions) Apply(opts ...TokenCreateOption)

type TokenMutator

type TokenMutator = MutatorFunc[*corev1.BootstrapToken]

type TokenStore

type TokenStore interface {
	CreateToken(ctx context.Context, ttl time.Duration, opts ...TokenCreateOption) (*corev1.BootstrapToken, error)
	DeleteToken(ctx context.Context, ref *corev1.Reference) error
	GetToken(ctx context.Context, ref *corev1.Reference) (*corev1.BootstrapToken, error)
	UpdateToken(ctx context.Context, ref *corev1.Reference, mutator TokenMutator) (*corev1.BootstrapToken, error)
	ListTokens(ctx context.Context) ([]*corev1.BootstrapToken, error)
}

type ValueStoreLocker added in v0.6.0

type ValueStoreLocker[T any] interface {
	ValueStoreT[T]
	sync.Locker
}

func NewValueStoreLocker added in v0.6.0

func NewValueStoreLocker[T any](s ValueStoreT[T], mutex ...sync.Locker) ValueStoreLocker[T]

type ValueStoreT added in v0.6.0

type ValueStoreT[T any] interface {
	Put(ctx context.Context, value T) error
	Get(ctx context.Context) (T, error)
	Delete(ctx context.Context) error
}

func NewValueStore added in v0.6.0

func NewValueStore[T any](base KeyValueStoreT[T], key string) ValueStoreT[T]

type WatchEvent added in v0.6.0

type WatchEvent[T any] struct {
	EventType WatchEventType
	Current   T
	Previous  T
}

type WatchEventType added in v0.6.0

type WatchEventType string
const (
	WatchEventCreate WatchEventType = "PUT"
	WatchEventUpdate WatchEventType = "UPDATE"
	WatchEventDelete WatchEventType = "DELETE"
)

Directories

Path Synopsis
Package etcd implements data storage using etcd.
Package etcd implements data storage using etcd.

Jump to

Keyboard shortcuts

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