Skip to content

Commit fd81bfb

Browse files
authored
feat(lb): add HTTPS health checks (#63) (#67)
Signed-off-by: Patrik Cyvoct <[email protected]>
1 parent bb6051f commit fd81bfb

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

scaleway/loadbalancers.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const (
4949
serviceAnnotationLoadBalancerStickySessionsCookieName = "service.beta.kubernetes.io/scw-loadbalancer-sticky-sessions-cookie-name"
5050

5151
// serviceAnnotationLoadBalancerHealthCheckType is the type of health check used
52-
// The default value is "tcp" and the possible values are "tcp", "http", "mysql", "pgsql", "redis" or "ldap"
52+
// The default value is "tcp" and the possible values are "tcp", "http", "https", "mysql", "pgsql", "redis" or "ldap"
5353
// NB: depending on the type, some other annotations are required, see below
5454
serviceAnnotationLoadBalancerHealthCheckType = "service.beta.kubernetes.io/scw-loadbalancer-health-check-type"
5555

@@ -66,15 +66,15 @@ const (
6666
serviceAnnotationLoadBalancerHealthCheckMaxRetries = "service.beta.kubernetes.io/scw-loadbalancer-health-check-max-retries"
6767

6868
// serviceAnnotationLoadBalancerHealthCheckHTTPURI is the URI that is used by the "http" health check
69-
// NB: Required when setting service.beta.kubernetes.io/scw-loadbalancer-health-check-type to "http"
69+
// NB: Required when setting service.beta.kubernetes.io/scw-loadbalancer-health-check-type to "http" or "https"
7070
serviceAnnotationLoadBalancerHealthCheckHTTPURI = "service.beta.kubernetes.io/scw-loadbalancer-health-check-http-uri"
7171

7272
// serviceAnnotationLoadBalancerHealthCheckHTTPMethod is the HTTP method used by the "http" health check
73-
// NB: Required when setting service.beta.kubernetes.io/scw-loadbalancer-health-check-type to "http"
73+
// NB: Required when setting service.beta.kubernetes.io/scw-loadbalancer-health-check-type to "http" or "https"
7474
serviceAnnotationLoadBalancerHealthCheckHTTPMethod = "service.beta.kubernetes.io/scw-loadbalancer-health-check-http-method"
7575

7676
// serviceAnnotationLoadBalancerHealthCheckHTTPCode is the HTTP code that the "http" health check will be matching against
77-
// NB: Required when setting service.beta.kubernetes.io/scw-loadbalancer-health-check-type to "http"
77+
// NB: Required when setting service.beta.kubernetes.io/scw-loadbalancer-health-check-type to "http" or "https"
7878
serviceAnnotationLoadBalancerHealthCheckHTTPCode = "service.beta.kubernetes.io/scw-loadbalancer-health-check-http-code"
7979

8080
// serviceAnnotationLoadBalancerHealthCheckMysqlUser is the MySQL user used to check the MySQL connection when using the "mysql" health check
@@ -939,6 +939,19 @@ func (l *loadbalancers) makeUpdateHealthCheckRequest(backend *scwlb.Backend, nod
939939
Method: healthCheckHTTPMethod,
940940
Code: &healthCheckHTTPCode,
941941
}
942+
case "https":
943+
healthCheckHTTPURI := getHealthCheckHTTPURI(service)
944+
healthCheckHTTPMethod := getHealthCheckHTTPMethod(service)
945+
healthCheckHTTPCode, err := getHealthCheckHTTPCode(service)
946+
if err != nil {
947+
return nil, err
948+
}
949+
request.HTTPSConfig = &scwlb.HealthCheckHTTPSConfig{
950+
URI: healthCheckHTTPURI,
951+
Method: healthCheckHTTPMethod,
952+
Code: &healthCheckHTTPCode,
953+
}
954+
942955
default:
943956
klog.Errorf("wrong value for healthCheckType")
944957
return nil, NewAnnorationError(serviceAnnotationLoadBalancerHealthCheckType, healthCheckType)
@@ -1084,6 +1097,18 @@ func (l *loadbalancers) makeCreateBackendRequest(loadbalancer *scwlb.LB, nodePor
10841097
Method: healthCheckHTTPMethod,
10851098
Code: &healthCheckHTTPCode,
10861099
}
1100+
case "https":
1101+
healthCheckHTTPURI := getHealthCheckHTTPURI(service)
1102+
healthCheckHTTPMethod := getHealthCheckHTTPMethod(service)
1103+
healthCheckHTTPCode, err := getHealthCheckHTTPCode(service)
1104+
if err != nil {
1105+
return nil, err
1106+
}
1107+
healthCheck.HTTPSConfig = &scwlb.HealthCheckHTTPSConfig{
1108+
URI: healthCheckHTTPURI,
1109+
Method: healthCheckHTTPMethod,
1110+
Code: &healthCheckHTTPCode,
1111+
}
10871112
default:
10881113
klog.Errorf("wrong value for healthCheckType")
10891114
return nil, errLoadBalancerInvalidAnnotation
@@ -1325,7 +1350,7 @@ func getHealthCheckType(service *v1.Service) (string, error) {
13251350
return "tcp", nil
13261351
}
13271352

1328-
if healthCheckType != "mysql" && healthCheckType != "ldap" && healthCheckType != "redis" && healthCheckType != "pgsql" && healthCheckType != "tcp" && healthCheckType != "http" {
1353+
if healthCheckType != "mysql" && healthCheckType != "ldap" && healthCheckType != "redis" && healthCheckType != "pgsql" && healthCheckType != "tcp" && healthCheckType != "http" && healthCheckType != "https" {
13291354
klog.Errorf("invalid value for annotation %s", serviceAnnotationLoadBalancerHealthCheckType)
13301355
return "", errLoadBalancerInvalidAnnotation
13311356
}

0 commit comments

Comments
 (0)