feat(ecs): add HealthCheck port label.

This commit is contained in:
Fernandez Ludovic 2017-12-16 19:29:30 +01:00 committed by Traefiker
parent f195ef27f3
commit 722ea28e3a
2 changed files with 24 additions and 0 deletions

View file

@ -30,6 +30,7 @@ func (p *Provider) buildConfiguration(services map[string][]ecsInstance) (*types
"getEntryPoints": getFuncSliceString(label.TraefikFrontendEntryPoints),
"hasHealthCheckLabels": hasFuncFirst(label.TraefikBackendHealthCheckPath),
"getHealthCheckPath": getFuncFirstStringValue(label.TraefikBackendHealthCheckPath, ""),
"getHealthCheckPort": getFuncFirstIntValue(label.TraefikBackendHealthCheckPort, label.DefaultBackendHealthCheckPort),
"getHealthCheckInterval": getFuncFirstStringValue(label.TraefikBackendHealthCheckInterval, ""),
}
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
@ -102,6 +103,15 @@ func getFuncFirstStringValue(labelName string, defaultValue string) func(instanc
}
}
func getFuncFirstIntValue(labelName string, defaultValue int) func(instances []ecsInstance) int {
return func(instances []ecsInstance) int {
if len(instances) < 0 {
return defaultValue
}
return getIntValue(instances[0], labelName, defaultValue)
}
}
func getFuncFirstBoolValue(labelName string, defaultValue bool) func(instances []ecsInstance) bool {
return func(instances []ecsInstance) bool {
if len(instances) < 0 {
@ -137,6 +147,19 @@ func getBoolValue(i ecsInstance, labelName string, defaultValue bool) bool {
return defaultValue
}
func getIntValue(i ecsInstance, labelName string, defaultValue int) int {
rawValue, ok := i.containerDefinition.DockerLabels[labelName]
if ok {
if rawValue != nil {
v, err := strconv.Atoi(*rawValue)
if err == nil {
return v
}
}
}
return defaultValue
}
func getSliceString(i ecsInstance, labelName string) []string {
if value, ok := i.containerDefinition.DockerLabels[labelName]; ok {
if value == nil {

View file

@ -12,6 +12,7 @@
{{ if hasHealthCheckLabels $instances }}
[backends.backend-{{ $serviceName }}.healthCheck]
path = "{{getHealthCheckPath $instances }}"
port = {{getHealthCheckPort $instances}}
interval = "{{getHealthCheckInterval $instances }}"
{{end}}