Skip to content

Commit

Permalink
stop etcd from retrying failures
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Jan 5, 2016
1 parent 99c6de7 commit f785f05
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/cmd/server/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net"
"net/http"
"net/http/httputil"
"time"

etcdclient "github.com/coreos/go-etcd/etcd"
Expand Down Expand Up @@ -114,6 +115,7 @@ func EtcdClient(etcdClientInfo configapi.EtcdConnectionInfo) (*etcdclient.Client

etcdClient := etcdclient.NewClient(etcdClientInfo.URLs)
etcdClient.SetTransport(transport)
etcdClient.CheckRetry = NeverRetryOnFailure
return etcdClient, nil
}

Expand All @@ -133,3 +135,19 @@ func TestEtcdClient(etcdClient *etcdclient.Client) error {
}
return nil
}

// NeverRetryOnFailure is a retry function for the etcdClient. If there's only one machine, master election doesn't make much sense,
// so we don't bother to retry, we simply dump the failure and return the error directly.
func NeverRetryOnFailure(cluster *etcdclient.Cluster, numReqs int, lastResp http.Response, err error) error {
if len(cluster.Machines) > 1 {
return etcdclient.DefaultCheckRetry(cluster, numReqs, lastResp, err)
}

content, err := httputil.DumpResponse(&lastResp, true)
if err != nil {
glog.Errorf("failure dumping response: %v", err)
} else {
glog.Errorf("etcd failure response: %s", string(content))
}
return err
}

0 comments on commit f785f05

Please sign in to comment.