mirror of
https://github.com/containous/traefik.git
synced 2024-12-23 17:34:13 +03:00
Fix empty address for registering service without IP
This commit is contained in:
parent
ca1d980746
commit
2ee2e29262
@ -175,6 +175,37 @@ func (s *ConsulCatalogSuite) TestSimpleConfiguration(c *check.C) {
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
||||
func (s *ConsulCatalogSuite) TestRegisterServiceWithoutIP(c *check.C) {
|
||||
tempObjects := struct {
|
||||
ConsulAddress string
|
||||
DefaultRule string
|
||||
}{
|
||||
ConsulAddress: s.consulAddress,
|
||||
DefaultRule: "Host(`{{ normalize .Name }}.consul.localhost`)",
|
||||
}
|
||||
|
||||
file := s.adaptFile(c, "fixtures/consul_catalog/simple.toml", tempObjects)
|
||||
defer os.Remove(file)
|
||||
|
||||
err := s.registerService("whoami1", "whoami", "", "80", []string{"traefik.enable=true"})
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
cmd, display := s.traefikCmd(withConfigFile(file))
|
||||
defer display(c)
|
||||
err = cmd.Start()
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8080/api/http/services", nil)
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = try.Request(req, 2*time.Second, try.StatusCodeIs(200), try.BodyContainsOr("whoami@consulcatalog", "\"http://127.0.0.1:80\": \"UP\""))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
err = s.deregisterService("whoami1")
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
|
||||
func (s *ConsulCatalogSuite) TestDefaultConsulService(c *check.C) {
|
||||
tempObjects := struct {
|
||||
ConsulAddress string
|
||||
|
@ -163,6 +163,10 @@ func (p *Provider) addServerTCP(ctx context.Context, item itemData, loadBalancer
|
||||
return errors.New("port is missing")
|
||||
}
|
||||
|
||||
if item.Address == "" {
|
||||
return errors.New("address is missing")
|
||||
}
|
||||
|
||||
loadBalancer.Servers[0].Address = net.JoinHostPort(item.Address, port)
|
||||
return nil
|
||||
}
|
||||
@ -193,6 +197,10 @@ func (p *Provider) addServer(ctx context.Context, item itemData, loadBalancer *d
|
||||
return errors.New("port is missing")
|
||||
}
|
||||
|
||||
if item.Address == "" {
|
||||
return errors.New("address is missing")
|
||||
}
|
||||
|
||||
loadBalancer.Servers[0].URL = fmt.Sprintf("%s://%s", loadBalancer.Servers[0].Scheme, net.JoinHostPort(item.Address, port))
|
||||
loadBalancer.Servers[0].Scheme = ""
|
||||
|
||||
|
@ -157,10 +157,15 @@ func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error
|
||||
|
||||
for _, consulService := range consulServices {
|
||||
labels := tagsToNeutralLabels(consulService.ServiceTags, p.Prefix)
|
||||
address := consulService.ServiceAddress
|
||||
if address == "" {
|
||||
address = consulService.Address
|
||||
}
|
||||
|
||||
item := itemData{
|
||||
ID: consulService.ServiceID,
|
||||
Name: consulService.ServiceName,
|
||||
Address: consulService.ServiceAddress,
|
||||
Address: address,
|
||||
Port: strconv.Itoa(consulService.ServicePort),
|
||||
Labels: labels,
|
||||
Status: consulService.Checks.AggregatedStatus(),
|
||||
|
Loading…
Reference in New Issue
Block a user