Skip to content

Commit 7f8b478

Browse files
committed
remove unused go-etcd helper
1 parent dda2508 commit 7f8b478

File tree

3 files changed

+11
-81
lines changed

3 files changed

+11
-81
lines changed

pkg/cmd/server/etcd/etcd.go

Lines changed: 9 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ import (
44
"fmt"
55
"net"
66
"net/http"
7-
"net/http/httputil"
87
"time"
98

10-
newetcdclient "github.com/coreos/etcd/client"
11-
etcdclient "github.com/coreos/go-etcd/etcd"
12-
"github.com/golang/glog"
9+
etcdclient "github.com/coreos/etcd/client"
1310
"golang.org/x/net/context"
1411

1512
"k8s.io/kubernetes/pkg/client/restclient"
@@ -22,9 +19,8 @@ import (
2219
// GetAndTestEtcdClient creates an etcd client based on the provided config. It will attempt to
2320
// connect to the etcd server and block until the server responds at least once, or return an
2421
// error if the server never responded.
25-
// TODO: switch this function to use EtcdHelper.
26-
func GetAndTestEtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (*etcdclient.Client, error) {
27-
etcdClient, err := EtcdClient(etcdClientInfo)
22+
func GetAndTestEtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (etcdclient.Client, error) {
23+
etcdClient, err := MakeEtcdClient(etcdClientInfo)
2824
if err != nil {
2925
return nil, err
3026
}
@@ -34,8 +30,8 @@ func GetAndTestEtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (*etcdcli
3430
return etcdClient, nil
3531
}
3632

37-
// EtcdClient creates an etcd client based on the provided config.
38-
func EtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (*etcdclient.Client, error) {
33+
// MakeEtcdClient creates an etcd client based on the provided config.
34+
func MakeEtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (etcdclient.Client, error) {
3935
tlsConfig, err := restclient.TLSConfigFor(&restclient.Config{
4036
TLSClientConfig: restclient.TLSClientConfig{
4137
CertFile: etcdClientInfo.ClientCert.CertFile,
@@ -59,51 +55,20 @@ func EtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (*etcdclient.Client
5955
MaxIdleConnsPerHost: 500,
6056
})
6157

62-
etcdClient := etcdclient.NewClient(etcdClientInfo.URLs)
63-
etcdClient.SetTransport(transport)
64-
etcdClient.CheckRetry = NeverRetryOnFailure
65-
return etcdClient, nil
66-
}
67-
68-
// MakeNewEtcdClient creates an etcd client based on the provided config.
69-
func MakeNewEtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (newetcdclient.Client, error) {
70-
tlsConfig, err := restclient.TLSConfigFor(&restclient.Config{
71-
TLSClientConfig: restclient.TLSClientConfig{
72-
CertFile: etcdClientInfo.ClientCert.CertFile,
73-
KeyFile: etcdClientInfo.ClientCert.KeyFile,
74-
CAFile: etcdClientInfo.CA,
75-
},
76-
})
77-
if err != nil {
78-
return nil, err
79-
}
80-
81-
transport := knet.SetTransportDefaults(&http.Transport{
82-
TLSClientConfig: tlsConfig,
83-
Dial: (&net.Dialer{
84-
// default from http.DefaultTransport
85-
Timeout: 30 * time.Second,
86-
// Lower the keep alive for connections.
87-
KeepAlive: 1 * time.Second,
88-
}).Dial,
89-
// Because watches are very bursty, defends against long delays in watch reconnections.
90-
MaxIdleConnsPerHost: 500,
91-
})
92-
93-
cfg := newetcdclient.Config{
58+
cfg := etcdclient.Config{
9459
Endpoints: etcdClientInfo.URLs,
9560
// TODO: Determine if transport needs optimization
9661
Transport: transport,
9762
}
98-
return newetcdclient.New(cfg)
63+
return etcdclient.New(cfg)
9964
}
10065

10166
// TestEtcdClient verifies a client is functional. It will attempt to
10267
// connect to the etcd server and block until the server responds at least once, or return an
10368
// error if the server never responded.
104-
func TestEtcdClient(etcdClient *etcdclient.Client) error {
69+
func TestEtcdClient(etcdClient etcdclient.Client) error {
10570
for i := 0; ; i++ {
106-
_, err := etcdClient.Get("/", false, false)
71+
_, err := etcdclient.NewKeysAPI(etcdClient).Get(context.Background(), "/", nil)
10772
if err == nil || etcdutil.IsEtcdNotFound(err) {
10873
break
10974
}
@@ -114,36 +79,3 @@ func TestEtcdClient(etcdClient *etcdclient.Client) error {
11479
}
11580
return nil
11681
}
117-
118-
// TestEtcdClient verifies a client is functional. It will attempt to
119-
// connect to the etcd server and block until the server responds at least once, or return an
120-
// error if the server never responded.
121-
func TestNewEtcdClient(etcdClient newetcdclient.Client) error {
122-
for i := 0; ; i++ {
123-
_, err := newetcdclient.NewKeysAPI(etcdClient).Get(context.Background(), "/", nil)
124-
if err == nil || etcdutil.IsEtcdNotFound(err) {
125-
break
126-
}
127-
if i > 100 {
128-
return fmt.Errorf("could not reach etcd: %v", err)
129-
}
130-
time.Sleep(50 * time.Millisecond)
131-
}
132-
return nil
133-
}
134-
135-
// NeverRetryOnFailure is a retry function for the etcdClient. If there's only one machine, master election doesn't make much sense,
136-
// so we don't bother to retry, we simply dump the failure and return the error directly.
137-
func NeverRetryOnFailure(cluster *etcdclient.Cluster, numReqs int, lastResp http.Response, err error) error {
138-
if len(cluster.Machines) > 1 {
139-
return etcdclient.DefaultCheckRetry(cluster, numReqs, lastResp, err)
140-
}
141-
142-
content, err := httputil.DumpResponse(&lastResp, true)
143-
if err != nil {
144-
glog.Errorf("failure dumping response: %v", err)
145-
} else {
146-
glog.Errorf("etcd failure response: %s", string(content))
147-
}
148-
return err
149-
}

pkg/cmd/server/origin/master_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ type MasterConfig struct {
167167
// BuildMasterConfig builds and returns the OpenShift master configuration based on the
168168
// provided options
169169
func BuildMasterConfig(options configapi.MasterConfig) (*MasterConfig, error) {
170-
client, err := etcd.MakeNewEtcdClient(options.EtcdClientInfo)
170+
client, err := etcd.MakeEtcdClient(options.EtcdClientInfo)
171171
if err != nil {
172172
return nil, err
173173
}

pkg/cmd/server/start/start_master.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,8 @@ func StartAPI(oc *origin.MasterConfig, kc *kubernetes.MasterConfig) error {
449449
}
450450

451451
// verify we can connect to etcd with the provided config
452-
if etcdClient, err := etcd.GetAndTestEtcdClient(oc.Options.EtcdClientInfo); err != nil {
452+
if _, err := etcd.GetAndTestEtcdClient(oc.Options.EtcdClientInfo); err != nil {
453453
return err
454-
} else {
455-
etcdClient.Close()
456454
}
457455

458456
// Must start policy caching immediately

0 commit comments

Comments
 (0)