mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Refactor etcd client function have same signatures in etcd.go
This commit is contained in:
parent
139a13d312
commit
a0ee4b471d
@ -149,7 +149,7 @@ type Member struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetMemberID returns the member ID of the given peer URL
|
// GetMemberID returns the member ID of the given peer URL
|
||||||
func (c Client) GetMemberID(peerURL string) (uint64, error) {
|
func (c *Client) GetMemberID(peerURL string) (uint64, error) {
|
||||||
cli, err := clientv3.New(clientv3.Config{
|
cli, err := clientv3.New(clientv3.Config{
|
||||||
Endpoints: c.Endpoints,
|
Endpoints: c.Endpoints,
|
||||||
DialTimeout: 30 * time.Second,
|
DialTimeout: 30 * time.Second,
|
||||||
@ -176,7 +176,7 @@ func (c Client) GetMemberID(peerURL string) (uint64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveMember notifies an etcd cluster to remove an existing member
|
// RemoveMember notifies an etcd cluster to remove an existing member
|
||||||
func (c Client) RemoveMember(id uint64) ([]Member, error) {
|
func (c *Client) RemoveMember(id uint64) ([]Member, error) {
|
||||||
cli, err := clientv3.New(clientv3.Config{
|
cli, err := clientv3.New(clientv3.Config{
|
||||||
Endpoints: c.Endpoints,
|
Endpoints: c.Endpoints,
|
||||||
DialTimeout: 30 * time.Second,
|
DialTimeout: 30 * time.Second,
|
||||||
@ -251,7 +251,7 @@ func (c *Client) AddMember(name string, peerAddrs string) ([]Member, error) {
|
|||||||
|
|
||||||
// GetVersion returns the etcd version of the cluster.
|
// GetVersion returns the etcd version of the cluster.
|
||||||
// An error is returned if the version of all endpoints do not match
|
// An error is returned if the version of all endpoints do not match
|
||||||
func (c Client) GetVersion() (string, error) {
|
func (c *Client) GetVersion() (string, error) {
|
||||||
var clusterVersion string
|
var clusterVersion string
|
||||||
|
|
||||||
versions, err := c.GetClusterVersions()
|
versions, err := c.GetClusterVersions()
|
||||||
@ -271,7 +271,7 @@ func (c Client) GetVersion() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetClusterVersions returns a map of the endpoints and their associated versions
|
// GetClusterVersions returns a map of the endpoints and their associated versions
|
||||||
func (c Client) GetClusterVersions() (map[string]string, error) {
|
func (c *Client) GetClusterVersions() (map[string]string, error) {
|
||||||
versions := make(map[string]string)
|
versions := make(map[string]string)
|
||||||
statuses, err := c.GetClusterStatus()
|
statuses, err := c.GetClusterStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -285,7 +285,7 @@ func (c Client) GetClusterVersions() (map[string]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ClusterAvailable returns true if the cluster status indicates the cluster is available.
|
// ClusterAvailable returns true if the cluster status indicates the cluster is available.
|
||||||
func (c Client) ClusterAvailable() (bool, error) {
|
func (c *Client) ClusterAvailable() (bool, error) {
|
||||||
_, err := c.GetClusterStatus()
|
_, err := c.GetClusterStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@ -294,7 +294,7 @@ func (c Client) ClusterAvailable() (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetClusterStatus returns nil for status Up or error for status Down
|
// GetClusterStatus returns nil for status Up or error for status Down
|
||||||
func (c Client) GetClusterStatus() (map[string]*clientv3.StatusResponse, error) {
|
func (c *Client) GetClusterStatus() (map[string]*clientv3.StatusResponse, error) {
|
||||||
cli, err := clientv3.New(clientv3.Config{
|
cli, err := clientv3.New(clientv3.Config{
|
||||||
Endpoints: c.Endpoints,
|
Endpoints: c.Endpoints,
|
||||||
DialTimeout: 5 * time.Second,
|
DialTimeout: 5 * time.Second,
|
||||||
@ -319,7 +319,7 @@ func (c Client) GetClusterStatus() (map[string]*clientv3.StatusResponse, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WaitForClusterAvailable returns true if all endpoints in the cluster are available after retry attempts, an error is returned otherwise
|
// WaitForClusterAvailable returns true if all endpoints in the cluster are available after retry attempts, an error is returned otherwise
|
||||||
func (c Client) WaitForClusterAvailable(retries int, retryInterval time.Duration) (bool, error) {
|
func (c *Client) WaitForClusterAvailable(retries int, retryInterval time.Duration) (bool, error) {
|
||||||
for i := 0; i < retries; i++ {
|
for i := 0; i < retries; i++ {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
fmt.Printf("[util/etcd] Waiting %v until next retry\n", retryInterval)
|
fmt.Printf("[util/etcd] Waiting %v until next retry\n", retryInterval)
|
||||||
|
Loading…
Reference in New Issue
Block a user