Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add annotation to set health check send proxy protocol #168

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading