1
0
Fork 0

Allow binding ECS container port

This commit is contained in:
Andrew Stucki 2018-07-04 08:08:03 -05:00 committed by Traefiker Bot
parent 12c713b187
commit 0d262561d1
5 changed files with 89 additions and 28 deletions

View file

@ -48,11 +48,16 @@ type ecsInstance struct {
TraefikLabels map[string]string
}
type portMapping struct {
containerPort int64
hostPort int64
}
type machine struct {
name string
state string
privateIP string
port int64
ports []portMapping
}
type awsClient struct {
@ -203,8 +208,7 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI
} else if p.Cluster != "" {
// TODO: Deprecated configuration - Need to be removed in the future
clusters = Clusters{p.Cluster}
log.Warn("Deprecated configuration found: ecs.cluster " +
"Please use ecs.clusters instead.")
log.Warn("Deprecated configuration found: ecs.cluster. Please use ecs.clusters instead.")
} else {
clusters = p.Clusters
}
@ -280,23 +284,33 @@ func (p *Provider) listInstances(ctx context.Context, client *awsClient) ([]ecsI
var mach *machine
if aws.StringValue(task.LaunchType) == ecs.LaunchTypeFargate {
var hostPort int64
if len(containerDefinition.PortMappings) > 0 && containerDefinition.PortMappings[0] != nil {
hostPort = aws.Int64Value(containerDefinition.PortMappings[0].HostPort)
var ports []portMapping
for _, mapping := range containerDefinition.PortMappings {
if mapping != nil {
ports = append(ports, portMapping{
hostPort: aws.Int64Value(mapping.HostPort),
containerPort: aws.Int64Value(mapping.ContainerPort),
})
}
}
mach = &machine{
privateIP: aws.StringValue(container.NetworkInterfaces[0].PrivateIpv4Address),
port: hostPort,
ports: ports,
state: aws.StringValue(task.LastStatus),
}
} else {
var hostPort int64
if len(container.NetworkBindings) > 0 && container.NetworkBindings[0] != nil {
hostPort = aws.Int64Value(container.NetworkBindings[0].HostPort)
var ports []portMapping
for _, mapping := range container.NetworkBindings {
if mapping != nil {
ports = append(ports, portMapping{
hostPort: aws.Int64Value(mapping.HostPort),
containerPort: aws.Int64Value(mapping.ContainerPort),
})
}
}
mach = &machine{
privateIP: aws.StringValue(containerInstance.PrivateIpAddress),
port: hostPort,
ports: ports,
state: aws.StringValue(containerInstance.State.Name),
}
}