Skip to content

Commit

Permalink
Consul catalog deregister service
Browse files Browse the repository at this point in the history
  • Loading branch information
juliens authored and traefiker committed Sep 29, 2017
1 parent 691a678 commit 2c17f85
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 5 additions & 1 deletion integration/consul_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,18 @@ func (s *ConsulCatalogSuite) TestSingleService(c *check.C) {

err = s.registerService("test", nginx.NetworkSettings.IPAddress, 80, []string{})
c.Assert(err, checker.IsNil, check.Commentf("Error registering service"))
defer s.deregisterService("test", nginx.NetworkSettings.IPAddress)

req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/", nil)
c.Assert(err, checker.IsNil)
req.Host = "test.consul.localhost"

err = try.Request(req, 10*time.Second, try.StatusCodeIs(http.StatusOK), try.HasBody())
c.Assert(err, checker.IsNil)

s.deregisterService("test", nginx.NetworkSettings.IPAddress)
err = try.Request(req, 10*time.Second, try.StatusCodeIs(http.StatusNotFound), try.HasBody())
c.Assert(err, checker.IsNil)

}

func (s *ConsulCatalogSuite) TestExposedByDefaultFalseSingleService(c *check.C) {
Expand Down
8 changes: 2 additions & 6 deletions provider/consul/consul_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func (p *CatalogProvider) watchCatalogServices(stopCh <-chan struct{}, watchCh c
catalog := p.client.Catalog()

safe.Go(func() {
current := make(map[string]Service)
// variable to hold previous state
var flashback map[string]Service

Expand All @@ -216,7 +215,7 @@ func (p *CatalogProvider) watchCatalogServices(stopCh <-chan struct{}, watchCh c
options.WaitIndex = meta.LastIndex

if data != nil {

current := make(map[string]Service)
for key, value := range data {
nodes, _, err := catalog.Service(key, "", &api.QueryOptions{})
if err != nil {
Expand Down Expand Up @@ -246,10 +245,7 @@ func (p *CatalogProvider) watchCatalogServices(stopCh <-chan struct{}, watchCh c
if len(removedServiceKeys) > 0 || len(removedServiceNodeKeys) > 0 || len(addedServiceKeys) > 0 || len(addedServiceNodeKeys) > 0 {
log.WithField("MissingServices", removedServiceKeys).WithField("DiscoveredServices", addedServiceKeys).Debug("Catalog Services change detected.")
watchCh <- data
flashback = make(map[string]Service, len(current))
for key, value := range current {
flashback[key] = value
}
flashback = current
}
}
}
Expand Down

0 comments on commit 2c17f85

Please sign in to comment.