fix: consul-catalog use port from label instead of item port.

This commit is contained in:
Ludovic Fernandez 2020-02-25 23:00:04 +01:00 committed by GitHub
parent 1557fda588
commit 9795a7c4a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View file

@ -149,15 +149,19 @@ func (p *Provider) addServerTCP(ctx context.Context, item itemData, loadBalancer
return errors.New("load-balancer is not defined") return errors.New("load-balancer is not defined")
} }
var port string
if len(loadBalancer.Servers) > 0 {
port = loadBalancer.Servers[0].Port
}
if len(loadBalancer.Servers) == 0 { if len(loadBalancer.Servers) == 0 {
loadBalancer.Servers = []dynamic.TCPServer{{}} loadBalancer.Servers = []dynamic.TCPServer{{}}
} }
var port string if item.Port != "" && port == "" {
if item.Port != "" {
port = item.Port port = item.Port
loadBalancer.Servers[0].Port = ""
} }
loadBalancer.Servers[0].Port = ""
if port == "" { if port == "" {
return errors.New("port is missing") return errors.New("port is missing")
@ -188,10 +192,10 @@ func (p *Provider) addServer(ctx context.Context, item itemData, loadBalancer *d
loadBalancer.Servers = []dynamic.Server{server} loadBalancer.Servers = []dynamic.Server{server}
} }
if item.Port != "" { if item.Port != "" && port == "" {
port = item.Port port = item.Port
loadBalancer.Servers[0].Port = ""
} }
loadBalancer.Servers[0].Port = ""
if port == "" { if port == "" {
return errors.New("port is missing") return errors.New("port is missing")

View file

@ -1371,7 +1371,7 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &dynamic.ServersLoadBalancer{ LoadBalancer: &dynamic.ServersLoadBalancer{
Servers: []dynamic.Server{ Servers: []dynamic.Server{
{ {
URL: "h2c://127.0.0.1:80", URL: "h2c://127.0.0.1:8080",
}, },
}, },
PassHostHeader: Bool(true), PassHostHeader: Bool(true),
@ -1419,7 +1419,7 @@ func Test_buildConfiguration(t *testing.T) {
LoadBalancer: &dynamic.ServersLoadBalancer{ LoadBalancer: &dynamic.ServersLoadBalancer{
Servers: []dynamic.Server{ Servers: []dynamic.Server{
{ {
URL: "http://127.0.0.1:80", URL: "http://127.0.0.1:8080",
}, },
}, },
PassHostHeader: Bool(true), PassHostHeader: Bool(true),