From e145cbd111825e159975cb7cff4cc5a6a7c1e03e Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 12 Aug 2016 19:55:55 -0700 Subject: [PATCH] embed: use default route IP for default advertise URL Fixes #2858 --- embed/config.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/embed/config.go b/embed/config.go index cb1ff114752d..19eee98e1ecc 100644 --- a/embed/config.go +++ b/embed/config.go @@ -24,6 +24,7 @@ import ( "github.com/coreos/etcd/discovery" "github.com/coreos/etcd/etcdserver" "github.com/coreos/etcd/pkg/cors" + "github.com/coreos/etcd/pkg/netutil" "github.com/coreos/etcd/pkg/transport" "github.com/coreos/etcd/pkg/types" "github.com/ghodss/yaml" @@ -33,13 +34,9 @@ const ( ClusterStateFlagNew = "new" ClusterStateFlagExisting = "existing" - DefaultName = "default" - DefaultInitialAdvertisePeerURLs = "http://localhost:2380" - DefaultAdvertiseClientURLs = "http://localhost:2379" - DefaultListenPeerURLs = "http://localhost:2380" - DefaultListenClientURLs = "http://localhost:2379" - DefaultMaxSnapshots = 5 - DefaultMaxWALs = 5 + DefaultName = "default" + DefaultMaxSnapshots = 5 + DefaultMaxWALs = 5 // maxElectionMs specifies the maximum value of election timeout. // More details are listed in ../Documentation/tuning.md#time-parameters. @@ -50,8 +47,25 @@ var ( ErrConflictBootstrapFlags = fmt.Errorf("multiple discovery or bootstrap flags are set. " + "Choose one of \"initial-cluster\", \"discovery\" or \"discovery-srv\"") ErrUnsetAdvertiseClientURLsFlag = fmt.Errorf("--advertise-client-urls is required when --listen-client-urls is set explicitly") + + DefaultListenPeerURLs = "http://localhost:2380" + DefaultListenClientURLs = "http://localhost:2379" + DefaultInitialAdvertisePeerURLs = "http://localhost:2380" + DefaultAdvertiseClientURLs = "http://localhost:2379" ) +func init() { + ip, err := netutil.GetDefaultHost() + if err != nil { + return + } + // found default host; listen everywhere, advertise on default host + DefaultListenPeerURLs = "http://0.0.0.0:2380" + DefaultListenClientURLs = "http://0.0.0.0:2379" + DefaultInitialAdvertisePeerURLs = "http://" + ip + ":2380" + DefaultAdvertiseClientURLs = "http://" + ip + ":2379" +} + // Config holds the arguments for configuring an etcd server. type Config struct { // member