Documentation
¶
Index ¶
- Constants
- func GetEndpoints(ctx context.Context, resources state.State) ([]string, error)
- func GetLocalMemberID(ctx context.Context, s state.State) (uint64, error)
- func WithLock(ctx context.Context, key string, logger *zap.Logger, f func() error) error
- type CertificateGenerator
- func (gen *CertificateGenerator) GenerateClientCert(commonName string) (*x509.PEMEncodedCertificateAndKey, error)
- func (gen *CertificateGenerator) GeneratePeerCert() (*x509.PEMEncodedCertificateAndKey, error)
- func (gen *CertificateGenerator) GenerateServerCert() (*x509.PEMEncodedCertificateAndKey, error)
- type Client
- func NewClient(ctx context.Context, endpoints []string, dialOpts ...grpc.DialOption) (client *Client, err error)
- func NewClientFromControlPlaneIPs(ctx context.Context, resources state.State, dialOpts ...grpc.DialOption) (client *Client, err error)
- func NewLocalClient(ctx context.Context, dialOpts ...grpc.DialOption) (client *Client, err error)
- func (c *Client) ForfeitLeadership(ctx context.Context, memberID string) (string, error)
- func (c *Client) GetMemberID(ctx context.Context) (uint64, error)
- func (c *Client) LeaveCluster(ctx context.Context, st state.State) error
- func (c *Client) PromoteMember(ctx context.Context, memberID uint64) error
- func (c *Client) RemoveMemberByMemberID(ctx context.Context, memberID uint64) error
- func (c *Client) RevokeSession(ctx context.Context, session *concurrency.Session) error
- func (c *Client) ValidateForUpgrade(ctx context.Context, config config.Config) error
- func (c *Client) ValidateQuorum(ctx context.Context) (err error)
Constants ¶
const CleanupTimeout = 10 * time.Second
CleanupTimeout bounds the best-effort cleanup RPCs issued when an etcd lock is released or an election campaign is torn down.
The cleanup runs on a context detached from the caller's one, as the caller's context is usually already canceled at that point (that is what aborted the lock or the campaign), but it must never block indefinitely: on machine shutdown the local etcd is stopped before the controller runtime is torn down, so the cleanup RPCs have no chance to ever complete.
const QuorumCheckTimeout = 15 * time.Second
QuorumCheckTimeout is the amount of time to allow for KV operations before quorum is declared invalid.
Variables ¶
This section is empty.
Functions ¶
func GetEndpoints ¶
GetEndpoints returns expected endpoints of etcd cluster members.
It is not guaranteed that etcd is running on each listed endpoint.
func GetLocalMemberID ¶
GetLocalMemberID gets the etcd member id of the local node via resources.
Types ¶
type CertificateGenerator ¶
type CertificateGenerator struct {
CA *x509.PEMEncodedCertificateAndKey
NodeAddresses *network.NodeAddress
HostnameStatus *network.HostnameStatus
}
CertificateGenerator contains etcd certificate options.
func (*CertificateGenerator) GenerateClientCert ¶
func (gen *CertificateGenerator) GenerateClientCert(commonName string) (*x509.PEMEncodedCertificateAndKey, error)
GenerateClientCert generates client certificate and key from etcd CA.
func (*CertificateGenerator) GeneratePeerCert ¶
func (gen *CertificateGenerator) GeneratePeerCert() (*x509.PEMEncodedCertificateAndKey, error)
GeneratePeerCert generates etcd peer certificate and key from etcd CA.
func (*CertificateGenerator) GenerateServerCert ¶
func (gen *CertificateGenerator) GenerateServerCert() (*x509.PEMEncodedCertificateAndKey, error)
GenerateServerCert generates server etcd certificate and key from etcd CA.
type Client ¶
Client is a wrapper around the official etcd client.
func NewClient ¶
func NewClient(ctx context.Context, endpoints []string, dialOpts ...grpc.DialOption) (client *Client, err error)
NewClient initializes and returns an etcd client configured to talk to a list of endpoints.
func NewClientFromControlPlaneIPs ¶
func NewClientFromControlPlaneIPs(ctx context.Context, resources state.State, dialOpts ...grpc.DialOption) (client *Client, err error)
NewClientFromControlPlaneIPs initializes and returns an etcd client configured to talk to all members.
func NewLocalClient ¶
NewLocalClient initializes and returns etcd client configured to talk to localhost endpoint.
func (*Client) ForfeitLeadership ¶
ForfeitLeadership transfers leadership from the current member to another member.
func (*Client) GetMemberID ¶
GetMemberID returns the member ID of the node client is connected to.
func (*Client) LeaveCluster ¶
LeaveCluster removes the current member from the etcd cluster and nukes etcd data directory.
nolint:gocyclo
func (*Client) PromoteMember ¶ added in v1.13.10
PromoteMember promotes a learner member to a voting member.
It is a fail-fast version of clientv3's MemberPromote: clientv3 hardcodes grpc.WaitForReady(true) in its default call options (and provides no way to override it via clientv3.Config), which makes a call against an endpoint which is not accepting connections block until the context deadline instead of returning the connection error. As the promotion call has to find a voting member to talk to, blocking on a dead endpoint is exactly the wrong behavior.
func (*Client) RemoveMemberByMemberID ¶
RemoveMemberByMemberID removes the member from the etcd cluster.
func (*Client) RevokeSession ¶ added in v1.12.11
RevokeSession stops refreshing the session lease and revokes it on a context detached from ctx.
This is what `concurrency.Session.Close` does, but with a context under our control: `Session.Close` revokes the lease on the session context, which defaults to the etcd client context, so it fails instantly once that context is canceled, and otherwise blocks for the whole session TTL (60s) when etcd is unreachable. Neither is useful: the point of the revoke is to run exactly when the caller is going away.
Revoking the lease drops every key attached to it, which for the `concurrency` package means the mutex and election keys of this session. Both are FIFO queues ordered by create revision, so a key left behind by a participant which is already gone blocks everybody queued behind it until the lease expires on its own.
func (*Client) ValidateForUpgrade ¶
ValidateForUpgrade validates the etcd cluster state to ensure that performing an upgrade is safe.