@@ -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
- 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"
13
10
"golang.org/x/net/context"
14
11
15
12
"k8s.io/kubernetes/pkg/client/restclient"
@@ -22,9 +19,8 @@ import (
22
19
// GetAndTestEtcdClient creates an etcd client based on the provided config. It will attempt to
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
- // 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 )
28
24
if err != nil {
29
25
return nil , err
30
26
}
@@ -34,8 +30,8 @@ func GetAndTestEtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (*etcdcli
34
30
return etcdClient , nil
35
31
}
36
32
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 ) {
39
35
tlsConfig , err := restclient .TLSConfigFor (& restclient.Config {
40
36
TLSClientConfig : restclient.TLSClientConfig {
41
37
CertFile : etcdClientInfo .ClientCert .CertFile ,
@@ -59,51 +55,20 @@ func EtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (*etcdclient.Client
59
55
MaxIdleConnsPerHost : 500 ,
60
56
})
61
57
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 {
94
59
Endpoints : etcdClientInfo .URLs ,
95
60
// TODO: Determine if transport needs optimization
96
61
Transport : transport ,
97
62
}
98
- return newetcdclient .New (cfg )
63
+ return etcdclient .New (cfg )
99
64
}
100
65
101
66
// TestEtcdClient verifies a client is functional. It will attempt to
102
67
// connect to the etcd server and block until the server responds at least once, or return an
103
68
// error if the server never responded.
104
- func TestEtcdClient (etcdClient * etcdclient.Client ) error {
69
+ func TestEtcdClient (etcdClient etcdclient.Client ) error {
105
70
for i := 0 ; ; i ++ {
106
- _ , err := etcdClient .Get ("/" , false , false )
71
+ _ , err := etcdclient . NewKeysAPI ( etcdClient ) .Get (context . Background (), "/" , nil )
107
72
if err == nil || etcdutil .IsEtcdNotFound (err ) {
108
73
break
109
74
}
@@ -114,36 +79,3 @@ func TestEtcdClient(etcdClient *etcdclient.Client) error {
114
79
}
115
80
return nil
116
81
}
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
- }
0 commit comments