Browse Source

Revert "Treat URLs have same IP address as same"

This reverts commit f8ce5996b0566619fde8cca431890a49c52cf3d6.

etcd no longer resolves TCP addresses passed in through flags,
so there is no need to compare hostname and IP slices anymore.
(for more details: a3892221eea4804f58ce83934c91964e83f4f30c)

Conflicts:
	etcdserver/cluster.go
	etcdserver/config.go
	pkg/netutil/netutil.go
	pkg/netutil/netutil_test.go
Yicheng Qin 10 years ago
parent
commit
3153e635d5
4 changed files with 4 additions and 157 deletions
  1. 2 3
      etcdserver/cluster.go
  2. 2 3
      etcdserver/config.go
  3. 0 46
      pkg/netutil/netutil.go
  4. 0 105
      pkg/netutil/netutil_test.go

+ 2 - 3
etcdserver/cluster.go

@@ -22,12 +22,12 @@ import (
 	"fmt"
 	"fmt"
 	"log"
 	"log"
 	"path"
 	"path"
+	"reflect"
 	"sort"
 	"sort"
 	"strings"
 	"strings"
 	"sync"
 	"sync"
 
 
 	"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
 	"github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
-	"github.com/coreos/etcd/pkg/netutil"
 	"github.com/coreos/etcd/pkg/types"
 	"github.com/coreos/etcd/pkg/types"
 	"github.com/coreos/etcd/raft"
 	"github.com/coreos/etcd/raft"
 	"github.com/coreos/etcd/raft/raftpb"
 	"github.com/coreos/etcd/raft/raftpb"
@@ -413,8 +413,7 @@ func ValidateClusterAndAssignIDs(local *cluster, existing *cluster) error {
 	sort.Sort(SortableMemberSliceByPeerURLs(lms))
 	sort.Sort(SortableMemberSliceByPeerURLs(lms))
 
 
 	for i := range ems {
 	for i := range ems {
-		// TODO: Remove URLStringsEqual after improvement of using hostnames #2150 #2123
-		if !netutil.URLStringsEqual(ems[i].PeerURLs, lms[i].PeerURLs) {
+		if !reflect.DeepEqual(ems[i].PeerURLs, lms[i].PeerURLs) {
 			return fmt.Errorf("unmatched member while checking PeerURLs")
 			return fmt.Errorf("unmatched member while checking PeerURLs")
 		}
 		}
 		lms[i].ID = ems[i].ID
 		lms[i].ID = ems[i].ID

+ 2 - 3
etcdserver/config.go

@@ -19,9 +19,9 @@ import (
 	"log"
 	"log"
 	"net/http"
 	"net/http"
 	"path"
 	"path"
+	"reflect"
 	"sort"
 	"sort"
 
 
-	"github.com/coreos/etcd/pkg/netutil"
 	"github.com/coreos/etcd/pkg/types"
 	"github.com/coreos/etcd/pkg/types"
 )
 )
 
 
@@ -90,12 +90,11 @@ func (c *ServerConfig) verifyLocalMember(strict bool) error {
 	}
 	}
 
 
 	// Advertised peer URLs must match those in the cluster peer list
 	// Advertised peer URLs must match those in the cluster peer list
-	// TODO: Remove URLStringsEqual after improvement of using hostnames #2150 #2123
 	apurls := c.PeerURLs.StringSlice()
 	apurls := c.PeerURLs.StringSlice()
 	sort.Strings(apurls)
 	sort.Strings(apurls)
 	urls.Sort()
 	urls.Sort()
 	if strict {
 	if strict {
-		if !netutil.URLStringsEqual(apurls, urls.StringSlice()) {
+		if !reflect.DeepEqual(apurls, urls.StringSlice()) {
 			return fmt.Errorf("%s has different advertised URLs in the cluster and advertised peer URLs list", c.Name)
 			return fmt.Errorf("%s has different advertised URLs in the cluster and advertised peer URLs list", c.Name)
 		}
 		}
 	}
 	}

+ 0 - 46
pkg/netutil/netutil.go

@@ -20,7 +20,6 @@ import (
 	"net"
 	"net"
 	"net/http"
 	"net/http"
 	"net/url"
 	"net/url"
-	"reflect"
 	"strings"
 	"strings"
 )
 )
 
 
@@ -58,51 +57,6 @@ func ResolveTCPAddrs(urls ...[]url.URL) error {
 	return nil
 	return nil
 }
 }
 
 
-// URLsEqual checks equality of url.URLS between two arrays.
-// This check pass even if an URL is in hostname and opposite is in IP address.
-func URLsEqual(a []url.URL, b []url.URL) bool {
-	if len(a) != len(b) {
-		return false
-	}
-	for i, urlA := range a {
-		urlB := b[i]
-
-		if !reflect.DeepEqual(urlA, urlB) {
-			urls := []url.URL{urlA, urlB}
-			ResolveTCPAddrs(urls)
-			if !reflect.DeepEqual(urls[0], urls[1]) {
-				return false
-			}
-		}
-	}
-
-	return true
-}
-
-func URLStringsEqual(a []string, b []string) bool {
-	if len(a) != len(b) {
-		return false
-	}
-	urlsA := make([]url.URL, len(a))
-	for _, str := range a {
-		u, err := url.Parse(str)
-		if err != nil {
-			return false
-		}
-		urlsA = append(urlsA, *u)
-	}
-	urlsB := make([]url.URL, len(b))
-	for _, str := range b {
-		u, err := url.Parse(str)
-		if err != nil {
-			return false
-		}
-		urlsB = append(urlsB, *u)
-	}
-
-	return URLsEqual(urlsA, urlsB)
-}
-
 // BasicAuth returns the username and password provided in the request's
 // BasicAuth returns the username and password provided in the request's
 // Authorization header, if the request uses HTTP Basic Authentication.
 // Authorization header, if the request uses HTTP Basic Authentication.
 // See RFC 2617, Section 2.
 // See RFC 2617, Section 2.

+ 0 - 105
pkg/netutil/netutil_test.go

@@ -136,108 +136,3 @@ func TestResolveTCPAddrs(t *testing.T) {
 		}
 		}
 	}
 	}
 }
 }
-
-func TestURLsEqual(t *testing.T) {
-	defer func() { resolveTCPAddr = net.ResolveTCPAddr }()
-	resolveTCPAddr = func(network, addr string) (*net.TCPAddr, error) {
-		host, port, err := net.SplitHostPort(addr)
-		if host != "example.com" {
-			return nil, errors.New("cannot resolve host.")
-		}
-		i, err := strconv.Atoi(port)
-		if err != nil {
-			return nil, err
-		}
-		return &net.TCPAddr{IP: net.ParseIP("10.0.10.1"), Port: i, Zone: ""}, nil
-	}
-
-	tests := []struct {
-		a      []url.URL
-		b      []url.URL
-		expect bool
-	}{
-		{
-			a:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}},
-			b:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}},
-			expect: true,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "example.com:2379"}},
-			b:      []url.URL{{Scheme: "http", Host: "10.0.10.1:2379"}},
-			expect: true,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			b:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			expect: true,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "example.com:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			b:      []url.URL{{Scheme: "http", Host: "example.com:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			expect: true,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "10.0.10.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			b:      []url.URL{{Scheme: "http", Host: "example.com:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			expect: true,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}},
-			b:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2380"}},
-			expect: false,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "example.com:2380"}},
-			b:      []url.URL{{Scheme: "http", Host: "10.0.10.1:2379"}},
-			expect: false,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}},
-			b:      []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}},
-			expect: false,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "example.com:2379"}},
-			b:      []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}},
-			expect: false,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			b:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2380"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			expect: false,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "example.com:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			b:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2380"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			expect: false,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "127.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			b:      []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			expect: false,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "example.com:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			b:      []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			expect: false,
-		},
-		{
-			a:      []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}},
-			b:      []url.URL{{Scheme: "http", Host: "10.0.0.1:2379"}, {Scheme: "http", Host: "127.0.0.1:2380"}},
-			expect: false,
-		},
-	}
-
-	for _, test := range tests {
-		result := URLsEqual(test.a, test.b)
-		if result != test.expect {
-			t.Errorf("a:%v b:%v, expected %v but %v", test.a, test.b, test.expect, result)
-		}
-	}
-}
-func TestURLStringsEqual(t *testing.T) {
-	result := URLStringsEqual([]string{"http://127.0.0.1:8080"}, []string{"http://127.0.0.1:8080"})
-	if !result {
-		t.Errorf("unexpected result %v", result)
-	}
-}