Skip to content

Commit 7e060ee

Browse files
authored
Merge pull request kubernetes#81908 from tedyu/etcd-cluster-avail
Remove Client#ClusterAvailable from interface
2 parents 4ce0a30 + 2167321 commit 7e060ee

File tree

6 files changed

+18
-40
lines changed

6 files changed

+18
-40
lines changed

cmd/kubeadm/app/phases/etcd/local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func CheckLocalEtcdClusterStatus(client clientset.Interface, cfg *kubeadmapi.Clu
8282
}
8383

8484
// Checking health state
85-
_, err = etcdClient.GetClusterStatus()
85+
err = etcdClient.CheckClusterHealth()
8686
if err != nil {
8787
return errors.Wrap(err, "etcd cluster is not healthy")
8888
}

cmd/kubeadm/app/phases/upgrade/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ go_test(
9797
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
9898
"//staging/src/k8s.io/client-go/tools/clientcmd:go_default_library",
9999
"//staging/src/k8s.io/client-go/util/cert:go_default_library",
100-
"//vendor/github.com/coreos/etcd/clientv3:go_default_library",
101100
"//vendor/github.com/coreos/etcd/pkg/transport:go_default_library",
102101
"//vendor/github.com/pkg/errors:go_default_library",
103102
],

cmd/kubeadm/app/phases/upgrade/compute_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"testing"
2323
"time"
2424

25-
"github.com/coreos/etcd/clientv3"
2625
"github.com/pkg/errors"
2726
apps "k8s.io/api/apps/v1"
2827
v1 "k8s.io/api/core/v1"
@@ -76,14 +75,12 @@ type fakeEtcdClient struct {
7675
mismatchedVersions bool
7776
}
7877

79-
func (f fakeEtcdClient) ClusterAvailable() (bool, error) { return true, nil }
80-
8178
func (f fakeEtcdClient) WaitForClusterAvailable(retries int, retryInterval time.Duration) (bool, error) {
8279
return true, nil
8380
}
8481

85-
func (f fakeEtcdClient) GetClusterStatus() (map[string]*clientv3.StatusResponse, error) {
86-
return make(map[string]*clientv3.StatusResponse), nil
82+
func (f fakeEtcdClient) CheckClusterHealth() error {
83+
return nil
8784
}
8885

8986
func (f fakeEtcdClient) GetVersion() (string, error) {

cmd/kubeadm/app/phases/upgrade/staticpods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func performEtcdStaticPodUpgrade(certsRenewMgr *renewal.Manager, client clientse
269269
}
270270

271271
// Checking health state of etcd before proceeding with the upgrade
272-
_, err := oldEtcdClient.GetClusterStatus()
272+
err := oldEtcdClient.CheckClusterHealth()
273273
if err != nil {
274274
return true, errors.Wrap(err, "etcd cluster is not healthy")
275275
}

cmd/kubeadm/app/phases/upgrade/staticpods_test.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"testing"
2929
"time"
3030

31-
"github.com/coreos/etcd/clientv3"
3231
"github.com/coreos/etcd/pkg/transport"
3332
"github.com/pkg/errors"
3433

@@ -241,17 +240,12 @@ func (spm *fakeStaticPodPathManager) CleanupDirs() error {
241240

242241
type fakeTLSEtcdClient struct{ TLS bool }
243242

244-
func (c fakeTLSEtcdClient) ClusterAvailable() (bool, error) { return true, nil }
245-
246243
func (c fakeTLSEtcdClient) WaitForClusterAvailable(retries int, retryInterval time.Duration) (bool, error) {
247244
return true, nil
248245
}
249246

250-
func (c fakeTLSEtcdClient) GetClusterStatus() (map[string]*clientv3.StatusResponse, error) {
251-
return map[string]*clientv3.StatusResponse{
252-
"https://1.2.3.4:2379": {
253-
Version: "3.1.12",
254-
}}, nil
247+
func (c fakeTLSEtcdClient) CheckClusterHealth() error {
248+
return nil
255249
}
256250

257251
func (c fakeTLSEtcdClient) GetClusterVersions() (map[string]string, error) {
@@ -280,27 +274,19 @@ func (c fakeTLSEtcdClient) RemoveMember(id uint64) ([]etcdutil.Member, error) {
280274

281275
type fakePodManifestEtcdClient struct{ ManifestDir, CertificatesDir string }
282276

283-
func (c fakePodManifestEtcdClient) ClusterAvailable() (bool, error) { return true, nil }
284-
285277
func (c fakePodManifestEtcdClient) WaitForClusterAvailable(retries int, retryInterval time.Duration) (bool, error) {
286278
return true, nil
287279
}
288280

289-
func (c fakePodManifestEtcdClient) GetClusterStatus() (map[string]*clientv3.StatusResponse, error) {
281+
func (c fakePodManifestEtcdClient) CheckClusterHealth() error {
290282
// Make sure the certificates generated from the upgrade are readable from disk
291283
tlsInfo := transport.TLSInfo{
292284
CertFile: filepath.Join(c.CertificatesDir, constants.EtcdCACertName),
293285
KeyFile: filepath.Join(c.CertificatesDir, constants.EtcdHealthcheckClientCertName),
294286
TrustedCAFile: filepath.Join(c.CertificatesDir, constants.EtcdHealthcheckClientKeyName),
295287
}
296288
_, err := tlsInfo.ClientConfig()
297-
if err != nil {
298-
return nil, err
299-
}
300-
301-
return map[string]*clientv3.StatusResponse{
302-
"https://1.2.3.4:2379": {Version: "3.1.12"},
303-
}, nil
289+
return err
304290
}
305291

306292
func (c fakePodManifestEtcdClient) GetClusterVersions() (map[string]string, error) {

cmd/kubeadm/app/util/etcd/etcd.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ var addRemoveBackoff = wait.Backoff{
4949

5050
// ClusterInterrogator is an interface to get etcd cluster related information
5151
type ClusterInterrogator interface {
52-
ClusterAvailable() (bool, error)
53-
GetClusterStatus() (map[string]*clientv3.StatusResponse, error)
52+
CheckClusterHealth() error
5453
GetClusterVersions() (map[string]string, error)
5554
GetVersion() (string, error)
5655
WaitForClusterAvailable(retries int, retryInterval time.Duration) (bool, error)
@@ -314,7 +313,7 @@ func (c *Client) GetVersion() (string, error) {
314313
// GetClusterVersions returns a map of the endpoints and their associated versions
315314
func (c *Client) GetClusterVersions() (map[string]string, error) {
316315
versions := make(map[string]string)
317-
statuses, err := c.GetClusterStatus()
316+
statuses, err := c.getClusterStatus()
318317
if err != nil {
319318
return versions, err
320319
}
@@ -325,17 +324,14 @@ func (c *Client) GetClusterVersions() (map[string]string, error) {
325324
return versions, nil
326325
}
327326

328-
// ClusterAvailable returns true if the cluster status indicates the cluster is available.
329-
func (c *Client) ClusterAvailable() (bool, error) {
330-
_, err := c.GetClusterStatus()
331-
if err != nil {
332-
return false, err
333-
}
334-
return true, nil
327+
// CheckClusterHealth returns nil for status Up or error for status Down
328+
func (c *Client) CheckClusterHealth() error {
329+
_, err := c.getClusterStatus()
330+
return err
335331
}
336332

337-
// GetClusterStatus returns nil for status Up or error for status Down
338-
func (c *Client) GetClusterStatus() (map[string]*clientv3.StatusResponse, error) {
333+
// getClusterStatus returns nil for status Up (along with endpoint status response map) or error for status Down
334+
func (c *Client) getClusterStatus() (map[string]*clientv3.StatusResponse, error) {
339335
cli, err := clientv3.New(clientv3.Config{
340336
Endpoints: c.Endpoints,
341337
DialTimeout: dialTimeout,
@@ -370,7 +366,7 @@ func (c *Client) WaitForClusterAvailable(retries int, retryInterval time.Duratio
370366
time.Sleep(retryInterval)
371367
}
372368
klog.V(2).Infof("[etcd] attempting to see if all cluster endpoints (%s) are available %d/%d", c.Endpoints, i+1, retries)
373-
resp, err := c.ClusterAvailable()
369+
_, err := c.getClusterStatus()
374370
if err != nil {
375371
switch err {
376372
case context.DeadlineExceeded:
@@ -380,7 +376,7 @@ func (c *Client) WaitForClusterAvailable(retries int, retryInterval time.Duratio
380376
}
381377
continue
382378
}
383-
return resp, nil
379+
return true, nil
384380
}
385381
return false, errors.New("timeout waiting for etcd cluster to be available")
386382
}

0 commit comments

Comments
 (0)