mirror of
https://github.com/containous/traefik.git
synced 2024-12-22 13:34:03 +03:00
Add missing functions for ECS template
This commit is contained in:
parent
a0c72cdf00
commit
7c4353a0ac
@ -178,7 +178,8 @@ func wrapAws(ctx context.Context, req *request.Request) error {
|
||||
return req.Send()
|
||||
}
|
||||
|
||||
func (p *Provider) loadECSConfig(ctx context.Context, client *awsClient) (*types.Configuration, error) {
|
||||
// generateECSConfig fills the config template with the given instances
|
||||
func (p *Provider) generateECSConfig(services map[string][]ecsInstance) (*types.Configuration, error) {
|
||||
var ecsFuncMap = template.FuncMap{
|
||||
"filterFrontends": p.filterFrontends,
|
||||
"getFrontendRule": p.getFrontendRule,
|
||||
@ -187,8 +188,22 @@ func (p *Provider) loadECSConfig(ctx context.Context, client *awsClient) (*types
|
||||
"getLoadBalancerSticky": p.getLoadBalancerSticky,
|
||||
"hasStickinessLabel": p.hasStickinessLabel,
|
||||
"getStickinessCookieName": p.getStickinessCookieName,
|
||||
"getProtocol": p.getProtocol,
|
||||
"getHost": p.getHost,
|
||||
"getPort": p.getPort,
|
||||
"getWeight": p.getWeight,
|
||||
"getPassHostHeader": p.getPassHostHeader,
|
||||
"getPriority": p.getPriority,
|
||||
"getEntryPoints": p.getEntryPoints,
|
||||
}
|
||||
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
|
||||
Services map[string][]ecsInstance
|
||||
}{
|
||||
services,
|
||||
})
|
||||
}
|
||||
|
||||
func (p *Provider) loadECSConfig(ctx context.Context, client *awsClient) (*types.Configuration, error) {
|
||||
instances, err := p.listInstances(ctx, client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -205,12 +220,7 @@ func (p *Provider) loadECSConfig(ctx context.Context, client *awsClient) (*types
|
||||
services[instance.Name] = []ecsInstance{instance}
|
||||
}
|
||||
}
|
||||
|
||||
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
|
||||
Services map[string][]ecsInstance
|
||||
}{
|
||||
services,
|
||||
})
|
||||
return p.generateECSConfig(services)
|
||||
}
|
||||
|
||||
// Find all running Provider tasks in a cluster, also collect the task definitions (for docker labels)
|
||||
|
@ -552,3 +552,74 @@ func TestEcsGetBasicAuth(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateECSConfig(t *testing.T) {
|
||||
provider := &Provider{}
|
||||
tests := []struct {
|
||||
desc string
|
||||
services map[string][]ecsInstance
|
||||
exp *types.Configuration
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "config parsed successfully",
|
||||
services: map[string][]ecsInstance{
|
||||
"testing": {
|
||||
{
|
||||
Name: "instance-1",
|
||||
containerDefinition: &ecs.ContainerDefinition{
|
||||
DockerLabels: map[string]*string{},
|
||||
},
|
||||
machine: &ec2.Instance{
|
||||
PrivateIpAddress: func(s string) *string { return &s }("10.0.0.1"),
|
||||
},
|
||||
container: &ecs.Container{
|
||||
NetworkBindings: []*ecs.NetworkBinding{
|
||||
{
|
||||
HostPort: func(i int64) *int64 { return &i }(1337),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
exp: &types.Configuration{
|
||||
Backends: map[string]*types.Backend{
|
||||
"backend-instance-1": {
|
||||
Servers: map[string]types.Server{
|
||||
"server-instance-1": {
|
||||
URL: "http://10.0.0.1:1337",
|
||||
},
|
||||
},
|
||||
},
|
||||
"backend-testing": {
|
||||
LoadBalancer: &types.LoadBalancer{
|
||||
Method: "wrr",
|
||||
},
|
||||
},
|
||||
},
|
||||
Frontends: map[string]*types.Frontend{
|
||||
"frontend-testing": {
|
||||
EntryPoints: []string{},
|
||||
Backend: "backend-testing",
|
||||
Routes: map[string]types.Route{
|
||||
"route-frontend-testing": {
|
||||
Rule: "Host:instance-1.",
|
||||
},
|
||||
},
|
||||
PassHostHeader: true,
|
||||
BasicAuth: []string{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
got, err := provider.generateECSConfig(test.services)
|
||||
assert.Equal(t, test.err, err)
|
||||
assert.Equal(t, test.exp, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user