Fix empty address for registering service without IP
This commit is contained in:
parent
ca1d980746
commit
2ee2e29262
3 changed files with 45 additions and 1 deletions
|
@ -175,6 +175,37 @@ func (s *ConsulCatalogSuite) TestSimpleConfiguration(c *check.C) {
|
||||||
c.Assert(err, checker.IsNil)
|
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) {
|
func (s *ConsulCatalogSuite) TestDefaultConsulService(c *check.C) {
|
||||||
tempObjects := struct {
|
tempObjects := struct {
|
||||||
ConsulAddress string
|
ConsulAddress string
|
||||||
|
|
|
@ -163,6 +163,10 @@ func (p *Provider) addServerTCP(ctx context.Context, item itemData, loadBalancer
|
||||||
return errors.New("port is missing")
|
return errors.New("port is missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if item.Address == "" {
|
||||||
|
return errors.New("address is missing")
|
||||||
|
}
|
||||||
|
|
||||||
loadBalancer.Servers[0].Address = net.JoinHostPort(item.Address, port)
|
loadBalancer.Servers[0].Address = net.JoinHostPort(item.Address, port)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -193,6 +197,10 @@ func (p *Provider) addServer(ctx context.Context, item itemData, loadBalancer *d
|
||||||
return errors.New("port is missing")
|
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].URL = fmt.Sprintf("%s://%s", loadBalancer.Servers[0].Scheme, net.JoinHostPort(item.Address, port))
|
||||||
loadBalancer.Servers[0].Scheme = ""
|
loadBalancer.Servers[0].Scheme = ""
|
||||||
|
|
||||||
|
|
|
@ -157,10 +157,15 @@ func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error
|
||||||
|
|
||||||
for _, consulService := range consulServices {
|
for _, consulService := range consulServices {
|
||||||
labels := tagsToNeutralLabels(consulService.ServiceTags, p.Prefix)
|
labels := tagsToNeutralLabels(consulService.ServiceTags, p.Prefix)
|
||||||
|
address := consulService.ServiceAddress
|
||||||
|
if address == "" {
|
||||||
|
address = consulService.Address
|
||||||
|
}
|
||||||
|
|
||||||
item := itemData{
|
item := itemData{
|
||||||
ID: consulService.ServiceID,
|
ID: consulService.ServiceID,
|
||||||
Name: consulService.ServiceName,
|
Name: consulService.ServiceName,
|
||||||
Address: consulService.ServiceAddress,
|
Address: address,
|
||||||
Port: strconv.Itoa(consulService.ServicePort),
|
Port: strconv.Itoa(consulService.ServicePort),
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
Status: consulService.Checks.AggregatedStatus(),
|
Status: consulService.Checks.AggregatedStatus(),
|
||||||
|
|
Loading…
Reference in a new issue