Skip to content

Commit 2167321

Browse files
tedyuyutedz
authored andcommitted
Remove Client#ClusterAvailable from interface
1 parent 518ff2a commit 2167321

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
@@ -48,8 +48,7 @@ var addRemoveBackoff = wait.Backoff{
4848

4949
// ClusterInterrogator is an interface to get etcd cluster related information
5050
type ClusterInterrogator interface {
51-
ClusterAvailable() (bool, error)
52-
GetClusterStatus() (map[string]*clientv3.StatusResponse, error)
51+
CheckClusterHealth() error
5352
GetClusterVersions() (map[string]string, error)
5453
GetVersion() (string, error)
5554
WaitForClusterAvailable(retries int, retryInterval time.Duration) (bool, error)
@@ -296,7 +295,7 @@ func (c *Client) GetVersion() (string, error) {
296295
// GetClusterVersions returns a map of the endpoints and their associated versions
297296
func (c *Client) GetClusterVersions() (map[string]string, error) {
298297
versions := make(map[string]string)
299-
statuses, err := c.GetClusterStatus()
298+
statuses, err := c.getClusterStatus()
300299
if err != nil {
301300
return versions, err
302301
}
@@ -307,17 +306,14 @@ func (c *Client) GetClusterVersions() (map[string]string, error) {
307306
return versions, nil
308307
}
309308

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
317313
}
318314

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) {
321317
cli, err := clientv3.New(clientv3.Config{
322318
Endpoints: c.Endpoints,
323319
DialTimeout: 5 * time.Second,
@@ -349,7 +345,7 @@ func (c *Client) WaitForClusterAvailable(retries int, retryInterval time.Duratio
349345
time.Sleep(retryInterval)
350346
}
351347
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()
353349
if err != nil {
354350
switch err {
355351
case context.DeadlineExceeded:
@@ -359,7 +355,7 @@ func (c *Client) WaitForClusterAvailable(retries int, retryInterval time.Duratio
359355
}
360356
continue
361357
}
362-
return resp, nil
358+
return true, nil
363359
}
364360
return false, errors.New("timeout waiting for etcd cluster to be available")
365361
}

0 commit comments

Comments
 (0)