Skip to content

Commit 1fd1d82

Browse files
Harsh ThakurRealHarshThakur
Harsh Thakur
authored andcommitted
Add server/client timeout options
Signed-off-by: Harsh Thakur <[email protected]>
1 parent 063b042 commit 1fd1d82

File tree

5 files changed

+108
-4
lines changed

5 files changed

+108
-4
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Read More: https://www.civo.com/learn/managing-external-load-balancers-on-civo
2424
| kubernetes.civo.com/loadbalancer-algorithm | Custom the algorithm the external load balancer uses | round_robin<br />least_connections |
2525
| kubernetes.civo.com/ipv4-address | If set, LoadBalancer will have the mentioned IP as the public IP. Please note: the reserved IP should be present in the account before claiming it. | 10.0.0.20<br/> my-reserved-ip |
2626
| kubernetes.civo.com/protocol | If set, this will override the protocol set on the svc with this | http<br />tcp |
27+
| kubernetes.civo.com/server-timeout| server timeout determines how long the load balancer will wait for a response from the server/upstream. Defaults to 60s | 60s<br /> 120m |
28+
| kubernetes.civo.com/client-timeout| client timeout determines how long the load balancer will wait for any activity from the client/downstream. Defaults to 60s | 60s<br /> 120m |
2729

2830
### Load Balancer Status Annotations
2931

cloud-controller-manager/civo/loadbalancer.go

+57-1
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ const (
4242
// annotationCivoIPv4 is the annotation specifying the reserved IP.
4343
annotationCivoIPv4 = "kubernetes.civo.com/ipv4-address"
4444

45-
// annDOProtocol is the annotation used to specify the protocol for the load balancer
45+
// annotationProtocol is the annotation used to specify the protocol for the load balancer
4646
annotationCivoProtocol = "kubernetes.civo.com/protocol"
47+
48+
// annotationServerTimeout is the annotation used to specify the server timeout for the load balancer
49+
annotationServerTimeout = "kubernetes.civo.com/server-timeout"
50+
51+
// annotationClientTimeout is the annotation used to specify the client timeout for the load balancer
52+
annotationClientTimeout = "kubernetes.civo.com/client-timeout"
4753
)
4854

4955
type loadbalancer struct {
@@ -148,6 +154,26 @@ func (l *loadbalancer) updateLBConfig(civolb *civogo.LoadBalancer, service *v1.S
148154
lbuc.MaxConcurrentRequests = &maxReq
149155
}
150156

157+
if serverTimeout := getServerTimeout(service); serverTimeout != "" {
158+
if lbuc.LoadBalancerOptions == nil {
159+
lbuc.LoadBalancerOptions = &civogo.LoadBalancerOptions{
160+
ServerTimeout: serverTimeout,
161+
}
162+
} else {
163+
lbuc.LoadBalancerOptions.ServerTimeout = serverTimeout
164+
}
165+
}
166+
167+
if clientTimeout := getClientTimeout(service); clientTimeout != "" {
168+
if lbuc.LoadBalancerOptions == nil {
169+
lbuc.LoadBalancerOptions = &civogo.LoadBalancerOptions{
170+
ClientTimeout: clientTimeout,
171+
}
172+
} else {
173+
lbuc.LoadBalancerOptions.ClientTimeout = clientTimeout
174+
}
175+
}
176+
151177
backends := []civogo.LoadBalancerBackendConfig{}
152178
for _, port := range service.Spec.Ports {
153179
for _, node := range nodes {
@@ -274,6 +300,11 @@ func (l *loadbalancer) UpdateLoadBalancer(ctx context.Context, clusterName strin
274300
updateServiceAnnotation(service, annotationCivoLoadBalancerMaxConcurrentRequests, fmt.Sprint(ulb.MaxConcurrentRequests))
275301
}
276302

303+
if civolb.Options != nil {
304+
updateServiceAnnotation(service, annotationServerTimeout, civolb.Options.ServerTimeout)
305+
updateServiceAnnotation(service, annotationClientTimeout, civolb.Options.ClientTimeout)
306+
}
307+
277308
return nil
278309
}
279310

@@ -333,6 +364,10 @@ func getLoadBalancer(ctx context.Context, c civogo.Clienter, kclient kubernetes.
333364
updateServiceAnnotation(service, annotationCivoFirewallID, civolb.FirewallID)
334365
updateServiceAnnotation(service, annotationCivoLoadBalancerMaxConcurrentRequests, fmt.Sprint(civolb.MaxConcurrentRequests))
335366
updateServiceAnnotation(service, annotationCivoLoadBalancerAlgorithm, civolb.Algorithm)
367+
if civolb.Options != nil {
368+
updateServiceAnnotation(service, annotationServerTimeout, civolb.Options.ServerTimeout)
369+
updateServiceAnnotation(service, annotationClientTimeout, civolb.Options.ClientTimeout)
370+
}
336371
}
337372
}
338373

@@ -405,6 +440,11 @@ func createLoadBalancer(ctx context.Context, clusterName string, service *v1.Ser
405440
updateServiceAnnotation(service, annotationCivoLoadBalancerEnableProxyProtocol, lb.EnableProxyProtocol)
406441
}
407442

443+
if lb.Options != nil {
444+
updateServiceAnnotation(service, annotationServerTimeout, lb.Options.ServerTimeout)
445+
updateServiceAnnotation(service, annotationClientTimeout, lb.Options.ClientTimeout)
446+
}
447+
408448
return nil
409449
}
410450

@@ -451,3 +491,19 @@ func getProtocol(svc *v1.Service, port v1.ServicePort) string {
451491
}
452492
return string(port.Protocol)
453493
}
494+
495+
func getServerTimeout(svc *v1.Service) string {
496+
if svc.Annotations[annotationServerTimeout] != "" {
497+
return svc.Annotations[annotationServerTimeout]
498+
}
499+
500+
return svc.Annotations[annotationServerTimeout]
501+
}
502+
503+
func getClientTimeout(svc *v1.Service) string {
504+
if svc.Annotations[annotationClientTimeout] != "" {
505+
return svc.Annotations[annotationClientTimeout]
506+
}
507+
508+
return svc.Annotations[annotationClientTimeout]
509+
}

cloud-controller-manager/civo/loadbalancer_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,46 @@ func TestUpdateServiceAnnotation(t *testing.T) {
236236
},
237237
},
238238
},
239+
{
240+
"Annotation for server timeout to 120s",
241+
&corev1.Service{
242+
Spec: corev1.ServiceSpec{
243+
Type: corev1.ServiceTypeLoadBalancer,
244+
},
245+
},
246+
"kubernetes.civo.com/server-timeout",
247+
"120s",
248+
&corev1.Service{
249+
ObjectMeta: metav1.ObjectMeta{
250+
Annotations: map[string]string{
251+
"kubernetes.civo.com/server-timeout": "120s",
252+
},
253+
},
254+
Spec: corev1.ServiceSpec{
255+
Type: corev1.ServiceTypeLoadBalancer,
256+
},
257+
},
258+
},
259+
{
260+
"Annotation for client timeout to 120s",
261+
&corev1.Service{
262+
Spec: corev1.ServiceSpec{
263+
Type: corev1.ServiceTypeLoadBalancer,
264+
},
265+
},
266+
"kubernetes.civo.com/client-timeout",
267+
"120s",
268+
&corev1.Service{
269+
ObjectMeta: metav1.ObjectMeta{
270+
Annotations: map[string]string{
271+
"kubernetes.civo.com/client-timeout": "120s",
272+
},
273+
},
274+
Spec: corev1.ServiceSpec{
275+
Type: corev1.ServiceTypeLoadBalancer,
276+
},
277+
},
278+
},
239279
}
240280

241281
for _, test := range tests {
@@ -286,6 +326,8 @@ func TestGetLoadBalanacer(t *testing.T) {
286326
annotationCivoClusterID: "a32fe5eb-1922-43e8-81bc-7f83b4011334",
287327
annotationCivoLoadBalancerName: "civo-lb-test",
288328
annotationCivoLoadBalancerMaxConcurrentRequests: "10000",
329+
annotationServerTimeout: "120s",
330+
annotationClientTimeout: "120s",
289331
},
290332
},
291333
Spec: corev1.ServiceSpec{
@@ -310,6 +352,10 @@ func TestGetLoadBalanacer(t *testing.T) {
310352
ClusterID: "a32fe5eb-1922-43e8-81bc-7f83b4011334",
311353
State: statusAvailable,
312354
MaxConcurrentRequests: 10000,
355+
Options: &civogo.LoadBalancerOptions{
356+
ServerTimeout: "120s",
357+
ClientTimeout: "120s",
358+
},
313359
},
314360
},
315361
expected: &corev1.LoadBalancerStatus{

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/civo/civo-cloud-controller-manager
33
go 1.20
44

55
require (
6-
github.com/civo/civogo v0.3.35
6+
github.com/civo/civogo v0.3.41
77
github.com/joho/godotenv v1.4.0
88
github.com/onsi/gomega v1.27.7
99
k8s.io/api v0.27.2

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
6565
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
6666
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
6767
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
68-
github.com/civo/civogo v0.3.35 h1:O59vmPk7cF4/d3MfdHPsbG41i47FE5P0l1xnDhIzS1M=
69-
github.com/civo/civogo v0.3.35/go.mod h1:ovGwXtszFiTsVq1OgKG9CtE8q8TPm+4bwE13KuJBr9E=
68+
github.com/civo/civogo v0.3.41 h1:/LkE/BYvsUFKwDWZ41xT2dFHGEdfr5hoWwlhPQFHxPI=
69+
github.com/civo/civogo v0.3.41/go.mod h1:54lv/FOf7gh6wE9ZwVdw4yBehk8V1CvU9aWa4v6dvW0=
7070
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
7171
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
7272
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=

0 commit comments

Comments
 (0)