Factorize labels managements.
This commit is contained in:
parent
21f6f81914
commit
f804053736
6 changed files with 192 additions and 137 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"text/template"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/containous/traefik/log"
|
||||
"github.com/containous/traefik/provider/label"
|
||||
"github.com/containous/traefik/types"
|
||||
|
@ -12,7 +13,18 @@ import (
|
|||
|
||||
// buildConfiguration fills the config template with the given instances
|
||||
// Deprecated
|
||||
func (p *Provider) buildConfigurationV1(services map[string][]ecsInstance) (*types.Configuration, error) {
|
||||
func (p *Provider) buildConfigurationV1(instances []ecsInstance) (*types.Configuration, error) {
|
||||
services := make(map[string][]ecsInstance)
|
||||
for _, instance := range instances {
|
||||
if p.filterInstanceV1(instance) {
|
||||
if serviceInstances, ok := services[instance.Name]; ok {
|
||||
services[instance.Name] = append(serviceInstances, instance)
|
||||
} else {
|
||||
services[instance.Name] = []ecsInstance{instance}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var ecsFuncMap = template.FuncMap{
|
||||
// Backend functions
|
||||
"getHost": getHost,
|
||||
|
@ -45,6 +57,35 @@ func (p *Provider) buildConfigurationV1(services map[string][]ecsInstance) (*typ
|
|||
})
|
||||
}
|
||||
|
||||
func (p *Provider) filterInstanceV1(i ecsInstance) bool {
|
||||
if labelPort := getStringValueV1(i, label.TraefikPort, ""); len(i.container.NetworkBindings) == 0 && labelPort == "" {
|
||||
log.Debugf("Filtering ecs instance without port %s (%s)", i.Name, i.ID)
|
||||
return false
|
||||
}
|
||||
|
||||
if i.machine == nil || i.machine.State == nil || i.machine.State.Name == nil {
|
||||
log.Debugf("Filtering ecs instance in an missing ec2 information %s (%s)", i.Name, i.ID)
|
||||
return false
|
||||
}
|
||||
|
||||
if aws.StringValue(i.machine.State.Name) != ec2.InstanceStateNameRunning {
|
||||
log.Debugf("Filtering ecs instance in an incorrect state %s (%s) (state = %s)", i.Name, i.ID, aws.StringValue(i.machine.State.Name))
|
||||
return false
|
||||
}
|
||||
|
||||
if i.machine.PrivateIpAddress == nil {
|
||||
log.Debugf("Filtering ecs instance without an ip address %s (%s)", i.Name, i.ID)
|
||||
return false
|
||||
}
|
||||
|
||||
if !isEnabled(i, p.ExposedByDefault) {
|
||||
log.Debugf("Filtering disabled ecs instance %s (%s)", i.Name, i.ID)
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// TODO: Deprecated
|
||||
// replaced by Stickiness
|
||||
// Deprecated
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue