Skip to content

Commit

Permalink
feat: add annotation to set health check send proxy protocol (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe authored Aug 27, 2024
1 parent a7a896a commit 43e1f57
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/loadbalancer-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ The default is the first zone of the cluster's region.
This is the annotation to set the time between two consecutive health checks.
The default value is `5s`. The duration are go's time.Duration (ex: `1s`, `2m`, `4h`, ...).

### `service.beta.kubernetes.io/scw-loadbalancer-health-check-send-proxy`
This is the annotation to control if proxy protocol should be activated for the health check.
The default value is `false`.

### `service.beta.kubernetes.io/scw-loadbalancer-health-transient-check-delay`
This is the annotation to set the time between two consecutive health checks in a transient state (going UP or DOWN).
The default value is `0.5s`. The duration are go's time.Duration (ex: `1s`, `2m`, `4h`, ...).
Expand Down
6 changes: 6 additions & 0 deletions scaleway/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,12 @@ func servicePortToBackend(service *v1.Service, loadbalancer *scwlb.LB, port v1.S
}
healthCheck.TransientCheckDelay = healthCheckTransientCheckDelay

healthCheckSendProxy, err := getHealthCheckSendProxy(service)
if err != nil {
return nil, err
}
healthCheck.CheckSendProxy = healthCheckSendProxy

healthCheckType, err := getHealthCheckType(service, port.NodePort)
if err != nil {
return nil, err
Expand Down
18 changes: 18 additions & 0 deletions scaleway/loadbalancers_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ const (
// The default value is "5s". The duration are go's time.Duration (ex: "1s", "2m", "4h", ...)
serviceAnnotationLoadBalancerHealthCheckDelay = "service.beta.kubernetes.io/scw-loadbalancer-health-check-delay"

// serviceAnnotationLoadBalancerHealthCheckSendProxy is the annotation to control if proxy protocol should be activated for the health check.
// The default value is "false"
serviceAnnotationLoadBalancerHealthCheckSendProxy = "service.beta.kubernetes.io/scw-loadbalancer-health-check-send-proxy"

// serviceAnnotationLoadBalancerHealthTransientCheckDelay is the time between two consecutive health checks on transient state (going UP or DOWN)
// The default value is "0.5s". The duration are go's time.Duration (ex: "1s", "2m", "4h", ...)
serviceAnnotationLoadBalancerHealthTransientCheckDelay = "service.beta.kubernetes.io/scw-loadbalancer-health-transient-check-delay"
Expand Down Expand Up @@ -483,6 +487,20 @@ func getHealthCheckMaxRetries(service *v1.Service) (int32, error) {
return int32(healthCheckMaxRetriesInt), nil
}

func getHealthCheckSendProxy(service *v1.Service) (bool, error) {
sendProxy, ok := service.Annotations[serviceAnnotationLoadBalancerHealthCheckSendProxy]
if !ok {
return false, nil
}
sendProxyBool, err := strconv.ParseBool(sendProxy)
if err != nil {
klog.Errorf("invalid value for annotation %s", serviceAnnotationLoadBalancerHealthCheckSendProxy)
return false, errLoadBalancerInvalidAnnotation
}

return sendProxyBool, nil
}

func getHealthCheckTransientCheckDelay(service *v1.Service) (*scw.Duration, error) {
transientCheckDelay, ok := service.Annotations[serviceAnnotationLoadBalancerHealthTransientCheckDelay]
if !ok {
Expand Down

0 comments on commit 43e1f57

Please sign in to comment.