Skip to content

Commit e704959

Browse files
authored
Merge pull request #196 from digitalocean/add-support-for-customizing-numeric-health-check-parameters
Add support for customizing remaining, numeric health check parameters
2 parents 093731a + d97a205 commit e704959

File tree

5 files changed

+365
-111
lines changed

5 files changed

+365
-111
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## unreleased
4+
5+
* loadbalancers: support numeric health check parameters (@timoreimann)
6+
37
## v0.1.10 (beta) - Feb 26th 2019
48

59
* loadbalancers: don't use pointer to loop variable in load balancers map (@bouk)

cloud-controller-manager/do/loadbalancers.go

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@ const (
4646
// 'service.beta.kubernetes.io/do-loadbalancer-protocol'.
4747
annDOHealthCheckProtocol = "service.beta.kubernetes.io/do-loadbalancer-healthcheck-protocol"
4848

49+
// annDOHealthCheckIntervalSeconds is the annotation used to specify the
50+
// number of seconds between between two consecutive health checks. The
51+
// value must be between 3 and 300. Defaults to 3.
52+
annDOHealthCheckIntervalSeconds = "service.beta.kubernetes.io/do-loadbalancer-healthcheck-check-interval-seconds"
53+
54+
// annDOHealthCheckResponseTimeoutSeconds is the annotation used to specify the
55+
// number of seconds the Load Balancer instance will wait for a response
56+
// until marking a health check as failed. The value must be between 3 and
57+
// 300. Defaults to 5.
58+
annDOHealthCheckResponseTimeoutSeconds = "service.beta.kubernetes.io/do-loadbalancer-healthcheck-response-timeout-seconds"
59+
60+
// annDOHealthCheckUnhealthyThreshold is the annotation used to specify the
61+
// number of times a health check must fail for a backend Droplet to be
62+
// marked "unhealthy" and be removed from the pool for the given service.
63+
// The value must be between 2 and 10. Defaults to 3.
64+
annDOHealthCheckUnhealthyThreshold = "service.beta.kubernetes.io/do-loadbalancer-healthcheck-unhealthy-threshold"
65+
66+
// annDOHealthCheckHealthyThreshold is the annotation used to specify the
67+
// number of times a health check must pass for a backend Droplet to be
68+
// marked "healthy" for the given service and be re-added to the pool. The
69+
// value must be between 2 and 10. Defaults to 5.
70+
annDOHealthCheckHealthyThreshold = "service.beta.kubernetes.io/do-loadbalancer-healthcheck-healthy-threshold"
71+
4972
// annDOTLSPorts is the annotation used to specify which ports of the load balancer
5073
// should use the https protocol. This is a comma separated list of ports
5174
// (e.g. 443,6443,7443).
@@ -399,17 +422,34 @@ func buildHealthCheck(service *v1.Service) (*godo.HealthCheck, error) {
399422
healthCheckProtocol = protocol
400423
}
401424

425+
checkIntervalSecs, err := healthCheckIntervalSeconds(service)
426+
if err != nil {
427+
return nil, err
428+
}
429+
responseTimeoutSecs, err := healthCheckResponseTimeoutSeconds(service)
430+
if err != nil {
431+
return nil, err
432+
}
433+
unhealthyThreshold, err := healthCheckUnhealthyThreshold(service)
434+
if err != nil {
435+
return nil, err
436+
}
437+
healthyThreshold, err := healthCheckHealthyThreshold(service)
438+
if err != nil {
439+
return nil, err
440+
}
441+
402442
healthCheckPath := healthCheckPath(service)
403443
port := service.Spec.Ports[0].NodePort
404444

405445
return &godo.HealthCheck{
406446
Protocol: healthCheckProtocol,
407447
Port: int(port),
408448
Path: healthCheckPath,
409-
CheckIntervalSeconds: 3,
410-
ResponseTimeoutSeconds: 5,
411-
HealthyThreshold: 5,
412-
UnhealthyThreshold: 3,
449+
CheckIntervalSeconds: checkIntervalSecs,
450+
ResponseTimeoutSeconds: responseTimeoutSecs,
451+
UnhealthyThreshold: unhealthyThreshold,
452+
HealthyThreshold: healthyThreshold,
413453
}, nil
414454
}
415455

@@ -543,6 +583,66 @@ func healthCheckPath(service *v1.Service) string {
543583
return path
544584
}
545585

586+
// healthCheckIntervalSeconds returns the health check interval in seconds
587+
func healthCheckIntervalSeconds(service *v1.Service) (int, error) {
588+
valStr, ok := service.Annotations[annDOHealthCheckIntervalSeconds]
589+
if !ok {
590+
return 3, nil
591+
}
592+
593+
val, err := strconv.Atoi(valStr)
594+
if err != nil {
595+
return 0, fmt.Errorf("failed to parse health check interval annotation %q: %s", annDOHealthCheckIntervalSeconds, err)
596+
}
597+
598+
return val, nil
599+
}
600+
601+
// healthCheckIntervalSeconds returns the health response timeout in seconds
602+
func healthCheckResponseTimeoutSeconds(service *v1.Service) (int, error) {
603+
valStr, ok := service.Annotations[annDOHealthCheckResponseTimeoutSeconds]
604+
if !ok {
605+
return 5, nil
606+
}
607+
608+
val, err := strconv.Atoi(valStr)
609+
if err != nil {
610+
return 0, fmt.Errorf("failed to parse health check response timeout annotation %q: %s", annDOHealthCheckResponseTimeoutSeconds, err)
611+
}
612+
613+
return val, nil
614+
}
615+
616+
// healthCheckUnhealthyThreshold returns the health check unhealthy threshold
617+
func healthCheckUnhealthyThreshold(service *v1.Service) (int, error) {
618+
valStr, ok := service.Annotations[annDOHealthCheckUnhealthyThreshold]
619+
if !ok {
620+
return 3, nil
621+
}
622+
623+
val, err := strconv.Atoi(valStr)
624+
if err != nil {
625+
return 0, fmt.Errorf("failed to parse health check unhealthy threshold annotation %q: %s", annDOHealthCheckUnhealthyThreshold, err)
626+
}
627+
628+
return val, nil
629+
}
630+
631+
// healthCheckHealthyThreshold returns the health check healthy threshold
632+
func healthCheckHealthyThreshold(service *v1.Service) (int, error) {
633+
valStr, ok := service.Annotations[annDOHealthCheckHealthyThreshold]
634+
if !ok {
635+
return 5, nil
636+
}
637+
638+
val, err := strconv.Atoi(valStr)
639+
if err != nil {
640+
return 0, fmt.Errorf("failed to parse health check healthy threshold annotation %q: %s", annDOHealthCheckHealthyThreshold, err)
641+
}
642+
643+
return val, nil
644+
}
645+
546646
// getTLSPorts returns the ports of service that are set to use TLS.
547647
func getTLSPorts(service *v1.Service) ([]int, error) {
548648
tlsPorts, ok := service.Annotations[annDOTLSPorts]

0 commit comments

Comments
 (0)