From 7ebb72bcceca8dd5ace57d2b3b1af54858ef5434 Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Wed, 1 Mar 2017 13:22:03 -0800 Subject: [PATCH] etcdmain: add separate 'acurl' field on user-provided flag Signed-off-by: Gyu-Ho Lee --- etcdmain/config.go | 23 +++++++++++++++++++++-- etcdmain/etcd.go | 2 +- etcdmain/help.go | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/etcdmain/config.go b/etcdmain/config.go index c4c63a942e54..73b708d04455 100644 --- a/etcdmain/config.go +++ b/etcdmain/config.go @@ -26,6 +26,7 @@ import ( "github.com/coreos/etcd/embed" "github.com/coreos/etcd/pkg/flags" + "github.com/coreos/etcd/pkg/types" "github.com/coreos/etcd/version" "github.com/ghodss/yaml" ) @@ -79,6 +80,11 @@ type config struct { printVersion bool ignored []string logOutput string + + // needs this separate field in order to decide + // whether user provides its own url and prevents + // it from being overwritten by the default host + acurl string } // configFlags has the set of flags used for command line parsing a Config @@ -141,7 +147,12 @@ func newConfig() *config { // clustering fs.Var(flags.NewURLsValue(embed.DefaultInitialAdvertisePeerURLs), "initial-advertise-peer-urls", "List of this member's peer URLs to advertise to the rest of the cluster.") - fs.Var(flags.NewURLsValue(embed.DefaultAdvertiseClientURLs), "advertise-client-urls", "List of this member's client URLs to advertise to the public.") + acflag := "List of this member's client URLs to advertise to the public" + if embed.DefaultAdvertiseClientURLs != "" { + acflag += fmt.Sprintf(" (if empty, defaults to %q)", embed.DefaultAdvertiseClientURLs) + } + acflag += "." + fs.StringVar(&cfg.acurl, "advertise-client-urls", "", acflag) fs.StringVar(&cfg.Durl, "discovery", cfg.Durl, "Discovery URL used to bootstrap the cluster.") fs.Var(cfg.fallback, "discovery-fallback", fmt.Sprintf("Valid values include %s", strings.Join(cfg.fallback.Values, ", "))) if err := cfg.fallback.Set(fallbackFlagProxy); err != nil { @@ -253,7 +264,15 @@ func (cfg *config) configFromCmdLine() error { cfg.LPUrls = flags.URLsFromFlag(cfg.FlagSet, "listen-peer-urls") cfg.APUrls = flags.URLsFromFlag(cfg.FlagSet, "initial-advertise-peer-urls") cfg.LCUrls = flags.URLsFromFlag(cfg.FlagSet, "listen-client-urls") - cfg.ACUrls = flags.URLsFromFlag(cfg.FlagSet, "advertise-client-urls") + addr := cfg.acurl + if addr == "" { + addr = embed.DefaultAdvertiseClientURLs + } + us, err := types.NewURLs(strings.Split(addr, ",")) + if err != nil { + plog.Panicf("unexpected error parsing advertise-client-urls flag: %v", err) + } + cfg.ACUrls = us cfg.ClusterState = cfg.clusterState.String() cfg.Fallback = cfg.fallback.String() cfg.Proxy = cfg.proxy.String() diff --git a/etcdmain/etcd.go b/etcdmain/etcd.go index 321e1ce47031..1d95c7572d2a 100644 --- a/etcdmain/etcd.go +++ b/etcdmain/etcd.go @@ -85,7 +85,7 @@ func startEtcdOrProxyV2() { GoMaxProcs := runtime.GOMAXPROCS(0) plog.Infof("setting maximum number of CPUs to %d, total number of available CPUs is %d", GoMaxProcs, runtime.NumCPU()) - (&cfg.Config).UpdateDefaultClusterFromName(defaultInitialCluster) + (&cfg.Config).UpdateDefaultClusterFromName(cfg.acurl, defaultInitialCluster) if cfg.Dir == "" { cfg.Dir = fmt.Sprintf("%v.etcd", cfg.Name) diff --git a/etcdmain/help.go b/etcdmain/help.go index fbdaf737c949..07540334da48 100644 --- a/etcdmain/help.go +++ b/etcdmain/help.go @@ -78,8 +78,8 @@ clustering flags: --initial-cluster-token 'etcd-cluster' initial cluster token for the etcd cluster during bootstrap. Specifying this can protect you from unintended cross-cluster interaction when running multiple clusters. - --advertise-client-urls 'http://localhost:2379' - list of this member's client URLs to advertise to the public. + --advertise-client-urls '' + list of this member's client URLs to advertise to the public (if empty, defaults to "` + embed.DefaultAdvertiseClientURLs + `"). The client URLs advertised should be accessible to machines that talk to etcd cluster. etcd client libraries parse these URLs to connect to the cluster. --discovery '' discovery URL used to bootstrap the cluster.