@@ -48,8 +48,7 @@ var addRemoveBackoff = wait.Backoff{
48
48
49
49
// ClusterInterrogator is an interface to get etcd cluster related information
50
50
type ClusterInterrogator interface {
51
- ClusterAvailable () (bool , error )
52
- GetClusterStatus () (map [string ]* clientv3.StatusResponse , error )
51
+ CheckClusterHealth () error
53
52
GetClusterVersions () (map [string ]string , error )
54
53
GetVersion () (string , error )
55
54
WaitForClusterAvailable (retries int , retryInterval time.Duration ) (bool , error )
@@ -296,7 +295,7 @@ func (c *Client) GetVersion() (string, error) {
296
295
// GetClusterVersions returns a map of the endpoints and their associated versions
297
296
func (c * Client ) GetClusterVersions () (map [string ]string , error ) {
298
297
versions := make (map [string ]string )
299
- statuses , err := c .GetClusterStatus ()
298
+ statuses , err := c .getClusterStatus ()
300
299
if err != nil {
301
300
return versions , err
302
301
}
@@ -307,17 +306,14 @@ func (c *Client) GetClusterVersions() (map[string]string, error) {
307
306
return versions , nil
308
307
}
309
308
310
- // ClusterAvailable returns true if the cluster status indicates the cluster is available.
311
- func (c * Client ) ClusterAvailable () (bool , error ) {
312
- _ , err := c .GetClusterStatus ()
313
- if err != nil {
314
- return false , err
315
- }
316
- return true , nil
309
+ // CheckClusterHealth returns nil for status Up or error for status Down
310
+ func (c * Client ) CheckClusterHealth () error {
311
+ _ , err := c .getClusterStatus ()
312
+ return err
317
313
}
318
314
319
- // GetClusterStatus returns nil for status Up or error for status Down
320
- func (c * Client ) GetClusterStatus () (map [string ]* clientv3.StatusResponse , error ) {
315
+ // getClusterStatus returns nil for status Up (along with endpoint status response map) or error for status Down
316
+ func (c * Client ) getClusterStatus () (map [string ]* clientv3.StatusResponse , error ) {
321
317
cli , err := clientv3 .New (clientv3.Config {
322
318
Endpoints : c .Endpoints ,
323
319
DialTimeout : 5 * time .Second ,
@@ -349,7 +345,7 @@ func (c *Client) WaitForClusterAvailable(retries int, retryInterval time.Duratio
349
345
time .Sleep (retryInterval )
350
346
}
351
347
klog .V (2 ).Infof ("[etcd] attempting to see if all cluster endpoints (%s) are available %d/%d" , c .Endpoints , i + 1 , retries )
352
- resp , err := c .ClusterAvailable ()
348
+ _ , err := c .getClusterStatus ()
353
349
if err != nil {
354
350
switch err {
355
351
case context .DeadlineExceeded :
@@ -359,7 +355,7 @@ func (c *Client) WaitForClusterAvailable(retries int, retryInterval time.Duratio
359
355
}
360
356
continue
361
357
}
362
- return resp , nil
358
+ return true , nil
363
359
}
364
360
return false , errors .New ("timeout waiting for etcd cluster to be available" )
365
361
}
0 commit comments