Configure Consul Catalog namespace at client level
Co-authored-by: Romain <rtribotte@users.noreply.github.com>
This commit is contained in:
parent
a4b354b33f
commit
9be44d8330
1 changed files with 19 additions and 18 deletions
|
@ -105,7 +105,7 @@ func (p *Provider) Init() error {
|
||||||
// Provide allows the consul catalog provider to provide configurations to traefik using the given configuration channel.
|
// Provide allows the consul catalog provider to provide configurations to traefik using the given configuration channel.
|
||||||
func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error {
|
func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error {
|
||||||
var err error
|
var err error
|
||||||
p.client, err = createClient(p.Endpoint)
|
p.client, err = createClient(p.Namespace, p.Endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create consul client: %w", err)
|
return fmt.Errorf("unable to create consul client: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -203,7 +203,7 @@ func (p *Provider) loadConfiguration(ctx context.Context, certInfo *connectCert,
|
||||||
func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error) {
|
func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error) {
|
||||||
// The query option "Filter" is not supported by /catalog/services.
|
// The query option "Filter" is not supported by /catalog/services.
|
||||||
// https://www.consul.io/api/catalog.html#list-services
|
// https://www.consul.io/api/catalog.html#list-services
|
||||||
opts := &api.QueryOptions{AllowStale: p.Stale, RequireConsistent: p.RequireConsistent, UseCache: p.Cache, Namespace: p.Namespace}
|
opts := &api.QueryOptions{AllowStale: p.Stale, RequireConsistent: p.RequireConsistent, UseCache: p.Cache}
|
||||||
opts = opts.WithContext(ctx)
|
opts = opts.WithContext(ctx)
|
||||||
|
|
||||||
serviceNames, _, err := p.client.Catalog().Services(opts)
|
serviceNames, _, err := p.client.Catalog().Services(opts)
|
||||||
|
@ -296,7 +296,7 @@ func (p *Provider) fetchService(ctx context.Context, name string, connectEnabled
|
||||||
tagFilter = p.Prefix + ".enable=true"
|
tagFilter = p.Prefix + ".enable=true"
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := &api.QueryOptions{AllowStale: p.Stale, RequireConsistent: p.RequireConsistent, UseCache: p.Cache, Namespace: p.Namespace}
|
opts := &api.QueryOptions{AllowStale: p.Stale, RequireConsistent: p.RequireConsistent, UseCache: p.Cache}
|
||||||
opts = opts.WithContext(ctx)
|
opts = opts.WithContext(ctx)
|
||||||
|
|
||||||
catalogFunc := p.client.Catalog().Service
|
catalogFunc := p.client.Catalog().Service
|
||||||
|
@ -458,29 +458,30 @@ func (p *Provider) watchConnectTLS(ctx context.Context, leafWatcher *watch.Plan,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createClient(cfg *EndpointConfig) (*api.Client, error) {
|
func createClient(namespace string, endpoint *EndpointConfig) (*api.Client, error) {
|
||||||
config := api.Config{
|
config := api.Config{
|
||||||
Address: cfg.Address,
|
Address: endpoint.Address,
|
||||||
Scheme: cfg.Scheme,
|
Scheme: endpoint.Scheme,
|
||||||
Datacenter: cfg.DataCenter,
|
Datacenter: endpoint.DataCenter,
|
||||||
WaitTime: time.Duration(cfg.EndpointWaitTime),
|
WaitTime: time.Duration(endpoint.EndpointWaitTime),
|
||||||
Token: cfg.Token,
|
Token: endpoint.Token,
|
||||||
|
Namespace: namespace,
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.HTTPAuth != nil {
|
if endpoint.HTTPAuth != nil {
|
||||||
config.HttpAuth = &api.HttpBasicAuth{
|
config.HttpAuth = &api.HttpBasicAuth{
|
||||||
Username: cfg.HTTPAuth.Username,
|
Username: endpoint.HTTPAuth.Username,
|
||||||
Password: cfg.HTTPAuth.Password,
|
Password: endpoint.HTTPAuth.Password,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.TLS != nil {
|
if endpoint.TLS != nil {
|
||||||
config.TLSConfig = api.TLSConfig{
|
config.TLSConfig = api.TLSConfig{
|
||||||
Address: cfg.Address,
|
Address: endpoint.Address,
|
||||||
CAFile: cfg.TLS.CA,
|
CAFile: endpoint.TLS.CA,
|
||||||
CertFile: cfg.TLS.Cert,
|
CertFile: endpoint.TLS.Cert,
|
||||||
KeyFile: cfg.TLS.Key,
|
KeyFile: endpoint.TLS.Key,
|
||||||
InsecureSkipVerify: cfg.TLS.InsecureSkipVerify,
|
InsecureSkipVerify: endpoint.TLS.InsecureSkipVerify,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue