@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"fmt"
22
22
"net"
23
+ "net/url"
23
24
"os"
24
25
"reflect"
25
26
"strconv"
@@ -79,7 +80,7 @@ const (
79
80
serviceAnnotationLoadBalancerHealthCheckMaxRetries = "service.beta.kubernetes.io/scw-loadbalancer-health-check-max-retries"
80
81
81
82
// serviceAnnotationLoadBalancerHealthCheckHTTPURI is the URI that is used by the "http" health check
82
- // It is possible to set the uri per port, like "80:/;443,8443:/healthz"
83
+ // It is possible to set the uri per port, like "80:/;443,8443:mydomain.tld /healthz"
83
84
// NB: Required when setting service.beta.kubernetes.io/scw-loadbalancer-health-check-type to "http" or "https"
84
85
serviceAnnotationLoadBalancerHealthCheckHTTPURI = "service.beta.kubernetes.io/scw-loadbalancer-health-check-http-uri"
85
86
@@ -88,10 +89,6 @@ const (
88
89
// NB: Required when setting service.beta.kubernetes.io/scw-loadbalancer-health-check-type to "http" or "https"
89
90
serviceAnnotationLoadBalancerHealthCheckHTTPMethod = "service.beta.kubernetes.io/scw-loadbalancer-health-check-http-method"
90
91
91
- // serviceAnnotationLoadBalancerHealthCheckHTTPHost is the HTTP host header used by the "http" health check
92
- // It is possible to set the method per port, like "80:mydomain1.tld;443,8443:mydomain2.tld"
93
- serviceAnnotationLoadBalancerHealthCheckHTTPHost = "service.beta.kubernetes.io/scw-loadbalancer-health-check-http-host"
94
-
95
92
// serviceAnnotationLoadBalancerHealthCheckHTTPCode is the HTTP code that the "http" health check will be matching against
96
93
// It is possible to set the code per port, like "80:404;443,8443:204"
97
94
// NB: Required when setting service.beta.kubernetes.io/scw-loadbalancer-health-check-type to "http" or "https"
@@ -1509,44 +1506,31 @@ func getHTTPHealthCheckMethod(service *v1.Service, nodePort int32) (string, erro
1509
1506
return method , nil
1510
1507
}
1511
1508
1512
- func getHTTPHealthCheckHost (service * v1.Service , nodePort int32 ) (string , error ) {
1513
- annotation , ok := service .Annotations [serviceAnnotationLoadBalancerHealthCheckHTTPHost ]
1514
- if ! ok {
1515
- return "" , nil
1516
- }
1517
-
1518
- method , err := getValueForPort (service , nodePort , annotation )
1519
- if err != nil {
1520
- klog .Errorf ("could not get value for annotation %s and port %d" , serviceAnnotationLoadBalancerHealthCheckHTTPHost , nodePort )
1521
- return "" , err
1522
- }
1523
-
1524
- return method , nil
1525
- }
1526
-
1527
1509
func getHTTPHealthCheck (service * v1.Service , nodePort int32 ) (* scwlb.HealthCheckHTTPConfig , error ) {
1528
1510
code , err := getHTTPHealthCheckCode (service , nodePort )
1529
1511
if err != nil {
1530
1512
return nil , err
1531
1513
}
1532
- uri , err := getHTTPHealthCheckURI (service , nodePort )
1514
+
1515
+ uriStr , err := getHTTPHealthCheckURI (service , nodePort )
1533
1516
if err != nil {
1534
1517
return nil , err
1535
1518
}
1536
- method , err := getHTTPHealthCheckMethod ( service , nodePort )
1519
+ uri , err := url . Parse ( fmt . Sprintf ( "http://%s" , uriStr ) )
1537
1520
if err != nil {
1538
1521
return nil , err
1539
1522
}
1540
- host , err := getHTTPHealthCheckHost (service , nodePort )
1523
+
1524
+ method , err := getHTTPHealthCheckMethod (service , nodePort )
1541
1525
if err != nil {
1542
1526
return nil , err
1543
1527
}
1544
1528
1545
1529
return & scwlb.HealthCheckHTTPConfig {
1546
1530
Method : method ,
1547
1531
Code : & code ,
1548
- URI : uri ,
1549
- HostHeader : host ,
1532
+ URI : uri . Path ,
1533
+ HostHeader : uri . Host ,
1550
1534
}, nil
1551
1535
}
1552
1536
@@ -1555,19 +1539,27 @@ func getHTTPSHealthCheck(service *v1.Service, nodePort int32) (*scwlb.HealthChec
1555
1539
if err != nil {
1556
1540
return nil , err
1557
1541
}
1558
- uri , err := getHTTPHealthCheckURI (service , nodePort )
1542
+
1543
+ uriStr , err := getHTTPHealthCheckURI (service , nodePort )
1544
+ if err != nil {
1545
+ return nil , err
1546
+ }
1547
+ uri , err := url .Parse (fmt .Sprintf ("https://%s" , uriStr ))
1559
1548
if err != nil {
1560
1549
return nil , err
1561
1550
}
1551
+
1562
1552
method , err := getHTTPHealthCheckMethod (service , nodePort )
1563
1553
if err != nil {
1564
1554
return nil , err
1565
1555
}
1566
1556
1567
1557
return & scwlb.HealthCheckHTTPSConfig {
1568
- Method : method ,
1569
- Code : & code ,
1570
- URI : uri ,
1558
+ Method : method ,
1559
+ Code : & code ,
1560
+ URI : uri .Path ,
1561
+ HostHeader : uri .Host ,
1562
+ Sni : uri .Host ,
1571
1563
}, nil
1572
1564
}
1573
1565
@@ -1929,65 +1921,9 @@ func backendEquals(got, want *scwlb.Backend) bool {
1929
1921
return false
1930
1922
}
1931
1923
1932
- // TODO
1933
- if got .HealthCheck != want .HealthCheck {
1934
- if got .HealthCheck == nil || want .HealthCheck == nil {
1935
- klog .V (3 ).Infof ("backend.HealthCheck: %s - %s" , got .HealthCheck , want .HealthCheck )
1936
- return false
1937
- }
1938
-
1939
- if got .HealthCheck .Port != want .HealthCheck .Port {
1940
- klog .V (3 ).Infof ("backend.HealthCheck.Port: %s - %s" , got .HealthCheck .Port , want .HealthCheck .Port )
1941
- return false
1942
- }
1943
- if ! durationPtrEqual (got .HealthCheck .CheckDelay , want .HealthCheck .CheckDelay ) {
1944
- klog .V (3 ).Infof ("backend.HealthCheck.CheckDelay: %s - %s" , got .HealthCheck .CheckDelay , want .HealthCheck .CheckDelay )
1945
- return false
1946
- }
1947
- if ! durationPtrEqual (got .HealthCheck .CheckTimeout , want .HealthCheck .CheckTimeout ) {
1948
- klog .V (3 ).Infof ("backend.HealthCheck.CheckTimeout: %s - %s" , got .HealthCheck .CheckTimeout , want .HealthCheck .CheckTimeout )
1949
- return false
1950
- }
1951
- if got .HealthCheck .CheckMaxRetries != want .HealthCheck .CheckMaxRetries {
1952
- klog .V (3 ).Infof ("backend.HealthCheck.CheckMaxRetries: %s - %s" , got .HealthCheck .CheckMaxRetries , want .HealthCheck .CheckMaxRetries )
1953
- return false
1954
- }
1955
- if got .HealthCheck .CheckSendProxy != want .HealthCheck .CheckSendProxy {
1956
- klog .V (3 ).Infof ("backend.HealthCheck.CheckSendProxy: %s - %s" , got .HealthCheck .CheckSendProxy , want .HealthCheck .CheckSendProxy )
1957
- return false
1958
- }
1959
- if (got .HealthCheck .TCPConfig == nil ) != (want .HealthCheck .TCPConfig == nil ) {
1960
- klog .V (3 ).Infof ("backend.HealthCheck.TCPConfig: %s - %s" , got .HealthCheck .TCPConfig , want .HealthCheck .TCPConfig )
1961
- return false
1962
- }
1963
- if (got .HealthCheck .MysqlConfig == nil ) != (want .HealthCheck .MysqlConfig == nil ) {
1964
- klog .V (3 ).Infof ("backend.HealthCheck.MysqlConfig: %s - %s" , got .HealthCheck .MysqlConfig , want .HealthCheck .MysqlConfig )
1965
- return false
1966
- }
1967
- if (got .HealthCheck .PgsqlConfig == nil ) != (want .HealthCheck .PgsqlConfig == nil ) {
1968
- klog .V (3 ).Infof ("backend.HealthCheck.PgsqlConfig: %s - %s" , got .HealthCheck .PgsqlConfig , want .HealthCheck .PgsqlConfig )
1969
- return false
1970
- }
1971
- if (got .HealthCheck .LdapConfig == nil ) != (want .HealthCheck .LdapConfig == nil ) {
1972
- klog .V (3 ).Infof ("backend.HealthCheck.LdapConfig: %s - %s" , got .HealthCheck .LdapConfig , want .HealthCheck .LdapConfig )
1973
- return false
1974
- }
1975
- if (got .HealthCheck .RedisConfig == nil ) != (want .HealthCheck .RedisConfig == nil ) {
1976
- klog .V (3 ).Infof ("backend.HealthCheck.RedisConfig: %s - %s" , got .HealthCheck .RedisConfig , want .HealthCheck .RedisConfig )
1977
- return false
1978
- }
1979
- if (got .HealthCheck .HTTPConfig == nil ) != (want .HealthCheck .HTTPConfig == nil ) {
1980
- klog .V (3 ).Infof ("backend.HealthCheck.HTTPConfig: %s - %s" , got .HealthCheck .HTTPConfig , want .HealthCheck .HTTPConfig )
1981
- return false
1982
- }
1983
- if (got .HealthCheck .HTTPSConfig == nil ) != (want .HealthCheck .HTTPSConfig == nil ) {
1984
- klog .V (3 ).Infof ("backend.HealthCheck.HTTPSConfig: %s - %s" , got .HealthCheck .HTTPSConfig , want .HealthCheck .HTTPSConfig )
1985
- return false
1986
- }
1987
- if ! scwDurationPtrEqual (got .HealthCheck .TransientCheckDelay , want .HealthCheck .TransientCheckDelay ) {
1988
- klog .V (3 ).Infof ("backend.HealthCheck.TransientCheckDelay: %s - %s" , got .HealthCheck .TransientCheckDelay , want .HealthCheck .TransientCheckDelay )
1989
- return false
1990
- }
1924
+ if ! reflect .DeepEqual (got .HealthCheck , want .HealthCheck ) {
1925
+ klog .V (3 ).Infof ("backend.HealthCheck: %s - %s" , got .HealthCheck , want .HealthCheck )
1926
+ return false
1991
1927
}
1992
1928
1993
1929
return true
@@ -2098,7 +2034,7 @@ func aclsEquals(got []*scwlb.ACL, want []*scwlb.ACLSpec) bool {
2098
2034
2099
2035
slices .SortStableFunc (got , func (a , b * scwlb.ACL ) bool { return a .Index < b .Index })
2100
2036
slices .SortStableFunc (want , func (a , b * scwlb.ACLSpec ) bool { return a .Index < b .Index })
2101
- for idx , _ := range want {
2037
+ for idx := range want {
2102
2038
if want [idx ].Name != got [idx ].Name {
2103
2039
return false
2104
2040
}
@@ -2126,7 +2062,6 @@ func aclsEquals(got []*scwlb.ACL, want []*scwlb.ACLSpec) bool {
2126
2062
}
2127
2063
2128
2064
func (l * loadbalancers ) createBackend (service * v1.Service , loadbalancer * scwlb.LB , backend * scwlb.Backend ) (* scwlb.Backend , error ) {
2129
- // TODO: implement createBackend
2130
2065
b , err := l .api .CreateBackend (& scwlb.ZonedAPICreateBackendRequest {
2131
2066
Zone : getLoadBalancerZone (service ),
2132
2067
LBID : loadbalancer .ID ,
@@ -2154,7 +2089,6 @@ func (l *loadbalancers) createBackend(service *v1.Service, loadbalancer *scwlb.L
2154
2089
}
2155
2090
2156
2091
func (l * loadbalancers ) updateBackend (service * v1.Service , loadbalancer * scwlb.LB , backend * scwlb.Backend ) (* scwlb.Backend , error ) {
2157
- // TODO: implement updateBackend
2158
2092
b , err := l .api .UpdateBackend (& scwlb.ZonedAPIUpdateBackendRequest {
2159
2093
Zone : getLoadBalancerZone (service ),
2160
2094
BackendID : backend .ID ,
0 commit comments