Support consul enterprise namespaces in consul catalog provider
Co-authored-by: Romain <rtribotte@users.noreply.github.com>
This commit is contained in:
parent
93de7cf0c0
commit
d970813c20
6 changed files with 42 additions and 2 deletions
|
@ -694,3 +694,32 @@ providers:
|
||||||
```
|
```
|
||||||
|
|
||||||
For additional information, refer to [Restrict the Scope of Service Discovery](./overview.md#restrict-the-scope-of-service-discovery).
|
For additional information, refer to [Restrict the Scope of Service Discovery](./overview.md#restrict-the-scope-of-service-discovery).
|
||||||
|
|
||||||
|
### `namespace`
|
||||||
|
|
||||||
|
_Optional, Default=""_
|
||||||
|
|
||||||
|
The `namespace` option defines the namespace in which the consul catalog services will be discovered.
|
||||||
|
|
||||||
|
!!! warning
|
||||||
|
|
||||||
|
The namespace option only works with [Consul Enterprise](https://www.consul.io/docs/enterprise),
|
||||||
|
which provides the [Namespaces](https://www.consul.io/docs/enterprise/namespaces) feature.
|
||||||
|
|
||||||
|
```yaml tab="File (YAML)"
|
||||||
|
providers:
|
||||||
|
consulCatalog:
|
||||||
|
namespace: "production"
|
||||||
|
# ...
|
||||||
|
```
|
||||||
|
|
||||||
|
```toml tab="File (TOML)"
|
||||||
|
[providers.consulCatalog]
|
||||||
|
namespace = "production"
|
||||||
|
# ...
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash tab="CLI"
|
||||||
|
--providers.consulcatalog.namespace=production
|
||||||
|
# ...
|
||||||
|
```
|
||||||
|
|
|
@ -432,6 +432,9 @@ Token is used to provide a per-request ACL token which overrides the agent's def
|
||||||
`--providers.consulcatalog.exposedbydefault`:
|
`--providers.consulcatalog.exposedbydefault`:
|
||||||
Expose containers by default. (Default: ```true```)
|
Expose containers by default. (Default: ```true```)
|
||||||
|
|
||||||
|
`--providers.consulcatalog.namespace`:
|
||||||
|
Sets the namespace used to discover services (Consul Enterprise only).
|
||||||
|
|
||||||
`--providers.consulcatalog.prefix`:
|
`--providers.consulcatalog.prefix`:
|
||||||
Prefix for consul service tags. Default 'traefik' (Default: ```traefik```)
|
Prefix for consul service tags. Default 'traefik' (Default: ```traefik```)
|
||||||
|
|
||||||
|
|
|
@ -405,6 +405,9 @@ Token is used to provide a per-request ACL token which overrides the agent's def
|
||||||
`TRAEFIK_PROVIDERS_CONSULCATALOG_EXPOSEDBYDEFAULT`:
|
`TRAEFIK_PROVIDERS_CONSULCATALOG_EXPOSEDBYDEFAULT`:
|
||||||
Expose containers by default. (Default: ```true```)
|
Expose containers by default. (Default: ```true```)
|
||||||
|
|
||||||
|
`TRAEFIK_PROVIDERS_CONSULCATALOG_NAMESPACE`:
|
||||||
|
Sets the namespace used to discover services (Consul Enterprise only).
|
||||||
|
|
||||||
`TRAEFIK_PROVIDERS_CONSULCATALOG_PREFIX`:
|
`TRAEFIK_PROVIDERS_CONSULCATALOG_PREFIX`:
|
||||||
Prefix for consul service tags. Default 'traefik' (Default: ```traefik```)
|
Prefix for consul service tags. Default 'traefik' (Default: ```traefik```)
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,7 @@
|
||||||
cache = true
|
cache = true
|
||||||
exposedByDefault = true
|
exposedByDefault = true
|
||||||
defaultRule = "foobar"
|
defaultRule = "foobar"
|
||||||
|
namespace = "foobar"
|
||||||
[providers.consulCatalog.endpoint]
|
[providers.consulCatalog.endpoint]
|
||||||
address = "foobar"
|
address = "foobar"
|
||||||
scheme = "foobar"
|
scheme = "foobar"
|
||||||
|
|
|
@ -160,6 +160,7 @@ providers:
|
||||||
cache: true
|
cache: true
|
||||||
exposedByDefault: true
|
exposedByDefault: true
|
||||||
defaultRule: foobar
|
defaultRule: foobar
|
||||||
|
namespace: foobar
|
||||||
endpoint:
|
endpoint:
|
||||||
address: foobar
|
address: foobar
|
||||||
scheme: foobar
|
scheme: foobar
|
||||||
|
|
|
@ -55,6 +55,7 @@ type Provider struct {
|
||||||
ConnectAware bool `description:"Enable Consul Connect support." json:"connectAware,omitempty" toml:"connectAware,omitempty" yaml:"connectAware,omitempty" export:"true"`
|
ConnectAware bool `description:"Enable Consul Connect support." json:"connectAware,omitempty" toml:"connectAware,omitempty" yaml:"connectAware,omitempty" export:"true"`
|
||||||
ConnectByDefault bool `description:"Consider every service as Connect capable by default." json:"connectByDefault,omitempty" toml:"connectByDefault,omitempty" yaml:"connectByDefault,omitempty" export:"true"`
|
ConnectByDefault bool `description:"Consider every service as Connect capable by default." json:"connectByDefault,omitempty" toml:"connectByDefault,omitempty" yaml:"connectByDefault,omitempty" export:"true"`
|
||||||
ServiceName string `description:"Name of the Traefik service in Consul Catalog (needs to be registered via the orchestrator or manually)." json:"serviceName,omitempty" toml:"serviceName,omitempty" yaml:"serviceName,omitempty" export:"true"`
|
ServiceName string `description:"Name of the Traefik service in Consul Catalog (needs to be registered via the orchestrator or manually)." json:"serviceName,omitempty" toml:"serviceName,omitempty" yaml:"serviceName,omitempty" export:"true"`
|
||||||
|
Namespace string `description:"Sets the namespace used to discover services (Consul Enterprise only)." json:"namespace,omitempty" toml:"namespace,omitempty" yaml:"namespace,omitempty" export:"true"`
|
||||||
|
|
||||||
client *api.Client
|
client *api.Client
|
||||||
defaultRuleTpl *template.Template
|
defaultRuleTpl *template.Template
|
||||||
|
@ -202,7 +203,9 @@ 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}
|
opts := &api.QueryOptions{AllowStale: p.Stale, RequireConsistent: p.RequireConsistent, UseCache: p.Cache, Namespace: p.Namespace}
|
||||||
|
opts = opts.WithContext(ctx)
|
||||||
|
|
||||||
serviceNames, _, err := p.client.Catalog().Services(opts)
|
serviceNames, _, err := p.client.Catalog().Services(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -293,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}
|
opts := &api.QueryOptions{AllowStale: p.Stale, RequireConsistent: p.RequireConsistent, UseCache: p.Cache, Namespace: p.Namespace}
|
||||||
opts = opts.WithContext(ctx)
|
opts = opts.WithContext(ctx)
|
||||||
|
|
||||||
catalogFunc := p.client.Catalog().Service
|
catalogFunc := p.client.Catalog().Service
|
||||||
|
|
Loading…
Reference in a new issue