From 3c1d5e0393e91ce977ce29d1176c1303d7e6dbf7 Mon Sep 17 00:00:00 2001 From: Kevin Pollet Date: Wed, 29 Jun 2022 12:04:09 +0200 Subject: [PATCH] Move consulcatalog provider to only use health apis Co-authored-by: Charles Zaffery --- pkg/provider/consulcatalog/consul_catalog.go | 33 ++++++++------------ 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/pkg/provider/consulcatalog/consul_catalog.go b/pkg/provider/consulcatalog/consul_catalog.go index 1bd0dab76..e0564681f 100644 --- a/pkg/provider/consulcatalog/consul_catalog.go +++ b/pkg/provider/consulcatalog/consul_catalog.go @@ -316,31 +316,31 @@ func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error } for _, consulService := range consulServices { - address := consulService.ServiceAddress + address := consulService.Service.Address if address == "" { - address = consulService.Address + address = consulService.Node.Address } - namespace := consulService.Namespace + namespace := consulService.Service.Namespace if namespace == "" { namespace = "default" } - status, exists := statuses[consulService.ID+consulService.ServiceID] + status, exists := statuses[consulService.Node.ID+consulService.Service.ID] if !exists { status = api.HealthAny } item := itemData{ - ID: consulService.ServiceID, - Node: consulService.Node, - Datacenter: consulService.Datacenter, + ID: consulService.Service.ID, + Node: consulService.Node.Node, + Datacenter: consulService.Node.Datacenter, Namespace: namespace, Name: name, Address: address, - Port: strconv.Itoa(consulService.ServicePort), - Labels: tagsToNeutralLabels(consulService.ServiceTags, p.Prefix), - Tags: consulService.ServiceTags, + Port: strconv.Itoa(consulService.Service.Port), + Labels: tagsToNeutralLabels(consulService.Service.Tags, p.Prefix), + Tags: consulService.Service.Tags, Status: status, } @@ -358,7 +358,7 @@ func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error return data, nil } -func (p *Provider) fetchService(ctx context.Context, name string, connectEnabled bool) ([]*api.CatalogService, map[string]string, error) { +func (p *Provider) fetchService(ctx context.Context, name string, connectEnabled bool) ([]*api.ServiceEntry, map[string]string, error) { var tagFilter string if !p.ExposedByDefault { tagFilter = p.Prefix + ".enable=true" @@ -367,19 +367,12 @@ func (p *Provider) fetchService(ctx context.Context, name string, connectEnabled opts := &api.QueryOptions{AllowStale: p.Stale, RequireConsistent: p.RequireConsistent, UseCache: p.Cache} opts = opts.WithContext(ctx) - catalogFunc := p.client.Catalog().Service healthFunc := p.client.Health().Service if connectEnabled { - catalogFunc = p.client.Catalog().Connect healthFunc = p.client.Health().Connect } - consulServices, _, err := catalogFunc(name, tagFilter, opts) - if err != nil { - return nil, nil, err - } - - healthServices, _, err := healthFunc(name, tagFilter, false, opts) + consulServices, _, err := healthFunc(name, tagFilter, false, opts) if err != nil { return nil, nil, err } @@ -387,7 +380,7 @@ func (p *Provider) fetchService(ctx context.Context, name string, connectEnabled // Index status by service and node so it can be retrieved from a CatalogService even if the health and services // are not in sync. statuses := make(map[string]string) - for _, health := range healthServices { + for _, health := range consulServices { if health.Service == nil || health.Node == nil { continue }