mirror of
https://github.com/docker/compose.git
synced 2025-07-27 15:44:08 +02:00
LoadBalancer names cannot be longer then 32 characters..
Longer names will fail with: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: ValidationError; Fairly straight forward approach, truncate at 32 characters. Considering that we append "LoadBalancer" to every name and it is 12 characters the name should stay useful. We can decide later if "LB" is better then a truncated "LoadBalan". The golden test data needed to be updated because its names were also over 32 characters. Fixes #160. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
8ab544a770
commit
b2a9019700
@ -218,7 +218,9 @@ func getLoadBalancerSecurityGroups(project *types.Project, template *cloudformat
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createLoadBalancer(project *types.Project, template *cloudformation.Template) string {
|
func createLoadBalancer(project *types.Project, template *cloudformation.Template) string {
|
||||||
loadBalancerName := fmt.Sprintf("%sLoadBalancer", strings.Title(project.Name))
|
|
||||||
|
// load balancer names are limited to 32 characters total
|
||||||
|
loadBalancerName := fmt.Sprintf("%.32s", fmt.Sprintf("%sLoadBalancer", strings.Title(project.Name)))
|
||||||
// Create LoadBalancer if `ParameterLoadBalancerName` is not set
|
// Create LoadBalancer if `ParameterLoadBalancerName` is not set
|
||||||
template.Conditions["CreateLoadBalancer"] = cloudformation.Equals("", cloudformation.Ref(ParameterLoadBalancerARN))
|
template.Conditions["CreateLoadBalancer"] = cloudformation.Equals("", cloudformation.Ref(ParameterLoadBalancerARN))
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ func TestSimpleWithOverrides(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRolePolicy(t *testing.T) {
|
func TestRolePolicy(t *testing.T) {
|
||||||
template := convertYaml(t, `
|
template := convertYaml(t, "test", `
|
||||||
version: "3"
|
version: "3"
|
||||||
services:
|
services:
|
||||||
foo:
|
foo:
|
||||||
@ -54,14 +54,14 @@ services:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMapNetworksToSecurityGroups(t *testing.T) {
|
func TestMapNetworksToSecurityGroups(t *testing.T) {
|
||||||
template := convertYaml(t, `
|
template := convertYaml(t, "test", `
|
||||||
version: "3"
|
version: "3"
|
||||||
services:
|
services:
|
||||||
test:
|
test:
|
||||||
image: hello_world
|
image: hello_world
|
||||||
networks:
|
networks:
|
||||||
- front-tier
|
- front-tier
|
||||||
- back-tier
|
- back-tier
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
front-tier:
|
front-tier:
|
||||||
@ -79,7 +79,7 @@ networks:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadBalancerTypeApplication(t *testing.T) {
|
func TestLoadBalancerTypeApplication(t *testing.T) {
|
||||||
template := convertYaml(t, `
|
template := convertYaml(t, "test123456789009876543211234567890", `
|
||||||
version: "3"
|
version: "3"
|
||||||
services:
|
services:
|
||||||
test:
|
test:
|
||||||
@ -89,12 +89,13 @@ services:
|
|||||||
`)
|
`)
|
||||||
lb := template.Resources["TestLoadBalancer"].(*elasticloadbalancingv2.LoadBalancer)
|
lb := template.Resources["TestLoadBalancer"].(*elasticloadbalancingv2.LoadBalancer)
|
||||||
assert.Check(t, lb != nil)
|
assert.Check(t, lb != nil)
|
||||||
|
assert.Check(t, len(lb.Name) <= 32)
|
||||||
assert.Check(t, lb.Type == elbv2.LoadBalancerTypeEnumApplication)
|
assert.Check(t, lb.Type == elbv2.LoadBalancerTypeEnumApplication)
|
||||||
assert.Check(t, len(lb.SecurityGroups) > 0)
|
assert.Check(t, len(lb.SecurityGroups) > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServiceReplicas(t *testing.T) {
|
func TestServiceReplicas(t *testing.T) {
|
||||||
template := convertYaml(t, `
|
template := convertYaml(t, "test", `
|
||||||
version: "3"
|
version: "3"
|
||||||
services:
|
services:
|
||||||
test:
|
test:
|
||||||
@ -108,7 +109,7 @@ services:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadBalancerTypeNetwork(t *testing.T) {
|
func TestLoadBalancerTypeNetwork(t *testing.T) {
|
||||||
template := convertYaml(t, `
|
template := convertYaml(t, "test", `
|
||||||
version: "3"
|
version: "3"
|
||||||
services:
|
services:
|
||||||
test:
|
test:
|
||||||
@ -123,7 +124,7 @@ services:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestServiceMapping(t *testing.T) {
|
func TestServiceMapping(t *testing.T) {
|
||||||
template := convertYaml(t, `
|
template := convertYaml(t, "test", `
|
||||||
version: "3"
|
version: "3"
|
||||||
services:
|
services:
|
||||||
test:
|
test:
|
||||||
@ -163,7 +164,7 @@ func get(l []ecs.TaskDefinition_KeyValuePair, name string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestResourcesHaveProjectTagSet(t *testing.T) {
|
func TestResourcesHaveProjectTagSet(t *testing.T) {
|
||||||
template := convertYaml(t, `
|
template := convertYaml(t, "test", `
|
||||||
version: "3"
|
version: "3"
|
||||||
services:
|
services:
|
||||||
test:
|
test:
|
||||||
@ -207,7 +208,7 @@ func load(t *testing.T, paths ...string) *types.Project {
|
|||||||
return project
|
return project
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertYaml(t *testing.T, yaml string) *cloudformation.Template {
|
func convertYaml(t *testing.T, name string, yaml string) *cloudformation.Template {
|
||||||
dict, err := loader.ParseYAML([]byte(yaml))
|
dict, err := loader.ParseYAML([]byte(yaml))
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
model, err := loader.Load(types.ConfigDetails{
|
model, err := loader.Load(types.ConfigDetails{
|
||||||
|
@ -260,10 +260,10 @@
|
|||||||
},
|
},
|
||||||
"Type": "AWS::EC2::SecurityGroupIngress"
|
"Type": "AWS::EC2::SecurityGroupIngress"
|
||||||
},
|
},
|
||||||
"TestSimpleWithOverridesLoadBalancer": {
|
"TestSimpleWithOverridesLoadBalan": {
|
||||||
"Condition": "CreateLoadBalancer",
|
"Condition": "CreateLoadBalancer",
|
||||||
"Properties": {
|
"Properties": {
|
||||||
"Name": "TestSimpleWithOverridesLoadBalancer",
|
"Name": "TestSimpleWithOverridesLoadBalan",
|
||||||
"Scheme": "internet-facing",
|
"Scheme": "internet-facing",
|
||||||
"SecurityGroups": [
|
"SecurityGroups": [
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user