Skip to content

Commit

Permalink
embed: only override default advertised client URL if the client list…
Browse files Browse the repository at this point in the history
…en URL is 0.0.0.0
  • Loading branch information
gyuho committed Dec 16, 2016
1 parent 531c306 commit c1cc6ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions embed/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,19 @@ func (cfg Config) IsDefaultHost() (string, error) {
return "", defaultHostStatus
}

// IsLCURLDefaultRoute returns true if listen client URL is 0.0.0.0.
func (cfg Config) IsLCURLDefaultRoute() bool {
ip, _, _ := net.SplitHostPort(cfg.LCUrls[0].Host)
return ip == "0.0.0.0"
}

// UpdateHost updates advertise URLs.
func UpdateHost(cfg *Config, host string) {
_, acPort, _ := net.SplitHostPort(cfg.ACUrls[0].Host)
cfg.ACUrls[0] = url.URL{Scheme: cfg.ACUrls[0].Scheme, Host: fmt.Sprintf("%s:%s", host, acPort)}
cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name)
}

// checkBindURLs returns an error if any URL uses a domain name.
// TODO: return error in 3.2.0
func checkBindURLs(urls []url.URL) error {
Expand Down
5 changes: 5 additions & 0 deletions etcdmain/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func startEtcdOrProxyV2() {
defaultHostOverride := defaultHost == "" || defaultHostErr == nil
if (defaultHostOverride || cfg.Name != embed.DefaultName) && cfg.InitialCluster == defaultInitialCluster {
cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name)
// if client-listen-url is 0.0.0.0, just use detected default host
// otherwise, rewrite advertise-client-url with localhost
if !cfg.IsLCURLDefaultRoute() {
embed.UpdateHost(&cfg.Config, "localhost")
}
}

if cfg.Dir == "" {
Expand Down

0 comments on commit c1cc6ad

Please sign in to comment.