Skip to content

Commit 860103c

Browse files
author
Mathieu Tortuyaux
committed
locksmithctl/locksmithcl: fix endpoints resilience
with the recent etcd upgrade (1b5eb50), the endpoints resilience were not ensured -> having failing endpoints would make the `locksmithcl` commands fail. in this commit, we patch the software (and not the vendor), to reproduce a kind of resilience: we loop over the endpoints - if one of them is not reachable we continue to the over. this patch can be reverted once the upgrade to etcd/v3 will be done. Signed-off-by: Mathieu Tortuyaux <mathieu@kinvolk.io>
1 parent c96ae6e commit 860103c

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

locksmithctl/locksmithctl.go

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package main
1717
import (
1818
"crypto/tls"
1919
"crypto/x509"
20+
"errors"
2021
"flag"
2122
"fmt"
2223
"io/ioutil"
@@ -25,6 +26,7 @@ import (
2526
"os"
2627
"path"
2728
"strings"
29+
"syscall"
2830
"text/tabwriter"
2931
"time"
3032

@@ -216,25 +218,39 @@ func getClient() (*lock.EtcdLockClient, error) {
216218
transport.TLSClientConfig = tlsconf
217219
}
218220

219-
cfg := client.Config{
220-
Endpoints: globalFlags.Endpoints,
221-
Transport: transport,
222-
Username: globalFlags.EtcdUsername,
223-
Password: globalFlags.EtcdPassword,
224-
}
221+
// This loop is a hack to bring a kind a resilience in case of unreachable endpoint.
222+
// It has been shown in the CI (cl.locksmith.cluster) that etcd/v2 recent upgrade has broke the resiliency
223+
// of the endpoint.
224+
// It can be safely removed once the `etcd` V3 upgrade done.
225+
// More details https://github.com/kinvolk/coreos-overlay/pull/1161#issuecomment-891906580.
226+
for _, ep := range globalFlags.Endpoints {
227+
cfg := client.Config{
228+
Endpoints: []string{ep},
229+
Transport: transport,
230+
Username: globalFlags.EtcdUsername,
231+
Password: globalFlags.EtcdPassword,
232+
}
225233

226-
ec, err := client.New(cfg)
227-
if err != nil {
228-
return nil, err
229-
}
234+
ec, err := client.New(cfg)
235+
if err != nil {
236+
return nil, fmt.Errorf("creating etcd client: %w", err)
237+
}
230238

231-
kapi := client.NewKeysAPI(ec)
239+
kapi := client.NewKeysAPI(ec)
232240

233-
lc, err := lock.NewEtcdLockClient(kapi, globalFlags.Group)
234-
if err != nil {
235-
return nil, err
241+
lc, err := lock.NewEtcdLockClient(kapi, globalFlags.Group)
242+
if err != nil {
243+
if errors.Is(err, syscall.ECONNREFUSED) {
244+
continue
245+
}
246+
247+
return nil, fmt.Errorf("creating etcd lock client: %w", err)
248+
}
249+
250+
return lc, nil
236251
}
237-
return lc, err
252+
253+
return nil, fmt.Errorf("no etcd endpoints available, tried: %s", strings.Join(globalFlags.Endpoints, ","))
238254
}
239255

240256
// flagsFromEnv parses all registered flags in the given flagSet,

0 commit comments

Comments
 (0)