Add support for ECS constraints
This commit is contained in:
parent
11691019a0
commit
157e76e829
4 changed files with 35 additions and 0 deletions
|
@ -102,6 +102,8 @@ If `accessKeyID`/`secretAccessKey` is not given credentials will be resolved in
|
||||||
- Shared credentials, determined by `AWS_PROFILE` and `AWS_SHARED_CREDENTIALS_FILE`, defaults to `default` and `~/.aws/credentials`.
|
- Shared credentials, determined by `AWS_PROFILE` and `AWS_SHARED_CREDENTIALS_FILE`, defaults to `default` and `~/.aws/credentials`.
|
||||||
- EC2 instance role or ECS task role
|
- EC2 instance role or ECS task role
|
||||||
|
|
||||||
|
To enable constraints see [provider-specific constraints section](/configuration/commons/#provider-specific).
|
||||||
|
|
||||||
## Policy
|
## Policy
|
||||||
|
|
||||||
Træfik needs the following policy to read ECS information:
|
Træfik needs the following policy to read ECS information:
|
||||||
|
|
|
@ -144,6 +144,7 @@ Supported Providers:
|
||||||
- Consul K/V
|
- Consul K/V
|
||||||
- BoltDB
|
- BoltDB
|
||||||
- Zookeeper
|
- Zookeeper
|
||||||
|
- ECS
|
||||||
- Etcd
|
- Etcd
|
||||||
- Consul Catalog
|
- Consul Catalog
|
||||||
- Rancher
|
- Rancher
|
||||||
|
|
|
@ -87,6 +87,14 @@ func (p *Provider) filterInstance(i ecsInstance) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constraintTags := label.GetSliceStringValue(i.TraefikLabels, label.TraefikTags)
|
||||||
|
if ok, failingConstraint := p.MatchConstraints(constraintTags); !ok {
|
||||||
|
if failingConstraint != nil {
|
||||||
|
log.Debugf("Filtering ecs instance pruned by constraint %s (%s) (constraint = %q)", i.Name, i.ID, failingConstraint.String())
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -372,6 +372,7 @@ func TestFilterInstance(t *testing.T) {
|
||||||
instanceInfo ecsInstance
|
instanceInfo ecsInstance
|
||||||
exposedByDefault bool
|
exposedByDefault bool
|
||||||
expected bool
|
expected bool
|
||||||
|
constrain bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Instance without enable label and exposed by default enabled should be not filtered",
|
desc: "Instance without enable label and exposed by default enabled should be not filtered",
|
||||||
|
@ -455,6 +456,24 @@ func TestFilterInstance(t *testing.T) {
|
||||||
exposedByDefault: true,
|
exposedByDefault: true,
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "Instance with failing constraint should be filtered",
|
||||||
|
instanceInfo: simpleEcsInstance(map[string]*string{
|
||||||
|
label.TraefikTags: aws.String("private"),
|
||||||
|
}),
|
||||||
|
exposedByDefault: true,
|
||||||
|
expected: false,
|
||||||
|
constrain: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "Instance with passing constraint should not be filtered",
|
||||||
|
instanceInfo: simpleEcsInstance(map[string]*string{
|
||||||
|
label.TraefikTags: aws.String("public"),
|
||||||
|
}),
|
||||||
|
exposedByDefault: true,
|
||||||
|
expected: true,
|
||||||
|
constrain: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
|
@ -465,6 +484,11 @@ func TestFilterInstance(t *testing.T) {
|
||||||
prov := &Provider{
|
prov := &Provider{
|
||||||
ExposedByDefault: test.exposedByDefault,
|
ExposedByDefault: test.exposedByDefault,
|
||||||
}
|
}
|
||||||
|
if test.constrain {
|
||||||
|
constraints := types.Constraints{}
|
||||||
|
assert.NoError(t, constraints.Set("tag==public"))
|
||||||
|
prov.Constraints = constraints
|
||||||
|
}
|
||||||
|
|
||||||
actual := prov.filterInstance(test.instanceInfo)
|
actual := prov.filterInstance(test.instanceInfo)
|
||||||
assert.Equal(t, test.expected, actual)
|
assert.Equal(t, test.expected, actual)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue