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.
|
||||
func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error {
|
||||
var err error
|
||||
p.client, err = createClient(p.Endpoint)
|
||||
p.client, err = createClient(p.Namespace, p.Endpoint)
|
||||
if err != nil {
|
||||
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) {
|
||||
// The query option "Filter" is not supported by /catalog/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)
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
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{
|
||||
Address: cfg.Address,
|
||||
Scheme: cfg.Scheme,
|
||||
Datacenter: cfg.DataCenter,
|
||||
WaitTime: time.Duration(cfg.EndpointWaitTime),
|
||||
Token: cfg.Token,
|
||||
Address: endpoint.Address,
|
||||
Scheme: endpoint.Scheme,
|
||||
Datacenter: endpoint.DataCenter,
|
||||
WaitTime: time.Duration(endpoint.EndpointWaitTime),
|
||||
Token: endpoint.Token,
|
||||
Namespace: namespace,
|
||||
}
|
||||
|
||||
if cfg.HTTPAuth != nil {
|
||||
if endpoint.HTTPAuth != nil {
|
||||
config.HttpAuth = &api.HttpBasicAuth{
|
||||
Username: cfg.HTTPAuth.Username,
|
||||
Password: cfg.HTTPAuth.Password,
|
||||
Username: endpoint.HTTPAuth.Username,
|
||||
Password: endpoint.HTTPAuth.Password,
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.TLS != nil {
|
||||
if endpoint.TLS != nil {
|
||||
config.TLSConfig = api.TLSConfig{
|
||||
Address: cfg.Address,
|
||||
CAFile: cfg.TLS.CA,
|
||||
CertFile: cfg.TLS.Cert,
|
||||
KeyFile: cfg.TLS.Key,
|
||||
InsecureSkipVerify: cfg.TLS.InsecureSkipVerify,
|
||||
Address: endpoint.Address,
|
||||
CAFile: endpoint.TLS.CA,
|
||||
CertFile: endpoint.TLS.Cert,
|
||||
KeyFile: endpoint.TLS.Key,
|
||||
InsecureSkipVerify: endpoint.TLS.InsecureSkipVerify,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue