embetcd

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: Apache-2.0 Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// EtcdClusterNamespace is the key namespace used for this package's etcd cluster
	EtcdClusterNamespace = "__etcd-cluster__/"
	// DefaultUnhealthyTTL is the grace period to wait before removing an unhealthy member
	DefaultUnhealthyTTL = time.Second * 15
	// DefaultCleanUpInterval is the interval at which to poll for the health of the cluster
	DefaultCleanUpInterval = time.Second * 10
	// DefaultStartUpGracePeriod is the graceperiod to wait for new cluster members to startup
	// before they're subject to health checks
	DefaultStartUpGracePeriod = time.Second * 60
	// DefaultShutdownTimeout is the default time to wait for the server to shutdown cleanly
	DefaultShutdownTimeout = time.Second * 60
	// DefaultDialTimeout is the default etcd dial timeout
	DefaultDialTimeout = time.Second * 5
	// DefaultAutoSyncInterval is the default etcd autosync interval
	DefaultAutoSyncInterval = time.Second * 5
)

Variables

View Source
var (
	// ErrNameConflict is an error indicating that the server name is in conflict with an existing member of the cluster
	ErrNameConflict = fmt.Errorf("server name is in conflict with an existing cluster member")
	// ErrAlreadyRunning is an error indicating that the server is already running
	ErrAlreadyRunning = fmt.Errorf("server is already running")
	// ErrAlreadyStopped is an error indicating that the server is already stopped
	ErrAlreadyStopped = fmt.Errorf("server is already stopped")
	// ErrClusterNameConflict is an error indicating that the configured cluster name conflicts with the target cluster
	ErrClusterNameConflict = fmt.Errorf("cluster name either does not exist in the cluster under '/_etcd-cluster/name' or is different from this server's cluster name")
)

Functions

func CancelContext

func CancelContext(cancel context.CancelFunc)

CancelContext is a helper function for canceling context using the context.CancelFunc if it isn't nil

func CloseClient

func CloseClient(client *Client)

CloseClient closes an embetcd client with nil checks

func CloseServer

func CloseServer(s *Server)

CloseServer closes an embetcd server with nil checks

func DurationOrDefault

func DurationOrDefault(in *time.Duration, def time.Duration) time.Duration

DurationOrDefault returns the pointed duration or the specified default

func RevokeLease

func RevokeLease(ctx context.Context, client *Client, lease *cli.LeaseGrantResponse)

RevokeLease revokes a lease using a client as long as the client and lease are not nil

func StringIsInStringSlice

func StringIsInStringSlice(s string, strs []string) (resp bool)

StringIsInStringSlice returns true if the given string is in the slice of strings

func URLSToStringSlice

func URLSToStringSlice(urls []url.URL) []string

URLSToStringSlice converts urls slices to string slices

func WaitForStructChOrErrCh

func WaitForStructChOrErrCh(ctx context.Context, structCh <-chan struct{}, errCh <-chan error) error

WaitForStructChOrErrCh waits for the struct channel, error channel or context to return a value

Types

type Client

type Client struct {
	*cli.Client
}

Client wraps around an etcd v3 client and adds some helper functions

func NewClient

func NewClient(cfg cli.Config) (client *Client, err error)

NewClient returns a new etcd v3client wrapped with some helper functions

func (*Client) PutWithKeepAlive

func (c *Client) PutWithKeepAlive(ctx context.Context, key string, value string, ttl int64) (lease *cli.LeaseGrantResponse, keepAlive <-chan *cli.LeaseKeepAliveResponse, cancel context.CancelFunc, err error)

PutWithKeepAlive puts a key and value with a keep alive returns a lease, the keep alive response channel, and an err if one occurrs

type Config

type Config struct {
	*embed.Config
	ClusterName         string
	InitialCluster      []string
	CleanUpInterval     *time.Duration
	DialTimeout         *time.Duration
	AutoSyncInterval    *time.Duration
	StartupGracePeriod  *time.Duration
	UnhealthyTTL        *time.Duration
	RemoveMemberTimeout *time.Duration
}

Config is a struct representing etcd config plus additional configurations we need for running etcd with this project

func NewConfig

func NewConfig() *Config

NewConfig returns a new config object with defaults provided by etcd embed

func (*Config) GetClientFromConfig

func (c *Config) GetClientFromConfig(ctx context.Context) (*Client, error)

GetClientFromConfig returns a client with the supplied context from the config

type Server

type Server struct {
	// the currently running etcd server
	*embed.Etcd
	// contains filtered or unexported fields
}

Server manages an etcd embedded server

func New

func New() *Server

New returns a new etcd Server

func (*Server) IsRunning

func (s *Server) IsRunning() bool

IsRunning indicates whether the server has been stopped or not and is thread safe

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) (err error)

Shutdown shuts down the server with a cancelable context

func (*Server) Start

func (s *Server) Start(ctx context.Context, cfg *Config) (err error)

Start starts the server with the given config

Jump to

Keyboard shortcuts

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