From 64b0052425bbc49cc2e0d3f7b6ecc26fd47a55e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Mon, 8 Jul 2024 16:52:31 +0200 Subject: [PATCH 1/3] Add annotation to set health check send proxy protocol --- docs/loadbalancer-annotations.md | 4 ++++ scaleway/loadbalancers.go | 6 ++++++ scaleway/loadbalancers_annotations.go | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/docs/loadbalancer-annotations.md b/docs/loadbalancer-annotations.md index cae0e67..da39341 100644 --- a/docs/loadbalancer-annotations.md +++ b/docs/loadbalancer-annotations.md @@ -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 set if the health checks send a proxy protocol v2 frame before the actual 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`, ...). diff --git a/scaleway/loadbalancers.go b/scaleway/loadbalancers.go index d7e8ab5..14c2887 100644 --- a/scaleway/loadbalancers.go +++ b/scaleway/loadbalancers.go @@ -1051,6 +1051,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 diff --git a/scaleway/loadbalancers_annotations.go b/scaleway/loadbalancers_annotations.go index d2e2f0e..1968e92 100644 --- a/scaleway/loadbalancers_annotations.go +++ b/scaleway/loadbalancers_annotations.go @@ -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 health check should send proxy protocol message + // 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" @@ -473,6 +477,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 { From 8153dde8f84519d87b30e5134f071fa1abf9d78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Er=C3=A8be=20-=20Romain=20Gerard?= Date: Mon, 26 Aug 2024 21:45:22 +0200 Subject: [PATCH 2/3] Update docs/loadbalancer-annotations.md Co-authored-by: Nox <5402193+Nox-404@users.noreply.github.com> --- docs/loadbalancer-annotations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/loadbalancer-annotations.md b/docs/loadbalancer-annotations.md index da39341..1850e23 100644 --- a/docs/loadbalancer-annotations.md +++ b/docs/loadbalancer-annotations.md @@ -54,7 +54,7 @@ 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 set if the health checks send a proxy protocol v2 frame before the actual check. +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` From d1d2d8322d962a737ac3804d17c510f5eb63717c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Er=C3=A8be=20-=20Romain=20Gerard?= Date: Mon, 26 Aug 2024 21:45:29 +0200 Subject: [PATCH 3/3] Update scaleway/loadbalancers_annotations.go Co-authored-by: Nox <5402193+Nox-404@users.noreply.github.com> --- scaleway/loadbalancers_annotations.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scaleway/loadbalancers_annotations.go b/scaleway/loadbalancers_annotations.go index 1968e92..3a9ecd1 100644 --- a/scaleway/loadbalancers_annotations.go +++ b/scaleway/loadbalancers_annotations.go @@ -44,7 +44,7 @@ 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 health check should send proxy protocol message + // 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"