provider

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package provider contains the storage provider implementation for Kubernetes.

Package provider contains the storage provider implementation for Kubernetes.

Index

Constants

View Source
const (
	// MeshStorageLabel is the label used to identify all mesh storage secrets.
	MeshStorageLabel = "webmesh.io/storage"
	// BucketLabel is the label used to identify the bucket for a given key.
	BucketLabel = "webmesh.io/storage-bucket"
	// StorageTraceVLevel is the log level for storage trace logs.
	StorageTraceVLevel = 2
)
View Source
const (
	// ConsensusTraceVLevel is the trace level for the consensus package.
	ConsensusTraceVLevel = 2
)
View Source
const (
	// LeaderElectionID is the name of the leader election lease.
	LeaderElectionID = "storage-provider-k8s-leader-election"
)

Variables

This section is empty.

Functions

func HashID added in v0.1.2

func HashID(id string) string

HashNodeID hashed a node ID into a compatible kubernetes object name.

Types

type Consensus

type Consensus struct {
	// contains filtered or unexported fields
}

Consensus is the consensus interface for the storage provider.

func (*Consensus) AddObserver

func (c *Consensus) AddObserver(ctx context.Context, peer types.StoragePeer) error

AddObserver adds an observer to the consensus group.

func (*Consensus) AddVoter

func (c *Consensus) AddVoter(ctx context.Context, peer types.StoragePeer) error

AddVoter adds a voter to the consensus group.

func (*Consensus) DemoteVoter

func (c *Consensus) DemoteVoter(ctx context.Context, peer types.StoragePeer) error

DemoteVoter demotes a voter to an observer.

func (*Consensus) GetLeader

func (c *Consensus) GetLeader(ctx context.Context) (types.StoragePeer, error)

GetLeader returns the leader of the storage group.

func (*Consensus) GetPeer added in v0.0.6

func (c *Consensus) GetPeer(ctx context.Context, id string) (types.StoragePeer, error)

GetPeer returns the peers of the storage group.

func (*Consensus) GetPeers

func (c *Consensus) GetPeers(ctx context.Context) ([]types.StoragePeer, error)

GetPeers returns the peers of the storage group.

func (*Consensus) IsLeader

func (c *Consensus) IsLeader() bool

IsLeader returns true if the node is the leader of the storage group.

func (*Consensus) IsMember

func (c *Consensus) IsMember() bool

IsMember returns true if the node is a member of the storage group.

func (*Consensus) RemovePeer

func (c *Consensus) RemovePeer(ctx context.Context, peer types.StoragePeer, wait bool) error

RemovePeer removes a peer from the consensus group.

func (*Consensus) StepDown added in v0.0.8

func (c *Consensus) StepDown(ctx context.Context) error

StepDown is a no-op for now, but hooks can potentially be given to the caller to perform some action when the node steps down.

type DataItem

type DataItem struct {
	Key    []byte
	Value  []byte
	Expiry time.Time
}

DataItem is a single item of data.

func (DataItem) Marshal

func (d DataItem) Marshal() ([]byte, error)

Marshal marshals the data item.

func (*DataItem) Unmarshal

func (d *DataItem) Unmarshal(data []byte) error

Unmarshal unmarshals the data item.

type Options

type Options struct {
	// NodeID is the ID of the node.
	NodeID string
	// ListenPort is the port the storage API is listening on, if any.
	ListenPort int
	// MetricsPort is the address to bind the metrics endpoint to.
	MetricsPort int
	// ProbePort is the address to bind the health probe endpoint to.
	ProbePort int
	// ShutdownTimeout is the timeout for shutting down the provider.
	ShutdownTimeout time.Duration
	// Namespace is the namespace to use for leader election and storage.
	Namespace string
	// LeaderElectionLeaseDuration is the duration of the leader election lease.
	LeaderElectionLeaseDuration time.Duration
	// LeaderElectionRenewDeadline is the duration of the leader election lease renewal deadline.
	LeaderElectionRenewDeadline time.Duration
	// LeaderElectionRetryPeriod is the duration of the leader election lease retry period.
	LeaderElectionRetryPeriod time.Duration
	// DisableCache disables the cache.
	DisableCache bool
}

Options are the options for configuring the provider.

type Provider

type Provider struct {
	Options
	// contains filtered or unexported fields
}

Provider is the storage provider implementation for Kubernetes.

func New

func New(options Options) (*Provider, error)

New creates a new Provider.

func NewObserverWithConfig added in v0.2.3

func NewObserverWithConfig(cfg *rest.Config, options Options) (*Provider, error)

NewObserverWithConfig creates a new observing storage provider with the given rest config. An observing storage provider can still write to storage depending on the given configuration, but it will not be able to mutate or participate in consensus.

func NewObserverWithManager added in v0.2.3

func NewObserverWithManager(mgr manager.Manager, options Options) (*Provider, error)

NewObserverWithManager creates an observing storage provider with the given manager.

func NewWithManager

func NewWithManager(mgr manager.Manager, options Options) (*Provider, error)

NewWithManager creates a new Provider with the given manager.

func (*Provider) Bootstrap

func (p *Provider) Bootstrap(ctx context.Context) error

Bootstrap should bootstrap the provider for first-time usage.

func (*Provider) Close

func (p *Provider) Close() error

Close closes the provider.

func (*Provider) Consensus

func (p *Provider) Consensus() storage.Consensus

Consensus returns the underlying Consensus instance.

func (*Provider) Datastore added in v0.1.3

func (p *Provider) Datastore() *database.Database

Datastore returns the underlying datastore instance. This is useful for embedding the provider in other components.

func (*Provider) Eventf

func (p *Provider) Eventf(obj runtime.Object, eventType, reason, message string, args ...interface{})

Eventf implements the resource recorder and is used to track changes to the leader election lease.

func (*Provider) ListenPort

func (p *Provider) ListenPort() uint16

ListenPort should return the TCP port that the storage provider is listening on.

func (*Provider) MeshDB

func (p *Provider) MeshDB() storage.MeshDB

MeshDB returns the underlying MeshDB instance. The provider does not need to guarantee consistency on read operations.

func (*Provider) MeshStorage

func (p *Provider) MeshStorage() storage.MeshStorage

MeshStorage returns the underlying MeshStorage instance. The provider does not need to guarantee consistency on read operations.

func (*Provider) Reconcile

func (p *Provider) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile reconciles the given request. This is used to notify subscribers of changes to the given object.

func (*Provider) RunLeaderElection

func (p *Provider) RunLeaderElection(ctx context.Context)

RunLeaderElection runs the leader election loop.

func (*Provider) Start

func (p *Provider) Start(ctx context.Context) error

Start starts the provider.

func (*Provider) StartManaged

func (p *Provider) StartManaged(ctx context.Context) error

StartUnmanaged starts the provider assuming it controls the controller manager.

func (*Provider) StartUnmanaged

func (p *Provider) StartUnmanaged(ctx context.Context) error

StartUnmanaged starts the provider assuming it does not control the controller manager.

func (*Provider) Status

func (p *Provider) Status() *v1.StorageStatus

Status returns the status of the storage provider.

func (*Provider) WaitForCacheSync added in v0.2.13

func (p *Provider) WaitForCacheSync(ctx context.Context) bool

WaitForCacheSync wait for the cache to sync.

type Storage

type Storage struct {
	*Provider
	// contains filtered or unexported fields
}

Storage is the storage interface for the storage provider.

func (*Storage) Delete

func (st *Storage) Delete(ctx context.Context, key []byte) error

Delete removes a key.

func (*Storage) GetValue

func (st *Storage) GetValue(ctx context.Context, key []byte) ([]byte, error)

GetValue returns the value of a key.

func (*Storage) IterPrefix

func (st *Storage) IterPrefix(ctx context.Context, prefix []byte, fn storage.PrefixIterator) error

IterPrefix iterates over all keys with a given prefix. It is important that the iterator not attempt any write operations as this will cause a deadlock. The iteration will stop if the iterator returns an error.

func (*Storage) ListKeys

func (st *Storage) ListKeys(ctx context.Context, prefix []byte) ([][]byte, error)

ListKeys returns all keys with a given prefix.

func (*Storage) PutValue

func (st *Storage) PutValue(ctx context.Context, key, value []byte, ttl time.Duration) error

PutValue sets the value of a key. TTL is optional and can be set to 0.

func (*Storage) Subscribe

func (st *Storage) Subscribe(ctx context.Context, prefix []byte, fn storage.KVSubscribeFunc) (context.CancelFunc, error)

Subscribe will call the given function whenever a key with the given prefix is changed. The returned function can be called to unsubscribe.

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis
Package database implements a MeshDB using Kubernetes custom resources.
Package database implements a MeshDB using Kubernetes custom resources.
Package manager contains the controller-runtime manager.
Package manager contains the controller-runtime manager.

Jump to

Keyboard shortcuts

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