Fix missing allow-empty tag on ECS and Consul Catalog providers
Co-authored-by: Kevin Pollet <pollet.kevin@gmail.com>
This commit is contained in:
parent
9177982334
commit
4f43c9ebb4
5 changed files with 38 additions and 34 deletions
|
@ -13,18 +13,15 @@ Attach labels to your ECS containers and let Traefik do the rest!
|
||||||
|
|
||||||
```toml tab="File (TOML)"
|
```toml tab="File (TOML)"
|
||||||
[providers.ecs]
|
[providers.ecs]
|
||||||
clusters = ["default"]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```yaml tab="File (YAML)"
|
```yaml tab="File (YAML)"
|
||||||
providers:
|
providers:
|
||||||
ecs:
|
ecs: {}
|
||||||
clusters:
|
|
||||||
- default
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash tab="CLI"
|
```bash tab="CLI"
|
||||||
--providers.ecs.clusters=default
|
--providers.ecs=true
|
||||||
```
|
```
|
||||||
|
|
||||||
## Policy
|
## Policy
|
||||||
|
|
|
@ -330,6 +330,9 @@ TLS key
|
||||||
`--providers.consul.username`:
|
`--providers.consul.username`:
|
||||||
KV Username
|
KV Username
|
||||||
|
|
||||||
|
`--providers.consulcatalog`:
|
||||||
|
Enable ConsulCatalog backend with default settings. (Default: ```false```)
|
||||||
|
|
||||||
`--providers.consulcatalog.cache`:
|
`--providers.consulcatalog.cache`:
|
||||||
Use local agent caching for catalog reads. (Default: ```false```)
|
Use local agent caching for catalog reads. (Default: ```false```)
|
||||||
|
|
||||||
|
@ -435,6 +438,9 @@ Use the ip address from the bound port, rather than from the inner network. (Def
|
||||||
`--providers.docker.watch`:
|
`--providers.docker.watch`:
|
||||||
Watch Docker Swarm events. (Default: ```true```)
|
Watch Docker Swarm events. (Default: ```true```)
|
||||||
|
|
||||||
|
`--providers.ecs`:
|
||||||
|
Enable AWS ECS backend with default settings. (Default: ```false```)
|
||||||
|
|
||||||
`--providers.ecs.accesskeyid`:
|
`--providers.ecs.accesskeyid`:
|
||||||
The AWS credentials access key to use for making requests
|
The AWS credentials access key to use for making requests
|
||||||
|
|
||||||
|
|
|
@ -303,6 +303,9 @@ Terminating status code (Default: ```503```)
|
||||||
`TRAEFIK_PROVIDERS_CONSUL`:
|
`TRAEFIK_PROVIDERS_CONSUL`:
|
||||||
Enable Consul backend with default settings. (Default: ```false```)
|
Enable Consul backend with default settings. (Default: ```false```)
|
||||||
|
|
||||||
|
`TRAEFIK_PROVIDERS_CONSULCATALOG`:
|
||||||
|
Enable ConsulCatalog backend with default settings. (Default: ```false```)
|
||||||
|
|
||||||
`TRAEFIK_PROVIDERS_CONSULCATALOG_CACHE`:
|
`TRAEFIK_PROVIDERS_CONSULCATALOG_CACHE`:
|
||||||
Use local agent caching for catalog reads. (Default: ```false```)
|
Use local agent caching for catalog reads. (Default: ```false```)
|
||||||
|
|
||||||
|
@ -435,6 +438,9 @@ Use the ip address from the bound port, rather than from the inner network. (Def
|
||||||
`TRAEFIK_PROVIDERS_DOCKER_WATCH`:
|
`TRAEFIK_PROVIDERS_DOCKER_WATCH`:
|
||||||
Watch Docker Swarm events. (Default: ```true```)
|
Watch Docker Swarm events. (Default: ```true```)
|
||||||
|
|
||||||
|
`TRAEFIK_PROVIDERS_ECS`:
|
||||||
|
Enable AWS ECS backend with default settings. (Default: ```false```)
|
||||||
|
|
||||||
`TRAEFIK_PROVIDERS_ECS_ACCESSKEYID`:
|
`TRAEFIK_PROVIDERS_ECS_ACCESSKEYID`:
|
||||||
The AWS credentials access key to use for making requests
|
The AWS credentials access key to use for making requests
|
||||||
|
|
||||||
|
|
|
@ -176,8 +176,8 @@ type Providers struct {
|
||||||
KubernetesCRD *crd.Provider `description:"Enable Kubernetes backend with default settings." json:"kubernetesCRD,omitempty" toml:"kubernetesCRD,omitempty" yaml:"kubernetesCRD,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
KubernetesCRD *crd.Provider `description:"Enable Kubernetes backend with default settings." json:"kubernetesCRD,omitempty" toml:"kubernetesCRD,omitempty" yaml:"kubernetesCRD,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||||
Rest *rest.Provider `description:"Enable Rest backend with default settings." json:"rest,omitempty" toml:"rest,omitempty" yaml:"rest,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
Rest *rest.Provider `description:"Enable Rest backend with default settings." json:"rest,omitempty" toml:"rest,omitempty" yaml:"rest,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||||
Rancher *rancher.Provider `description:"Enable Rancher backend with default settings." json:"rancher,omitempty" toml:"rancher,omitempty" yaml:"rancher,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
Rancher *rancher.Provider `description:"Enable Rancher backend with default settings." json:"rancher,omitempty" toml:"rancher,omitempty" yaml:"rancher,omitempty" export:"true" label:"allowEmpty" file:"allowEmpty"`
|
||||||
ConsulCatalog *consulcatalog.Provider `description:"Enable ConsulCatalog backend with default settings." json:"consulCatalog,omitempty" toml:"consulCatalog,omitempty" yaml:"consulCatalog,omitempty" export:"true"`
|
ConsulCatalog *consulcatalog.Provider `description:"Enable ConsulCatalog backend with default settings." json:"consulCatalog,omitempty" toml:"consulCatalog,omitempty" yaml:"consulCatalog,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||||
Ecs *ecs.Provider `description:"Enable AWS ECS backend with default settings." json:"ecs,omitempty" toml:"ecs,omitempty" yaml:"ecs,omitempty" export:"true"`
|
Ecs *ecs.Provider `description:"Enable AWS ECS backend with default settings." json:"ecs,omitempty" toml:"ecs,omitempty" yaml:"ecs,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||||
|
|
||||||
Consul *consul.Provider `description:"Enable Consul backend with default settings." json:"consul,omitempty" toml:"consul,omitempty" yaml:"consul,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
Consul *consul.Provider `description:"Enable Consul backend with default settings." json:"consul,omitempty" toml:"consul,omitempty" yaml:"consul,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||||
Etcd *etcd.Provider `description:"Enable Etcd backend with default settings." json:"etcd,omitempty" toml:"etcd,omitempty" yaml:"etcd,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
Etcd *etcd.Provider `description:"Enable Etcd backend with default settings." json:"etcd,omitempty" toml:"etcd,omitempty" yaml:"etcd,omitempty" label:"allowEmpty" file:"allowEmpty" export:"true"`
|
||||||
|
|
|
@ -151,35 +151,25 @@ func (p Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.P
|
||||||
operation := func() error {
|
operation := func() error {
|
||||||
awsClient, err := p.createClient(logger)
|
awsClient, err := p.createClient(logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("unable to create AWS client: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration, err := p.loadECSConfig(ctxLog, awsClient)
|
err = p.loadConfiguration(ctxLog, awsClient, configurationChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("failed to get ECS configuration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
configurationChan <- dynamic.Message{
|
ticker := time.NewTicker(time.Second * time.Duration(p.RefreshSeconds))
|
||||||
ProviderName: "ecs",
|
defer ticker.Stop()
|
||||||
Configuration: configuration,
|
|
||||||
}
|
|
||||||
|
|
||||||
reload := time.NewTicker(time.Second * time.Duration(p.RefreshSeconds))
|
|
||||||
defer reload.Stop()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-reload.C:
|
case <-ticker.C:
|
||||||
configuration, err := p.loadECSConfig(ctxLog, awsClient)
|
err = p.loadConfiguration(ctxLog, awsClient, configurationChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Failed to load ECS configuration, error %s", err)
|
return fmt.Errorf("failed to refresh ECS configuration: %w", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configurationChan <- dynamic.Message{
|
|
||||||
ProviderName: "ecs",
|
|
||||||
Configuration: configuration,
|
|
||||||
}
|
|
||||||
case <-routineCtx.Done():
|
case <-routineCtx.Done():
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -198,6 +188,20 @@ func (p Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.P
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Provider) loadConfiguration(ctx context.Context, client *awsClient, configurationChan chan<- dynamic.Message) error {
|
||||||
|
instances, err := p.listInstances(ctx, client)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
configurationChan <- dynamic.Message{
|
||||||
|
ProviderName: "ecs",
|
||||||
|
Configuration: p.buildConfiguration(ctx, instances),
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Find all running Provider tasks in a cluster, also collect the task definitions (for docker labels)
|
// Find all running Provider tasks in a cluster, also collect the task definitions (for docker labels)
|
||||||
// and the EC2 instance data.
|
// and the EC2 instance data.
|
||||||
func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsInstance, error) {
|
func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsInstance, error) {
|
||||||
|
@ -365,15 +369,6 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI
|
||||||
return instances, nil
|
return instances, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) loadECSConfig(ctx context.Context, client *awsClient) (*dynamic.Configuration, error) {
|
|
||||||
instances, err := p.listInstances(ctx, client)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.buildConfiguration(ctx, instances), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Provider) lookupEc2Instances(ctx context.Context, client *awsClient, clusterName *string, ecsDatas map[string]*ecs.Task) (map[string]*ec2.Instance, error) {
|
func (p *Provider) lookupEc2Instances(ctx context.Context, client *awsClient, clusterName *string, ecsDatas map[string]*ecs.Task) (map[string]*ec2.Instance, error) {
|
||||||
logger := log.FromContext(ctx)
|
logger := log.FromContext(ctx)
|
||||||
instanceIds := make(map[string]string)
|
instanceIds := make(map[string]string)
|
||||||
|
|
Loading…
Add table
Reference in a new issue