1
0
Fork 0

Support Host NetworkMode for ECS provider

This commit is contained in:
Félix P 2017-10-31 11:44:03 +01:00 committed by Traefiker
parent e8d63b2a3b
commit 93a46089ce
3 changed files with 70 additions and 1 deletions

View file

@ -57,6 +57,14 @@ func simpleEcsInstance(labels map[string]*string) ecsInstance {
})
}
func simpleEcsInstanceNoNetwork(labels map[string]*string) ecsInstance {
return makeEcsInstance(&ecs.ContainerDefinition{
Name: aws.String("http"),
PortMappings: []*ecs.PortMapping{},
DockerLabels: labels,
})
}
func TestEcsProtocol(t *testing.T) {
tests := []struct {
desc string
@ -337,6 +345,12 @@ func TestFilterInstance(t *testing.T) {
invalidMachineState := simpleEcsInstance(map[string]*string{})
invalidMachineState.machine.State.Name = aws.String(ec2.InstanceStateNameStopped)
noNetwork := simpleEcsInstanceNoNetwork(map[string]*string{})
noNetworkWithLabel := simpleEcsInstanceNoNetwork(map[string]*string{
types.LabelPort: aws.String("80"),
})
tests := []struct {
desc string
expected bool
@ -419,6 +433,22 @@ func TestFilterInstance(t *testing.T) {
ExposedByDefault: true,
},
},
{
desc: "Instance with no port mappings should be filtered",
expected: false,
instanceInfo: noNetwork,
provider: &Provider{
ExposedByDefault: true,
},
},
{
desc: "Instance with no port mapping and with label should not be filtered",
expected: true,
instanceInfo: noNetworkWithLabel,
provider: &Provider{
ExposedByDefault: true,
},
},
}
for _, test := range tests {
@ -623,3 +653,38 @@ func TestGenerateECSConfig(t *testing.T) {
})
}
}
func TestEcsWithoutPort(t *testing.T) {
tests := []struct {
desc string
expected string
instanceInfo ecsInstance
provider *Provider
}{
{
desc: "Label should override network port",
expected: "4242",
instanceInfo: simpleEcsInstance(map[string]*string{
types.LabelPort: aws.String("4242"),
}),
provider: &Provider{},
},
{
desc: "Label should provide exposed port",
expected: "80",
instanceInfo: simpleEcsInstanceNoNetwork(map[string]*string{
types.LabelPort: aws.String("80"),
}),
provider: &Provider{},
},
}
for _, test := range tests {
test := test
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
actual := test.provider.getPort(test.instanceInfo)
assert.Equal(t, test.expected, actual)
})
}
}