etcdcli

package
v0.0.0-alpha.0....-eeef803 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BootstrapIPAnnotationKey = "alpha.installer.openshift.io/etcd-bootstrap"
	DefaultDialTimeout       = 15 * time.Second
	DefragDialTimeout        = 60 * time.Second
	DefaultClientTimeout     = 30 * time.Second
)
View Source
const (
	EtcdMemberStatusAvailable  = "EtcdMemberAvailable"
	EtcdMemberStatusNotStarted = "EtcdMemberNotStarted"
	EtcdMemberStatusUnhealthy  = "EtcdMemberUnhealthy"
	EtcdMemberStatusUnknown    = "EtcdMemberUnknown"
)

Variables

This section is empty.

Functions

func GetHealthyMemberNames

func GetHealthyMemberNames(memberHealth []healthCheck) []string

GetHealthyMemberNames returns a list of healthy member names

func GetMemberHealth

func GetMemberHealth(ctx context.Context, etcdMembers []*etcdserverpb.Member) memberHealth

func GetMemberNameOrHost

func GetMemberNameOrHost(member *etcdserverpb.Member) string

GetMemberNameOrHost If the member's name is not set, extract ip/hostname from peerURL. Useful with unstarted members.

func GetUnhealthyMemberNames

func GetUnhealthyMemberNames(memberHealth []healthCheck) []string

GetUnhealthyMemberNames returns a list of unhealthy member names

func GetUnstartedMemberNames

func GetUnstartedMemberNames(memberHealth []healthCheck) []string

GetUnstartedMemberNames returns a list of unstarted member names

func HasStarted

func HasStarted(member *etcdserverpb.Member) bool

HasStarted return true if etcd member has started.

func IsClusterHealthy

func IsClusterHealthy(memberHealth memberHealth) bool

func IsQuorumFaultTolerant

func IsQuorumFaultTolerant(memberHealth []healthCheck) bool

IsQuorumFaultTolerant checks the current etcd cluster and returns true if the cluster can tolerate the loss of a single etcd member. Such loss is common during new static pod revision.

func IsQuorumFaultTolerantErr

func IsQuorumFaultTolerantErr(memberHealth []healthCheck) error

IsQuorumFaultTolerantErr is the same as IsQuorumFaultTolerant but with an error return instead of the log

func MinimumTolerableQuorum

func MinimumTolerableQuorum(members int) (int, error)

Types

type AllMemberLister

func NewMemberCache

func NewMemberCache(client EtcdClient) AllMemberLister

type CachedMembers

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

func (*CachedMembers) HealthyMembers

func (c *CachedMembers) HealthyMembers(ctx context.Context) ([]*etcdserverpb.Member, error)

func (*CachedMembers) HealthyVotingMembers

func (c *CachedMembers) HealthyVotingMembers(ctx context.Context) ([]*etcdserverpb.Member, error)

func (*CachedMembers) MemberHealth

func (c *CachedMembers) MemberHealth(ctx context.Context) (memberHealth, error)

func (*CachedMembers) MemberList

func (c *CachedMembers) MemberList(ctx context.Context) ([]*etcdserverpb.Member, error)

func (*CachedMembers) UnhealthyMembers

func (c *CachedMembers) UnhealthyMembers(ctx context.Context) ([]*etcdserverpb.Member, error)

func (*CachedMembers) UnhealthyVotingMembers

func (c *CachedMembers) UnhealthyVotingMembers(ctx context.Context) ([]*etcdserverpb.Member, error)

func (*CachedMembers) VotingMemberList

func (c *CachedMembers) VotingMemberList(ctx context.Context) ([]*etcdserverpb.Member, error)

type ClientOption

type ClientOption func(*ClientOptions)

func WithDialTimeout

func WithDialTimeout(timeout time.Duration) ClientOption

type ClientOptions

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

type Defragment

type Defragment interface {
	Defragment(ctx context.Context, member *etcdserverpb.Member) (*clientv3.DefragmentResponse, error)
}

type EtcdClientPool

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

EtcdClientPool fulfills these requirements: * cache clients to avoid re-creating them all the time (TLS handshakes are expensive after all) * return an exclusively unused client, no other can acquire the same client at that time * health checking a client before using it (using list), return a new one if unhealthy and closing the old one * update endpoints, to be always up to date with the changes * return a used client to the pool, making it available to consume again

func NewDefaultEtcdClientPool

func NewDefaultEtcdClientPool(newFunc func() (*clientv3.Client, error), endpointsFunc func() ([]string, error)) *EtcdClientPool

func NewEtcdClientPool

func NewEtcdClientPool(
	newFunc func() (*clientv3.Client, error),
	endpointsFunc func() ([]string, error),
	healthFunc func(*clientv3.Client) error,
	closeFunc func(*clientv3.Client) error) *EtcdClientPool

func (*EtcdClientPool) Get

func (p *EtcdClientPool) Get() (*clientv3.Client, error)

Get returns a client that can be used exclusively by the caller, the caller must not close the client but return it using Return. This is intentionally not a fast operation, Get will ensure the client returned will be healthy and retries on errors. If no client is available, this method will block intentionally to protect etcd from being overwhelmed by too many clients at once.

func (*EtcdClientPool) Return

func (p *EtcdClientPool) Return(client *clientv3.Client)

Return will make the given client available for other callers through Get again. When the underlying pool is filled it will close the client instead of waiting for a free spot.

type FakeClientOption

type FakeClientOption func(*FakeClientOptions)

func WithFakeClusterHealth

func WithFakeClusterHealth(members *FakeMemberHealth) FakeClientOption

func WithFakeDefragErrors

func WithFakeDefragErrors(errors []error) FakeClientOption

WithFakeDefragErrors configures each call to Defrag to consume one error from the given slice

func WithFakeStatus

func WithFakeStatus(status []*clientv3.StatusResponse) FakeClientOption

type FakeClientOptions

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

type FakeMemberHealth

type FakeMemberHealth struct {
	Healthy   int
	Unhealthy int
}

type HealthyMemberLister

type HealthyMemberLister interface {
	// HealthyMembers lists all healthy members in a cluster
	HealthyMembers(ctx context.Context) ([]*etcdserverpb.Member, error)
	// HealthyVotingMembers lists all non learner healthy members in a cluster
	HealthyVotingMembers(ctx context.Context) ([]*etcdserverpb.Member, error)
}

type IsMemberHealthy

type IsMemberHealthy interface {
	IsMemberHealthy(ctx context.Context, member *etcdserverpb.Member) (bool, error)
}

type MemberAdder

type MemberAdder interface {
	MemberAddAsLearner(ctx context.Context, peerURL string) error
}

type MemberHealth

type MemberHealth interface {
	MemberHealth(ctx context.Context) (memberHealth, error)
}

type MemberLister

type MemberLister interface {
	// MemberList lists all members in a cluster
	MemberList(ctx context.Context) ([]*etcdserverpb.Member, error)
	// VotingMemberList lists all non learner members in a cluster
	VotingMemberList(ctx context.Context) ([]*etcdserverpb.Member, error)
}

type MemberPromoter

type MemberPromoter interface {
	MemberPromote(ctx context.Context, member *etcdserverpb.Member) error
}

type MemberRemover

type MemberRemover interface {
	MemberRemove(ctx context.Context, memberID uint64) error
}

type MemberStatusChecker

type MemberStatusChecker interface {
	MemberStatus(ctx context.Context, member *etcdserverpb.Member) string
}

type Status

type Status interface {
	Status(ctx context.Context, target string) (*clientv3.StatusResponse, error)
}

type UnhealthyMemberLister

type UnhealthyMemberLister interface {
	// UnhealthyMembers lists all unhealthy members in a cluster
	UnhealthyMembers(ctx context.Context) ([]*etcdserverpb.Member, error)
	// UnhealthyVotingMembers lists all non learner unhealthy members in a cluster
	UnhealthyVotingMembers(ctx context.Context) ([]*etcdserverpb.Member, error)
}

Jump to

Keyboard shortcuts

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