Skip to content

Commit

Permalink
gateway: fix the dns discovery method
Browse files Browse the repository at this point in the history
strip the scheme from the endpoints to have a clean hostname for TCP proxy

Fixes #7452
  • Loading branch information
bdudelsack committed Mar 8, 2017
1 parent 320768b commit e317664
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions etcdmain/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"net"
"os"
"time"
"net/url"

"github.com/coreos/etcd/client"
"github.com/coreos/etcd/pkg/transport"
Expand Down Expand Up @@ -77,6 +78,20 @@ func newGatewayStartCommand() *cobra.Command {
return &cmd
}

func stripSchema(eps []string) []string {
var endpoints []string

for _, ep := range eps {

if u, err := url.Parse(ep); err == nil && u.Host != "" {
ep = u.Host
}

endpoints = append(endpoints, ep)
}

return endpoints
}
func startGateway(cmd *cobra.Command, args []string) {
endpoints := gatewayEndpoints
if gatewayDNSCluster != "" {
Expand All @@ -101,6 +116,9 @@ func startGateway(cmd *cobra.Command, args []string) {
}
}

// Strip the schema from the endpoints because we start just a TCP proxy
endpoints = stripSchema(endpoints)

if len(endpoints) == 0 {
plog.Fatalf("no endpoints found")
}
Expand Down
27 changes: 27 additions & 0 deletions etcdmain/gateway_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package etcdmain

import "testing"

func TestStripSchema(t *testing.T) {
endpoints := []string{
"https://etcd-node:2379",
"http://etcd-node:2379",
"etcd-node:2379",
"etcd-node",
}

expected := []string {
"etcd-node:2379",
"etcd-node:2379",
"etcd-node:2379",
"etcd-node",
}

result := stripSchema(endpoints)

for i, ep := range result {
if ep != expected[i] {
t.Errorf("Expected stripSchema to return '%v' from '%v' but got '%v'", expected[i], endpoints[i], ep)
}
}
}

0 comments on commit e317664

Please sign in to comment.