From c3a91629b91922b77fac777b821d9ee692d1c62b Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Mon, 12 Jun 2017 13:36:32 -0700 Subject: [PATCH] etcdserver: better warning when initial-cluster doesn't match advertise urls The old error was not clear about what URLs needed to be added, sometimes truncating the list. To make it clearer, print out the missing entries for --initial-cluster and print the full list of initial advertise peers. Fixes #8079 and #7927 --- etcdserver/config.go | 32 ++++++++++++++++++++++++++++---- etcdserver/config_test.go | 8 ++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/etcdserver/config.go b/etcdserver/config.go index a2713c9e61a9..3f876f46fecd 100644 --- a/etcdserver/config.go +++ b/etcdserver/config.go @@ -117,11 +117,35 @@ func (c *ServerConfig) advertiseMatchesCluster() error { sort.Strings(apurls) ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second) defer cancel() - if !netutil.URLStringsEqual(ctx, apurls, urls.StringSlice()) { - umap := map[string]types.URLs{c.Name: c.PeerURLs} - return fmt.Errorf("--initial-cluster must include %s given --initial-advertise-peer-urls=%s", types.URLsMap(umap).String(), strings.Join(apurls, ",")) + if netutil.URLStringsEqual(ctx, apurls, urls.StringSlice()) { + return nil } - return nil + + initMap, apMap := make(map[string]struct{}), make(map[string]struct{}) + for _, url := range c.PeerURLs { + apMap[url.String()] = struct{}{} + } + for _, url := range c.InitialPeerURLsMap[c.Name] { + initMap[url.String()] = struct{}{} + } + + missing := []string{} + for url := range initMap { + if _, ok := apMap[url]; !ok { + missing = append(missing, url) + } + } + + apStr := strings.Join(apurls, ",") + if len(missing) > 0 { + for i := range missing { + missing[i] = c.Name + "=" + missing[i] + } + mstr := strings.Join(missing, ",") + return fmt.Errorf("--initial-cluster has %s but missing from --initial-advertise-peer-urls=%s ", mstr, apStr) + } + umap := types.URLsMap(map[string]types.URLs{c.Name: c.PeerURLs}) + return fmt.Errorf("--initial-advertise-peer-urls=%s but missing from --initial-cluster=%s", apStr, umap.String()) } func (c *ServerConfig) MemberDir() string { return filepath.Join(c.DataDir, "member") } diff --git a/etcdserver/config_test.go b/etcdserver/config_test.go index bf0cd7f75d21..e574ab10dc04 100644 --- a/etcdserver/config_test.go +++ b/etcdserver/config_test.go @@ -107,6 +107,14 @@ func TestConfigVerifyLocalMember(t *testing.T) { true, }, + { + // Advertised peer URLs must match those in cluster-state + "node1=http://localhost:12345", + []string{"http://localhost:2380", "http://localhost:12345"}, + true, + + true, + }, { // Advertised peer URLs must match those in cluster-state "node1=http://localhost:2380",