Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locksmithctl/locksmithcl: fix endpoints resilience #11

Merged
merged 1 commit into from
Aug 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions locksmithctl/locksmithctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"crypto/tls"
"crypto/x509"
"errors"
"flag"
"fmt"
"io/ioutil"
Expand All @@ -25,6 +26,7 @@ import (
"os"
"path"
"strings"
"syscall"
"text/tabwriter"
"time"

Expand Down Expand Up @@ -216,25 +218,39 @@ func getClient() (*lock.EtcdLockClient, error) {
transport.TLSClientConfig = tlsconf
}

cfg := client.Config{
Endpoints: globalFlags.Endpoints,
Transport: transport,
Username: globalFlags.EtcdUsername,
Password: globalFlags.EtcdPassword,
}
// This loop is a hack to bring a kind a resilience in case of unreachable endpoint.
// It has been shown in the CI (cl.locksmith.cluster) that etcd/v2 recent upgrade has broke the resiliency
// of the endpoint.
// It can be safely removed once the `etcd` V3 upgrade done.
// More details https://github.com/kinvolk/coreos-overlay/pull/1161#issuecomment-891906580.
for _, ep := range globalFlags.Endpoints {
invidian marked this conversation as resolved.
Show resolved Hide resolved
cfg := client.Config{
Endpoints: []string{ep},
Transport: transport,
Username: globalFlags.EtcdUsername,
Password: globalFlags.EtcdPassword,
}

ec, err := client.New(cfg)
if err != nil {
return nil, err
}
ec, err := client.New(cfg)
if err != nil {
return nil, fmt.Errorf("creating etcd client: %w", err)
}

kapi := client.NewKeysAPI(ec)
kapi := client.NewKeysAPI(ec)

lc, err := lock.NewEtcdLockClient(kapi, globalFlags.Group)
if err != nil {
return nil, err
lc, err := lock.NewEtcdLockClient(kapi, globalFlags.Group)
if err != nil {
if errors.Is(err, syscall.ECONNREFUSED) {
continue
}

return nil, fmt.Errorf("creating etcd lock client: %w", err)
}

return lc, nil
}
return lc, err

return nil, fmt.Errorf("no etcd endpoints available, tried: %s", strings.Join(globalFlags.Endpoints, ","))
}

// flagsFromEnv parses all registered flags in the given flagSet,
Expand Down