@@ -115,6 +115,10 @@ const (
115115 // serviceAnnotationLoadBalancerZone is the zone to create the load balancer
116116 serviceAnnotationLoadBalancerZone = "service.beta.kubernetes.io/scw-loadbalancer-zone"
117117
118+ // serviceAnnotationLoadBalancerTimeoutClient is the maximum client connection inactivity time
119+ // The default value is "10m". The duration are go's time.Duration (ex: "1s", "2m", "4h", ...)
120+ serviceAnnotationLoadBalancerTimeoutClient = "service.beta.kubernetes.io/scw-loadbalancer-timeout-client"
121+
118122 // serviceAnnotationLoadBalancerTimeoutServer is the maximum server connection inactivity time
119123 // The default value is "10m". The duration are go's time.Duration (ex: "1s", "2m", "4h", ...)
120124 serviceAnnotationLoadBalancerTimeoutServer = "service.beta.kubernetes.io/scw-loadbalancer-timeout-server"
@@ -710,6 +714,13 @@ func (l *loadbalancers) updateLoadBalancer(ctx context.Context, loadbalancer *sc
710714 if err != nil {
711715 return fmt .Errorf ("error getting certificate IDs for loadbalancer %s: %v" , loadbalancer .ID , err )
712716 }
717+
718+ timeoutClient , err := getTimeoutClient (service )
719+ if err != nil {
720+ return fmt .Errorf ("error getting %s annotation for loadbalancer %s: %v" ,
721+ serviceAnnotationLoadBalancerTimeoutClient , loadbalancer .ID , err )
722+ }
723+
713724 // if the frontend exists for the port, update it
714725 if frontend , ok := portFrontends [port .Port ]; ok {
715726 _ , err := l .api .UpdateFrontend (& scwlb.ZonedAPIUpdateFrontendRequest {
@@ -718,7 +729,7 @@ func (l *loadbalancers) updateLoadBalancer(ctx context.Context, loadbalancer *sc
718729 Name : frontend .Name ,
719730 InboundPort : frontend .InboundPort ,
720731 BackendID : portBackends [port .NodePort ].ID ,
721- TimeoutClient : frontend . TimeoutClient ,
732+ TimeoutClient : & timeoutClient ,
722733 CertificateIDs : scw .StringsPtr (certificateIDs ),
723734 })
724735
@@ -729,14 +740,13 @@ func (l *loadbalancers) updateLoadBalancer(ctx context.Context, loadbalancer *sc
729740
730741 frontendID = frontend .ID
731742 } else { // if the frontend for this port does not exist, create it
732- timeoutClient := time .Minute * 10
733743 resp , err := l .api .CreateFrontend (& scwlb.ZonedAPICreateFrontendRequest {
734744 Zone : loadbalancer .Zone ,
735745 LBID : loadbalancer .ID ,
736746 Name : fmt .Sprintf ("%s_tcp_%d" , string (service .UID ), port .Port ),
737747 InboundPort : port .Port ,
738748 BackendID : portBackends [port .NodePort ].ID ,
739- TimeoutClient : & timeoutClient , // TODO use annotation?
749+ TimeoutClient : & timeoutClient ,
740750 CertificateIDs : scw .StringsPtr (certificateIDs ),
741751 })
742752
@@ -1330,6 +1340,21 @@ func getProxyProtocol(service *v1.Service, nodePort int32) (scwlb.ProxyProtocol,
13301340 return getSendProxyV2 (service , nodePort )
13311341}
13321342
1343+ func getTimeoutClient (service * v1.Service ) (time.Duration , error ) {
1344+ timeoutClient , ok := service .Annotations [serviceAnnotationLoadBalancerTimeoutClient ]
1345+ if ! ok {
1346+ return time .ParseDuration ("10m" )
1347+ }
1348+
1349+ timeoutClientDuration , err := time .ParseDuration (timeoutClient )
1350+ if err != nil {
1351+ klog .Errorf ("invalid value for annotation %s" , serviceAnnotationLoadBalancerTimeoutClient )
1352+ return time .Duration (0 ), errLoadBalancerInvalidAnnotation
1353+ }
1354+
1355+ return timeoutClientDuration , nil
1356+ }
1357+
13331358func getTimeoutServer (service * v1.Service ) (time.Duration , error ) {
13341359 timeoutServer , ok := service .Annotations [serviceAnnotationLoadBalancerTimeoutServer ]
13351360 if ! ok {
0 commit comments