feat(rancher): add HealthCheck labels.

This commit is contained in:
Fernandez Ludovic 2017-12-16 14:21:33 +01:00 committed by Traefiker
parent c884c7bb8a
commit a1f47cb4db
2 changed files with 17 additions and 0 deletions

View file

@ -41,6 +41,10 @@ func (p *Provider) buildConfiguration(services []rancherData) *types.Configurati
"getRedirectRegex": getFuncString(label.TraefikFrontendRedirectRegex, ""), "getRedirectRegex": getFuncString(label.TraefikFrontendRedirectRegex, ""),
"getRedirectReplacement": getFuncString(label.TraefikFrontendRedirectReplacement, ""), "getRedirectReplacement": getFuncString(label.TraefikFrontendRedirectReplacement, ""),
"getWhitelistSourceRange": getFuncSliceString(label.TraefikFrontendWhitelistSourceRange), "getWhitelistSourceRange": getFuncSliceString(label.TraefikFrontendWhitelistSourceRange),
"hasHealthCheckLabels": hasFunc(label.TraefikBackendHealthCheckPath),
"getHealthCheckPath": getFuncString(label.TraefikBackendHealthCheckPath, ""),
"getHealthCheckPort": getFuncInt(label.TraefikBackendHealthCheckPort, label.DefaultBackendHealthCheckPort),
"getHealthCheckInterval": getFuncString(label.TraefikBackendHealthCheckInterval, ""),
} }
// filter services // filter services
@ -162,6 +166,12 @@ func getFuncString(labelName string, defaultValue string) func(service rancherDa
} }
} }
func getFuncInt(labelName string, defaultValue int) func(service rancherData) int {
return func(service rancherData) int {
return label.GetIntValue(service.Labels, labelName, defaultValue)
}
}
func getFuncBool(labelName string, defaultValue bool) func(service rancherData) bool { func getFuncBool(labelName string, defaultValue bool) func(service rancherData) bool {
return func(service rancherData) bool { return func(service rancherData) bool {
return label.GetBoolValue(service.Labels, labelName, defaultValue) return label.GetBoolValue(service.Labels, labelName, defaultValue)

View file

@ -23,6 +23,13 @@
extractorFunc = "{{getMaxConnExtractorFunc $backend}}" extractorFunc = "{{getMaxConnExtractorFunc $backend}}"
{{end}} {{end}}
{{if hasHealthCheckLabels $backend}}
[backends.backend-{{$backendName}}.healthCheck]
path = "{{getHealthCheckPath $backend}}"
port = {{getHealthCheckPort $backend}}
interval = "{{getHealthCheckInterval $backend}}"
{{end}}
{{range $index, $ip := $backend.Containers}} {{range $index, $ip := $backend.Containers}}
[backends.backend-{{$backendName}}.servers.server-{{$index}}] [backends.backend-{{$backendName}}.servers.server-{{$index}}]
url = "{{getProtocol $backend}}://{{$ip}}:{{getPort $backend}}" url = "{{getProtocol $backend}}://{{$ip}}:{{getPort $backend}}"