From 64c52a6921993a37c509e6211570070a80c7045b Mon Sep 17 00:00:00 2001 From: SALLEYRON Julien Date: Fri, 29 Sep 2017 16:30:03 +0200 Subject: [PATCH] Consul catalog remove service failed --- integration/consul_catalog_test.go | 6 +++++- provider/consul/consul_catalog.go | 8 ++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/integration/consul_catalog_test.go b/integration/consul_catalog_test.go index ca913983f..1ec14f6a1 100644 --- a/integration/consul_catalog_test.go +++ b/integration/consul_catalog_test.go @@ -138,7 +138,6 @@ 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) @@ -146,6 +145,11 @@ func (s *ConsulCatalogSuite) TestSingleService(c *check.C) { 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) { diff --git a/provider/consul/consul_catalog.go b/provider/consul/consul_catalog.go index 2ae332792..e34a07a0d 100644 --- a/provider/consul/consul_catalog.go +++ b/provider/consul/consul_catalog.go @@ -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 @@ -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 { @@ -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 } } }