feat(docker): add HealthCheck labels.
This commit is contained in:
parent
9ee642a7db
commit
c26b9b1a5d
6 changed files with 52 additions and 17 deletions
|
@ -13,23 +13,26 @@ import (
|
||||||
|
|
||||||
func (p *Provider) buildConfiguration(containersInspected []dockerData) *types.Configuration {
|
func (p *Provider) buildConfiguration(containersInspected []dockerData) *types.Configuration {
|
||||||
var DockerFuncMap = template.FuncMap{
|
var DockerFuncMap = template.FuncMap{
|
||||||
"getBackend": getBackend,
|
"getBackend": getBackend,
|
||||||
"getIPAddress": p.getIPAddress,
|
"getIPAddress": p.getIPAddress,
|
||||||
"getPort": getPort,
|
"getPort": getPort,
|
||||||
"getWeight": getFuncStringLabel(label.TraefikWeight, label.DefaultWeight),
|
"getWeight": getFuncStringLabel(label.TraefikWeight, label.DefaultWeight),
|
||||||
"getDomain": getFuncStringLabel(label.TraefikDomain, p.Domain),
|
"getDomain": getFuncStringLabel(label.TraefikDomain, p.Domain),
|
||||||
"getProtocol": getFuncStringLabel(label.TraefikProtocol, label.DefaultProtocol),
|
"getProtocol": getFuncStringLabel(label.TraefikProtocol, label.DefaultProtocol),
|
||||||
"getPassHostHeader": getFuncStringLabel(label.TraefikFrontendPassHostHeader, label.DefaultPassHostHeader),
|
"getPassHostHeader": getFuncStringLabel(label.TraefikFrontendPassHostHeader, label.DefaultPassHostHeader),
|
||||||
"getPassTLSCert": getFuncBoolLabel(label.TraefikFrontendPassTLSCert, label.DefaultPassTLSCert),
|
"getPassTLSCert": getFuncBoolLabel(label.TraefikFrontendPassTLSCert, label.DefaultPassTLSCert),
|
||||||
"getPriority": getFuncStringLabel(label.TraefikFrontendPriority, label.DefaultFrontendPriority),
|
"getPriority": getFuncStringLabel(label.TraefikFrontendPriority, label.DefaultFrontendPriority),
|
||||||
"getEntryPoints": getFuncSliceStringLabel(label.TraefikFrontendEntryPoints),
|
"getEntryPoints": getFuncSliceStringLabel(label.TraefikFrontendEntryPoints),
|
||||||
"getBasicAuth": getFuncSliceStringLabel(label.TraefikFrontendAuthBasic),
|
"getBasicAuth": getFuncSliceStringLabel(label.TraefikFrontendAuthBasic),
|
||||||
"getFrontendRule": p.getFrontendRule,
|
"getFrontendRule": p.getFrontendRule,
|
||||||
"hasRedirect": hasRedirect,
|
"hasRedirect": hasRedirect,
|
||||||
"getRedirectEntryPoint": getFuncStringLabel(label.TraefikFrontendRedirectEntryPoint, label.DefaultFrontendRedirectEntryPoint),
|
"getRedirectEntryPoint": getFuncStringLabel(label.TraefikFrontendRedirectEntryPoint, label.DefaultFrontendRedirectEntryPoint),
|
||||||
"getRedirectRegex": getFuncStringLabel(label.TraefikFrontendRedirectRegex, ""),
|
"getRedirectRegex": getFuncStringLabel(label.TraefikFrontendRedirectRegex, ""),
|
||||||
"getRedirectReplacement": getFuncStringLabel(label.TraefikFrontendRedirectReplacement, ""),
|
"getRedirectReplacement": getFuncStringLabel(label.TraefikFrontendRedirectReplacement, ""),
|
||||||
|
"hasHealthCheckLabels": hasFunc(label.TraefikBackendHealthCheckPath),
|
||||||
|
"getHealthCheckPath": getFuncStringLabel(label.TraefikBackendHealthCheckPath, ""),
|
||||||
|
"getHealthCheckPort": getFuncIntLabel(label.TraefikBackendHealthCheckPort, label.DefaultBackendHealthCheckPort),
|
||||||
|
"getHealthCheckInterval": getFuncStringLabel(label.TraefikBackendHealthCheckInterval, ""),
|
||||||
"hasCircuitBreakerLabel": hasFunc(label.TraefikBackendCircuitBreakerExpression),
|
"hasCircuitBreakerLabel": hasFunc(label.TraefikBackendCircuitBreakerExpression),
|
||||||
"getCircuitBreakerExpression": getFuncStringLabel(label.TraefikBackendCircuitBreakerExpression, label.DefaultCircuitBreakerExpression),
|
"getCircuitBreakerExpression": getFuncStringLabel(label.TraefikBackendCircuitBreakerExpression, label.DefaultCircuitBreakerExpression),
|
||||||
"hasLoadBalancerLabel": hasLoadBalancerLabel,
|
"hasLoadBalancerLabel": hasLoadBalancerLabel,
|
||||||
|
|
|
@ -192,6 +192,12 @@ func getFuncStringLabel(labelName string, defaultValue string) func(container do
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getFuncIntLabel(labelName string, defaultValue int) func(container dockerData) int {
|
||||||
|
return func(container dockerData) int {
|
||||||
|
return label.GetIntValue(container.Labels, labelName, defaultValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getFuncBoolLabel(labelName string, defaultValue bool) func(container dockerData) bool {
|
func getFuncBoolLabel(labelName string, defaultValue bool) func(container dockerData) bool {
|
||||||
return func(container dockerData) bool {
|
return func(container dockerData) bool {
|
||||||
return label.GetBoolValue(container.Labels, labelName, defaultValue)
|
return label.GetBoolValue(container.Labels, labelName, defaultValue)
|
||||||
|
|
|
@ -122,6 +122,12 @@ func getFuncServiceBoolLabel(labelSuffix string, defaultValue bool) func(contain
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getFuncServiceIntLabel(labelSuffix string, defaultValue int) func(container dockerData, serviceName string) int {
|
||||||
|
return func(container dockerData, serviceName string) int {
|
||||||
|
return getServiceIntLabel(container, serviceName, labelSuffix, defaultValue)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func hasFuncServiceLabel(labelSuffix string) func(container dockerData, serviceName string) bool {
|
func hasFuncServiceLabel(labelSuffix string) func(container dockerData, serviceName string) bool {
|
||||||
return func(container dockerData, serviceName string) bool {
|
return func(container dockerData, serviceName string) bool {
|
||||||
return hasServiceLabel(container, serviceName, labelSuffix)
|
return hasServiceLabel(container, serviceName, labelSuffix)
|
||||||
|
@ -168,6 +174,16 @@ func getServiceBoolLabel(container dockerData, serviceName string, labelSuffix s
|
||||||
return label.GetBoolValue(container.Labels, label.Prefix+labelSuffix, defaultValue)
|
return label.GetBoolValue(container.Labels, label.Prefix+labelSuffix, defaultValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getServiceIntLabel(container dockerData, serviceName string, labelSuffix string, defaultValue int) int {
|
||||||
|
if rawValue, ok := getServiceLabels(container, serviceName)[labelSuffix]; ok {
|
||||||
|
value, err := strconv.Atoi(rawValue)
|
||||||
|
if err == nil {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return label.GetIntValue(container.Labels, label.Prefix+labelSuffix, defaultValue)
|
||||||
|
}
|
||||||
|
|
||||||
func getServiceLabels(container dockerData, serviceName string) label.ServicePropertyValues {
|
func getServiceLabels(container dockerData, serviceName string) label.ServicePropertyValues {
|
||||||
return label.ExtractServiceProperties(container.Labels)[serviceName]
|
return label.ExtractServiceProperties(container.Labels)[serviceName]
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ const (
|
||||||
DefaultBackendLoadBalancerMethod = "wrr"
|
DefaultBackendLoadBalancerMethod = "wrr"
|
||||||
DefaultBackendMaxconnExtractorFunc = "request.host"
|
DefaultBackendMaxconnExtractorFunc = "request.host"
|
||||||
DefaultBackendLoadbalancerStickinessCookieName = ""
|
DefaultBackendLoadbalancerStickinessCookieName = ""
|
||||||
|
DefaultBackendHealthCheckPort = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServicesPropertiesRegexp used to extract the name of the service and the name of the property for this service
|
// ServicesPropertiesRegexp used to extract the name of the service and the name of the property for this service
|
||||||
|
|
|
@ -15,6 +15,7 @@ const (
|
||||||
SuffixBackendCircuitBreaker = "backend.circuitbreaker"
|
SuffixBackendCircuitBreaker = "backend.circuitbreaker"
|
||||||
SuffixBackendCircuitBreakerExpression = "backend.circuitbreaker.expression"
|
SuffixBackendCircuitBreakerExpression = "backend.circuitbreaker.expression"
|
||||||
SuffixBackendHealthCheckPath = "backend.healthcheck.path"
|
SuffixBackendHealthCheckPath = "backend.healthcheck.path"
|
||||||
|
SuffixBackendHealthCheckPort = "backend.healthcheck.port"
|
||||||
SuffixBackendHealthCheckInterval = "backend.healthcheck.interval"
|
SuffixBackendHealthCheckInterval = "backend.healthcheck.interval"
|
||||||
SuffixBackendLoadBalancerMethod = "backend.loadbalancer.method"
|
SuffixBackendLoadBalancerMethod = "backend.loadbalancer.method"
|
||||||
SuffixBackendLoadBalancerSticky = "backend.loadbalancer.sticky"
|
SuffixBackendLoadBalancerSticky = "backend.loadbalancer.sticky"
|
||||||
|
@ -67,6 +68,7 @@ const (
|
||||||
TraefikBackendCircuitBreaker = Prefix + SuffixBackendCircuitBreaker
|
TraefikBackendCircuitBreaker = Prefix + SuffixBackendCircuitBreaker
|
||||||
TraefikBackendCircuitBreakerExpression = Prefix + SuffixBackendCircuitBreakerExpression
|
TraefikBackendCircuitBreakerExpression = Prefix + SuffixBackendCircuitBreakerExpression
|
||||||
TraefikBackendHealthCheckPath = Prefix + SuffixBackendHealthCheckPath
|
TraefikBackendHealthCheckPath = Prefix + SuffixBackendHealthCheckPath
|
||||||
|
TraefikBackendHealthCheckPort = Prefix + SuffixBackendHealthCheckPort
|
||||||
TraefikBackendHealthCheckInterval = Prefix + SuffixBackendHealthCheckInterval
|
TraefikBackendHealthCheckInterval = Prefix + SuffixBackendHealthCheckInterval
|
||||||
TraefikBackendLoadBalancerMethod = Prefix + SuffixBackendLoadBalancerMethod
|
TraefikBackendLoadBalancerMethod = Prefix + SuffixBackendLoadBalancerMethod
|
||||||
TraefikBackendLoadBalancerSticky = Prefix + SuffixBackendLoadBalancerSticky
|
TraefikBackendLoadBalancerSticky = Prefix + SuffixBackendLoadBalancerSticky
|
||||||
|
|
|
@ -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}}
|
||||||
|
|
||||||
{{$servers := index $backendServers $backendName}}
|
{{$servers := index $backendServers $backendName}}
|
||||||
{{range $serverName, $server := $servers}}
|
{{range $serverName, $server := $servers}}
|
||||||
{{if hasServices $server}}
|
{{if hasServices $server}}
|
||||||
|
|
Loading…
Reference in a new issue