@@ -4,12 +4,9 @@ import (
4
4
"fmt"
5
5
"net"
6
6
"net/http"
7
- "net/http/httputil"
8
7
"time"
9
8
10
9
newetcdclient "github.com/coreos/etcd/client"
11
- etcdclient "github.com/coreos/go-etcd/etcd"
12
- "github.com/golang/glog"
13
10
"golang.org/x/net/context"
14
11
15
12
"k8s.io/kubernetes/pkg/client/restclient"
@@ -23,48 +20,17 @@ import (
23
20
// connect to the etcd server and block until the server responds at least once, or return an
24
21
// error if the server never responded.
25
22
// TODO: switch this function to use EtcdHelper.
26
- func GetAndTestEtcdClient (etcdClientInfo configapi.EtcdConnectionInfo ) (* etcdclient .Client , error ) {
27
- etcdClient , err := EtcdClient (etcdClientInfo )
23
+ func GetAndTestEtcdClient (etcdClientInfo configapi.EtcdConnectionInfo ) (newetcdclient .Client , error ) {
24
+ etcdClient , err := MakeNewEtcdClient (etcdClientInfo )
28
25
if err != nil {
29
26
return nil , err
30
27
}
31
- if err := TestEtcdClient (etcdClient ); err != nil {
28
+ if err := TestNewEtcdClient (etcdClient ); err != nil {
32
29
return nil , err
33
30
}
34
31
return etcdClient , nil
35
32
}
36
33
37
- // EtcdClient creates an etcd client based on the provided config.
38
- func EtcdClient (etcdClientInfo configapi.EtcdConnectionInfo ) (* etcdclient.Client , error ) {
39
- tlsConfig , err := restclient .TLSConfigFor (& restclient.Config {
40
- TLSClientConfig : restclient.TLSClientConfig {
41
- CertFile : etcdClientInfo .ClientCert .CertFile ,
42
- KeyFile : etcdClientInfo .ClientCert .KeyFile ,
43
- CAFile : etcdClientInfo .CA ,
44
- },
45
- })
46
- if err != nil {
47
- return nil , err
48
- }
49
-
50
- transport := knet .SetTransportDefaults (& http.Transport {
51
- TLSClientConfig : tlsConfig ,
52
- Dial : (& net.Dialer {
53
- // default from http.DefaultTransport
54
- Timeout : 30 * time .Second ,
55
- // Lower the keep alive for connections.
56
- KeepAlive : 1 * time .Second ,
57
- }).Dial ,
58
- // Because watches are very bursty, defends against long delays in watch reconnections.
59
- MaxIdleConnsPerHost : 500 ,
60
- })
61
-
62
- etcdClient := etcdclient .NewClient (etcdClientInfo .URLs )
63
- etcdClient .SetTransport (transport )
64
- etcdClient .CheckRetry = NeverRetryOnFailure
65
- return etcdClient , nil
66
- }
67
-
68
34
// MakeNewEtcdClient creates an etcd client based on the provided config.
69
35
func MakeNewEtcdClient (etcdClientInfo configapi.EtcdConnectionInfo ) (newetcdclient.Client , error ) {
70
36
tlsConfig , err := restclient .TLSConfigFor (& restclient.Config {
@@ -98,23 +64,6 @@ func MakeNewEtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (newetcdclie
98
64
return newetcdclient .New (cfg )
99
65
}
100
66
101
- // TestEtcdClient verifies a client is functional. It will attempt to
102
- // connect to the etcd server and block until the server responds at least once, or return an
103
- // error if the server never responded.
104
- func TestEtcdClient (etcdClient * etcdclient.Client ) error {
105
- for i := 0 ; ; i ++ {
106
- _ , err := etcdClient .Get ("/" , false , false )
107
- if err == nil || etcdutil .IsEtcdNotFound (err ) {
108
- break
109
- }
110
- if i > 100 {
111
- return fmt .Errorf ("could not reach etcd: %v" , err )
112
- }
113
- time .Sleep (50 * time .Millisecond )
114
- }
115
- return nil
116
- }
117
-
118
67
// TestEtcdClient verifies a client is functional. It will attempt to
119
68
// connect to the etcd server and block until the server responds at least once, or return an
120
69
// error if the server never responded.
@@ -131,19 +80,3 @@ func TestNewEtcdClient(etcdClient newetcdclient.Client) error {
131
80
}
132
81
return nil
133
82
}
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
- }
0 commit comments