diff --git a/etcdmain/etcd.go b/etcdmain/etcd.go index 21e9854a53f..2444023a4cd 100644 --- a/etcdmain/etcd.go +++ b/etcdmain/etcd.go @@ -60,6 +60,8 @@ func startEtcdOrProxyV2() { grpc.EnableTracing = false cfg := newConfig() + defaultInitialCluster := cfg.InitialCluster + err := cfg.parse(os.Args[1:]) if err != nil { plog.Errorf("error verifying flags, %v. See 'etcd --help'.", err) @@ -83,7 +85,9 @@ func startEtcdOrProxyV2() { plog.Infof("setting maximum number of CPUs to %d, total number of available CPUs is %d", GoMaxProcs, runtime.NumCPU()) // TODO: check whether fields are set instead of whether fields have default value - if cfg.Name != embed.DefaultName && cfg.InitialCluster == cfg.InitialClusterFromName(embed.DefaultName) { + defaultHost, defaultHostErr := cfg.IsDefaultHost() + defaultHostOverride := defaultHost == "" || defaultHostErr == nil + if (defaultHostOverride || cfg.Name != embed.DefaultName) && cfg.InitialCluster == defaultInitialCluster { cfg.InitialCluster = cfg.InitialClusterFromName(cfg.Name) } @@ -184,6 +188,15 @@ func startEtcdOrProxyV2() { // startEtcd runs StartEtcd in addition to hooks needed for standalone etcd. func startEtcd(cfg *embed.Config) (<-chan struct{}, <-chan error, error) { + defaultHost, dhErr := cfg.IsDefaultHost() + if defaultHost != "" { + if dhErr == nil { + plog.Infof("advertising using detected default host %q", defaultHost) + } else { + plog.Noticef("failed to detect default host, advertise falling back to %q (%v)", defaultHost, dhErr) + } + } + e, err := embed.StartEtcd(cfg) if err != nil { return nil, nil, err