diff --git a/integration/consul_catalog_test.go b/integration/consul_catalog_test.go index 9cb0c5590..ca913983f 100644 --- a/integration/consul_catalog_test.go +++ b/integration/consul_catalog_test.go @@ -261,6 +261,7 @@ func (s *ConsulCatalogSuite) TestRefreshConfigWithMultipleNodeWithoutHealthCheck err = s.registerAgentService("test", nginx.NetworkSettings.IPAddress, 80, []string{"name=nginx1"}) c.Assert(err, checker.IsNil, check.Commentf("Error registering agent service")) + defer s.deregisterAgentService(nginx.NetworkSettings.IPAddress) req, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:8000/", nil) c.Assert(err, checker.IsNil) diff --git a/provider/consul/consul_catalog.go b/provider/consul/consul_catalog.go index a6fe6f447..2ae332792 100644 --- a/provider/consul/consul_catalog.go +++ b/provider/consul/consul_catalog.go @@ -218,7 +218,7 @@ func (p *CatalogProvider) watchCatalogServices(stopCh <-chan struct{}, watchCh c if data != nil { for key, value := range data { - nodes, _, err := catalog.Service(key, "", options) + nodes, _, err := catalog.Service(key, "", &api.QueryOptions{}) if err != nil { log.Errorf("Failed to get detail of service %s: %s", key, err) return @@ -243,16 +243,13 @@ func (p *CatalogProvider) watchCatalogServices(stopCh <-chan struct{}, watchCh c addedServiceNodeKeys, removedServiceNodeKeys := getChangedServiceNodeKeys(current, flashback) - if len(addedServiceKeys) > 0 || len(addedServiceNodeKeys) > 0 { - log.WithField("DiscoveredServices", addedServiceKeys).Debug("Catalog Services change detected.") + 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 = current - } - - if len(removedServiceKeys) > 0 || len(removedServiceNodeKeys) > 0 { - log.WithField("MissingServices", removedServiceKeys).Debug("Catalog Services change detected.") - watchCh <- data - flashback = current + flashback = make(map[string]Service, len(current)) + for key, value := range current { + flashback[key] = value + } } } }