From a1f47cb4dbf1dd13dc20d03b1134de9ae61c920b Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sat, 16 Dec 2017 14:21:33 +0100 Subject: [PATCH] feat(rancher): add HealthCheck labels. --- provider/rancher/config.go | 10 ++++++++++ templates/rancher.tmpl | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/provider/rancher/config.go b/provider/rancher/config.go index 295658f42..9359fbea1 100644 --- a/provider/rancher/config.go +++ b/provider/rancher/config.go @@ -41,6 +41,10 @@ func (p *Provider) buildConfiguration(services []rancherData) *types.Configurati "getRedirectRegex": getFuncString(label.TraefikFrontendRedirectRegex, ""), "getRedirectReplacement": getFuncString(label.TraefikFrontendRedirectReplacement, ""), "getWhitelistSourceRange": getFuncSliceString(label.TraefikFrontendWhitelistSourceRange), + "hasHealthCheckLabels": hasFunc(label.TraefikBackendHealthCheckPath), + "getHealthCheckPath": getFuncString(label.TraefikBackendHealthCheckPath, ""), + "getHealthCheckPort": getFuncInt(label.TraefikBackendHealthCheckPort, label.DefaultBackendHealthCheckPort), + "getHealthCheckInterval": getFuncString(label.TraefikBackendHealthCheckInterval, ""), } // 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 { return func(service rancherData) bool { return label.GetBoolValue(service.Labels, labelName, defaultValue) diff --git a/templates/rancher.tmpl b/templates/rancher.tmpl index 3e9f278e3..732d4a267 100644 --- a/templates/rancher.tmpl +++ b/templates/rancher.tmpl @@ -23,6 +23,13 @@ extractorFunc = "{{getMaxConnExtractorFunc $backend}}" {{end}} + {{if hasHealthCheckLabels $backend}} + [backends.backend-{{$backendName}}.healthCheck] + path = "{{getHealthCheckPath $backend}}" + port = {{getHealthCheckPort $backend}} + interval = "{{getHealthCheckInterval $backend}}" + {{end}} + {{range $index, $ip := $backend.Containers}} [backends.backend-{{$backendName}}.servers.server-{{$index}}] url = "{{getProtocol $backend}}://{{$ip}}:{{getPort $backend}}"