// 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 }
func main() { flag.Parse() runtime.GOMAXPROCS(*maxThreads) docker, err := godocker.NewClient(*endpoint) if err != nil { log.Fatalln("Couldn't docker.NewClient: ", err) } etcd := goetcd.NewClient(strings.Split(*etcdNodes, ",")) etcd.SetDialTimeout(*etcdDialTimeout) if *strongConsistency { etcd.SetConsistency(goetcd.STRONG_CONSISTENCY) } // Add a delay for each retry attempt etcd.CheckRetry = func(cluster *goetcd.Cluster, numReqs int, lastResp http.Response, err error) error { time.Sleep(*etcdRetryDelay) return goetcd.DefaultCheckRetry(cluster, numReqs, lastResp, err) } auth := godocker.AuthConfiguration{} if *dockerCfg != "" { auth, err = AuthFromDockerCfg(*dockerCfg, *registry) if err != nil { log.Fatalln("AuthFromDockerCfg: ", err) } } deployer := NewDeployer(docker, *registry, auth, etcd, *etcdPrefix, uint(*killTimeout), *repullPeriod) deployer.RegisterDockerHubWebhook(*webhookPath) if *slackWebhookURL != "" { slack = NewSlackClient(*slackWebhookURL) } log.Fatal(http.ListenAndServe(*listenAddr, nil)) }