Add health check label to ECS
This commit is contained in:
parent
4b91204686
commit
6d2f4a0813
7 changed files with 111 additions and 26 deletions
|
@ -195,6 +195,9 @@ func (p *Provider) generateECSConfig(services map[string][]ecsInstance) (*types.
|
|||
"getPassHostHeader": p.getPassHostHeader,
|
||||
"getPriority": p.getPriority,
|
||||
"getEntryPoints": p.getEntryPoints,
|
||||
"hasHealthCheckLabels": p.hasHealthCheckLabels,
|
||||
"getHealthCheckPath": p.getHealthCheckPath,
|
||||
"getHealthCheckInterval": p.getHealthCheckInterval,
|
||||
}
|
||||
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
|
||||
Services map[string][]ecsInstance
|
||||
|
@ -526,6 +529,18 @@ func (p *Provider) getLoadBalancerMethod(instances []ecsInstance) string {
|
|||
return "wrr"
|
||||
}
|
||||
|
||||
func (p *Provider) hasHealthCheckLabels(instances []ecsInstance) bool {
|
||||
return p.getHealthCheckPath(instances) != ""
|
||||
}
|
||||
|
||||
func (p *Provider) getHealthCheckPath(instances []ecsInstance) string {
|
||||
return p.getFirstInstanceLabel(instances, types.LabelBackendHealthcheckPath)
|
||||
}
|
||||
|
||||
func (p *Provider) getHealthCheckInterval(instances []ecsInstance) string {
|
||||
return p.getFirstInstanceLabel(instances, types.LabelBackendHealthcheckInterval)
|
||||
}
|
||||
|
||||
// Provider expects no more than 100 parameters be passed to a DescribeTask call; thus, pack
|
||||
// each string into an array capped at 100 elements
|
||||
func (p *Provider) chunkedTaskArns(tasks []*string) [][]*string {
|
||||
|
|
|
@ -643,6 +643,65 @@ func TestGenerateECSConfig(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
desc: "config parsed successfully with health check labels",
|
||||
services: map[string][]ecsInstance{
|
||||
"testing": {
|
||||
{
|
||||
Name: "instance-1",
|
||||
containerDefinition: &ecs.ContainerDefinition{
|
||||
DockerLabels: map[string]*string{
|
||||
types.LabelBackendHealthcheckPath: func(s string) *string { return &s }("/health"),
|
||||
types.LabelBackendHealthcheckInterval: func(s string) *string { return &s }("1s"),
|
||||
},
|
||||
},
|
||||
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",
|
||||
},
|
||||
HealthCheck: &types.HealthCheck{
|
||||
Path: "/health",
|
||||
Interval: "1s",
|
||||
},
|
||||
},
|
||||
},
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue