Skip to content

Commit 4b2f3e7

Browse files
Lb maxconcurrent req (#15)
* update k8s api version to v0.27.2 * loadbalancer max concurrent requests annotation * Add test Signed-off-by: Haardik Dharma <[email protected]> * Update unit tests Signed-off-by: Haardik Dharma <[email protected]> * Add note about downtime in README Signed-off-by: Haardik Dharma <[email protected]> --------- Signed-off-by: Haardik Dharma <[email protected]> Co-authored-by: Haardik Dharma <[email protected]>
1 parent 665e252 commit 4b2f3e7

File tree

6 files changed

+586
-423
lines changed

6 files changed

+586
-423
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Read More: https://www.civo.com/learn/managing-external-load-balancers-on-civo
1919
| Annotation | Description | Example Values |
2020
|------------|-------------|----------------|
2121
| kubernetes.civo.com/firewall-id | If provided, an existing Firewall will be used. | 03093EF6-31E6-48B1-AB1D-152AC3A8C90A |
22+
| kubernetes.civo.com/max-concurrent-requests | If provided, the user can specify the max number of concurrent requests a loadbalancer could afford. Note: Defaults to 10000. Whenever user updates this value, there will be a downtime for the loadbalancer (usually < 1 minute) | 10000, 20000, 30000, 40000, 50000 |
2223
| kubernetes.civo.com/loadbalancer-enable-proxy-protocol | If set, a proxy-protocol header will be sent via the load balancer. <br /><br />NB: This requires support from the Service End Points within the cluster. | send-proxy<br />send-proxy-v2 |
2324
| kubernetes.civo.com/loadbalancer-algorithm | Custom the algorithm the external load balancer uses | round_robin<br />least_connections |
2425
| 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 |

cloud-controller-manager/civo/loadbalancer.go

+32
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package civo
33
import (
44
"context"
55
"fmt"
6+
"strconv"
67
"strings"
78

89
v1 "k8s.io/api/core/v1"
@@ -23,6 +24,9 @@ const (
2324
// annotationCivoFirewallID is the annotation specifying the CivoFirewall ID.
2425
annotationCivoFirewallID = "kubernetes.civo.com/firewall-id"
2526

27+
// annotationCivoLoadBalancerMaxConcurrentRequests is the annotation specifying the max number of concurrent requests a CivoLoadBalancer can afford
28+
annotationCivoLoadBalancerMaxConcurrentRequests = "kubernetes.civo.com/max-concurrent-requests"
29+
2630
// annotationCivoLoadBalancerEnableProxyProtocol is the annotation specifying whether PROXY protocol should be enabled.
2731
annotationCivoLoadBalancerEnableProxyProtocol = "kubernetes.civo.com/loadbalancer-enable-proxy-protocol"
2832

@@ -135,6 +139,15 @@ func (l *loadbalancer) updateLBConfig(civolb *civogo.LoadBalancer, service *v1.S
135139
lbuc.FirewallID = firewallID
136140
}
137141

142+
if maxConcurrentReq := getMaxConcurrentRequests(service); maxConcurrentReq != "" {
143+
maxReq, err := strconv.Atoi(maxConcurrentReq)
144+
if err != nil {
145+
klog.Errorf("Unable to parse Loadbalancer MaxConcurrentRequests annotation, error: %s", err.Error())
146+
return nil, err
147+
}
148+
lbuc.MaxConcurrentRequests = &maxReq
149+
}
150+
138151
backends := []civogo.LoadBalancerBackendConfig{}
139152
for _, port := range service.Spec.Ports {
140153
for _, node := range nodes {
@@ -257,6 +270,9 @@ func (l *loadbalancer) UpdateLoadBalancer(ctx context.Context, clusterName strin
257270
if civolb.EnableProxyProtocol != ulb.EnableProxyProtocol {
258271
updateServiceAnnotation(service, annotationCivoLoadBalancerEnableProxyProtocol, ulb.EnableProxyProtocol)
259272
}
273+
if civolb.MaxConcurrentRequests != ulb.MaxConcurrentRequests {
274+
updateServiceAnnotation(service, annotationCivoLoadBalancerMaxConcurrentRequests, fmt.Sprint(ulb.MaxConcurrentRequests))
275+
}
260276

261277
return nil
262278
}
@@ -315,6 +331,7 @@ func getLoadBalancer(ctx context.Context, c civogo.Clienter, kclient kubernetes.
315331
updateServiceAnnotation(service, annotationCivoLoadBalancerName, civolb.Name)
316332
updateServiceAnnotation(service, annotationCivoClusterID, ClusterID)
317333
updateServiceAnnotation(service, annotationCivoFirewallID, civolb.FirewallID)
334+
updateServiceAnnotation(service, annotationCivoLoadBalancerMaxConcurrentRequests, fmt.Sprint(civolb.MaxConcurrentRequests))
318335
updateServiceAnnotation(service, annotationCivoLoadBalancerAlgorithm, civolb.Algorithm)
319336
}
320337
}
@@ -346,6 +363,15 @@ func createLoadBalancer(ctx context.Context, clusterName string, service *v1.Ser
346363
lbc.FirewallID = firewallID
347364
}
348365

366+
if maxConcurrentReq := getMaxConcurrentRequests(service); maxConcurrentReq != "" {
367+
maxReq, err := strconv.Atoi(maxConcurrentReq)
368+
if err != nil {
369+
klog.Errorf("Unable to parse Loadbalancer MaxConcurrentRequests annotation, error: %s", err.Error())
370+
return err
371+
}
372+
lbc.MaxConcurrentRequests = &maxReq
373+
}
374+
349375
backends := []civogo.LoadBalancerBackendConfig{}
350376
for _, port := range service.Spec.Ports {
351377
for _, node := range nodes {
@@ -373,6 +399,7 @@ func createLoadBalancer(ctx context.Context, clusterName string, service *v1.Ser
373399
updateServiceAnnotation(service, annotationCivoLoadBalancerID, lb.ID)
374400
updateServiceAnnotation(service, annotationCivoLoadBalancerName, lb.Name)
375401
updateServiceAnnotation(service, annotationCivoLoadBalancerAlgorithm, lb.Algorithm)
402+
updateServiceAnnotation(service, annotationCivoLoadBalancerMaxConcurrentRequests, fmt.Sprint(lb.MaxConcurrentRequests))
376403

377404
if lb.EnableProxyProtocol != "" {
378405
updateServiceAnnotation(service, annotationCivoLoadBalancerEnableProxyProtocol, lb.EnableProxyProtocol)
@@ -413,6 +440,11 @@ func getFirewallID(service *v1.Service) string {
413440
return service.Annotations[annotationCivoFirewallID]
414441
}
415442

443+
// getMaxConcurrentRequests returns the max concurrent requests a CivoLoadbalancer could afford from the service annotation.
444+
func getMaxConcurrentRequests(service *v1.Service) string {
445+
return service.Annotations[annotationCivoLoadBalancerMaxConcurrentRequests]
446+
}
447+
416448
func getProtocol(svc *v1.Service, port v1.ServicePort) string {
417449
if svc.Annotations[annotationCivoProtocol] != "" {
418450
return strings.ToUpper(svc.Annotations[annotationCivoProtocol])

cloud-controller-manager/civo/loadbalancer_test.go

+43-15
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,26 @@ func TestUpdateServiceAnnotation(t *testing.T) {
216216
},
217217
},
218218
},
219+
{
220+
"Annotation for max concurrent requests set to 20000",
221+
&corev1.Service{
222+
Spec: corev1.ServiceSpec{
223+
Type: corev1.ServiceTypeLoadBalancer,
224+
},
225+
},
226+
"kubernetes.civo.com/max-concurrent-requests",
227+
"20000",
228+
&corev1.Service{
229+
ObjectMeta: metav1.ObjectMeta{
230+
Annotations: map[string]string{
231+
"kubernetes.civo.com/max-concurrent-requests": "20000",
232+
},
233+
},
234+
Spec: corev1.ServiceSpec{
235+
Type: corev1.ServiceTypeLoadBalancer,
236+
},
237+
},
238+
},
219239
}
220240

221241
for _, test := range tests {
@@ -261,10 +281,11 @@ func TestGetLoadBalanacer(t *testing.T) {
261281
Name: "test",
262282
Namespace: corev1.NamespaceDefault,
263283
Annotations: map[string]string{
264-
annotationCivoLoadBalancerID: "6dc1c87d-b8a1-42cd-8fc6-8293378e5715",
265-
annotationCivoFirewallID: "fc91d382-2609-4f5c-a875-1491776fab8c",
266-
annotationCivoClusterID: "a32fe5eb-1922-43e8-81bc-7f83b4011334",
267-
annotationCivoLoadBalancerName: "civo-lb-test",
284+
annotationCivoLoadBalancerID: "6dc1c87d-b8a1-42cd-8fc6-8293378e5715",
285+
annotationCivoFirewallID: "fc91d382-2609-4f5c-a875-1491776fab8c",
286+
annotationCivoClusterID: "a32fe5eb-1922-43e8-81bc-7f83b4011334",
287+
annotationCivoLoadBalancerName: "civo-lb-test",
288+
annotationCivoLoadBalancerMaxConcurrentRequests: "10000",
268289
},
269290
},
270291
Spec: corev1.ServiceSpec{
@@ -281,13 +302,14 @@ func TestGetLoadBalanacer(t *testing.T) {
281302
},
282303
store: []civogo.LoadBalancer{
283304
{
284-
ID: "6dc1c87d-b8a1-42cd-8fc6-8293378e5715",
285-
Name: "civo-lb-test",
286-
Algorithm: "round-robin",
287-
PublicIP: "192.168.11.11",
288-
FirewallID: "fc91d382-2609-4f5c-a875-1491776fab8c",
289-
ClusterID: "a32fe5eb-1922-43e8-81bc-7f83b4011334",
290-
State: statusAvailable,
305+
ID: "6dc1c87d-b8a1-42cd-8fc6-8293378e5715",
306+
Name: "civo-lb-test",
307+
Algorithm: "round-robin",
308+
PublicIP: "192.168.11.11",
309+
FirewallID: "fc91d382-2609-4f5c-a875-1491776fab8c",
310+
ClusterID: "a32fe5eb-1922-43e8-81bc-7f83b4011334",
311+
State: statusAvailable,
312+
MaxConcurrentRequests: 10000,
291313
},
292314
},
293315
expected: &corev1.LoadBalancerStatus{
@@ -683,10 +705,11 @@ func TestUpdateLoadBalancer(t *testing.T) {
683705
Name: "test-update",
684706
Namespace: corev1.NamespaceDefault,
685707
Annotations: map[string]string{
686-
annotationCivoLoadBalancerID: "6dc1c87d-b8a1-42cd-8fc6-8293378e5715",
687-
annotationCivoClusterID: "a32fe5eb-1922-43e8-81bc-7f83b4011334",
688-
annotationCivoLoadBalancerAlgorithm: "least-connections",
689-
annotationCivoLoadBalancerEnableProxyProtocol: "send-proxy",
708+
annotationCivoLoadBalancerID: "6dc1c87d-b8a1-42cd-8fc6-8293378e5715",
709+
annotationCivoClusterID: "a32fe5eb-1922-43e8-81bc-7f83b4011334",
710+
annotationCivoLoadBalancerAlgorithm: "least-connections",
711+
annotationCivoLoadBalancerEnableProxyProtocol: "send-proxy",
712+
annotationCivoLoadBalancerMaxConcurrentRequests: "30000",
690713
},
691714
},
692715
Spec: corev1.ServiceSpec{
@@ -746,6 +769,7 @@ func TestUpdateLoadBalancer(t *testing.T) {
746769
IP: "192.168.1.2",
747770
},
748771
},
772+
MaxConcurrentRequests: 30000,
749773
},
750774
},
751775
err: nil,
@@ -791,6 +815,10 @@ func TestUpdateLoadBalancer(t *testing.T) {
791815
if svc.Annotations[annotationCivoLoadBalancerAlgorithm] != "" {
792816
g.Expect(svc.Annotations[annotationCivoLoadBalancerAlgorithm]).To(Equal("least-connections"))
793817
}
818+
819+
if svc.Annotations[annotationCivoLoadBalancerMaxConcurrentRequests] != "" {
820+
g.Expect(svc.Annotations[annotationCivoLoadBalancerMaxConcurrentRequests]).To(Equal("30000"))
821+
}
794822
})
795823
}
796824
}

e2e/suite_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func run(secret *corev1.Secret, kubeconfig string) {
239239

240240
// Set the provider name
241241
opts.KubeCloudShared.CloudProvider.Name = civo.ProviderName
242-
opts.Kubeconfig = "./kubeconfig"
242+
opts.Generic.ClientConnection.Kubeconfig = "./kubeconfig"
243243
// Disable Cloud Routes
244244
opts.KubeCloudShared.ConfigureCloudRoutes = false
245245

go.mod

+107-25
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,115 @@
11
module github.com/civo/civo-cloud-controller-manager
22

3-
go 1.16
3+
go 1.20
44

55
require (
6-
github.com/civo/civogo v0.3.19
7-
github.com/emicklei/go-restful v2.11.1+incompatible // indirect
8-
github.com/go-openapi/swag v0.19.7 // indirect
9-
github.com/google/go-cmp v0.5.6 // indirect
10-
github.com/google/uuid v1.3.0 // indirect
6+
github.com/civo/civogo v0.3.35
117
github.com/joho/godotenv v1.4.0
12-
github.com/onsi/gomega v1.19.0
13-
github.com/sirupsen/logrus v1.8.1 // indirect
14-
k8s.io/api v0.21.1
15-
k8s.io/apimachinery v0.21.1
16-
k8s.io/client-go v12.0.0+incompatible
17-
k8s.io/cloud-provider v0.21.1
18-
k8s.io/component-base v0.21.1
19-
k8s.io/klog/v2 v2.9.0
20-
sigs.k8s.io/controller-runtime v0.0.0-00010101000000-000000000000
8+
github.com/onsi/gomega v1.27.7
9+
k8s.io/api v0.27.2
10+
k8s.io/apimachinery v0.27.2
11+
k8s.io/client-go v0.27.2
12+
k8s.io/cloud-provider v0.27.2
13+
k8s.io/component-base v0.27.2
14+
k8s.io/klog/v2 v2.90.1
15+
sigs.k8s.io/controller-runtime v0.15.0
2116
)
2217

23-
replace (
24-
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.4.1
25-
github.com/openshift/api => github.com/openshift/api v0.0.0-20200526144822-34f54f12813a
26-
github.com/openshift/client-go => github.com/openshift/client-go v0.0.0-20200521150516-05eb9880269c
27-
github.com/operator-framework/operator-lifecycle-manager => github.com/operator-framework/operator-lifecycle-manager v0.0.0-20190128024246-5eb7ae5bdb7a
28-
k8s.io/client-go => k8s.io/client-go v0.21.1
29-
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.21.1
30-
k8s.io/kubectl => k8s.io/kubectl v0.21.1
31-
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.9.0
32-
sigs.k8s.io/structured-merge-diff => sigs.k8s.io/structured-merge-diff v1.0.0
18+
require (
19+
cloud.google.com/go/compute/metadata v0.2.1 // indirect
20+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
21+
github.com/NYTimes/gziphandler v1.1.1 // indirect
22+
github.com/antlr/antlr4/runtime/Go/antlr v1.4.10 // indirect
23+
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
24+
github.com/beorn7/perks v1.0.1 // indirect
25+
github.com/blang/semver/v4 v4.0.0 // indirect
26+
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
27+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
28+
github.com/coreos/go-semver v0.3.0 // indirect
29+
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
30+
github.com/davecgh/go-spew v1.1.1 // indirect
31+
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
32+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
33+
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
34+
github.com/felixge/httpsnoop v1.0.3 // indirect
35+
github.com/fsnotify/fsnotify v1.6.0 // indirect
36+
github.com/go-logr/logr v1.2.4 // indirect
37+
github.com/go-logr/stdr v1.2.2 // indirect
38+
github.com/go-openapi/jsonpointer v0.19.6 // indirect
39+
github.com/go-openapi/jsonreference v0.20.1 // indirect
40+
github.com/go-openapi/swag v0.22.3 // indirect
41+
github.com/gogo/protobuf v1.3.2 // indirect
42+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
43+
github.com/golang/protobuf v1.5.3 // indirect
44+
github.com/google/cel-go v0.12.6 // indirect
45+
github.com/google/gnostic v0.5.7-v3refs // indirect
46+
github.com/google/go-cmp v0.5.9 // indirect
47+
github.com/google/go-querystring v1.1.0 // indirect
48+
github.com/google/gofuzz v1.1.0 // indirect
49+
github.com/google/uuid v1.3.0 // indirect
50+
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
51+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
52+
github.com/imdario/mergo v0.3.6 // indirect
53+
github.com/inconshreveable/mousetrap v1.0.1 // indirect
54+
github.com/josharian/intern v1.0.0 // indirect
55+
github.com/json-iterator/go v1.1.12 // indirect
56+
github.com/mailru/easyjson v0.7.7 // indirect
57+
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
58+
github.com/mitchellh/mapstructure v1.4.1 // indirect
59+
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
60+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
61+
github.com/modern-go/reflect2 v1.0.2 // indirect
62+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
63+
github.com/pkg/errors v0.9.1 // indirect
64+
github.com/prometheus/client_golang v1.15.1 // indirect
65+
github.com/prometheus/client_model v0.4.0 // indirect
66+
github.com/prometheus/common v0.42.0 // indirect
67+
github.com/prometheus/procfs v0.9.0 // indirect
68+
github.com/spf13/cobra v1.6.0 // indirect
69+
github.com/spf13/pflag v1.0.5 // indirect
70+
github.com/stoewer/go-strcase v1.2.0 // indirect
71+
go.etcd.io/etcd/api/v3 v3.5.7 // indirect
72+
go.etcd.io/etcd/client/pkg/v3 v3.5.7 // indirect
73+
go.etcd.io/etcd/client/v3 v3.5.7 // indirect
74+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.35.0 // indirect
75+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.35.1 // indirect
76+
go.opentelemetry.io/otel v1.10.0 // indirect
77+
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.10.0 // indirect
78+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.10.0 // indirect
79+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.10.0 // indirect
80+
go.opentelemetry.io/otel/metric v0.31.0 // indirect
81+
go.opentelemetry.io/otel/sdk v1.10.0 // indirect
82+
go.opentelemetry.io/otel/trace v1.10.0 // indirect
83+
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
84+
go.uber.org/atomic v1.7.0 // indirect
85+
go.uber.org/multierr v1.6.0 // indirect
86+
go.uber.org/zap v1.24.0 // indirect
87+
golang.org/x/crypto v0.1.0 // indirect
88+
golang.org/x/net v0.10.0 // indirect
89+
golang.org/x/oauth2 v0.5.0 // indirect
90+
golang.org/x/sync v0.1.0 // indirect
91+
golang.org/x/sys v0.8.0 // indirect
92+
golang.org/x/term v0.8.0 // indirect
93+
golang.org/x/text v0.9.0 // indirect
94+
golang.org/x/time v0.3.0 // indirect
95+
google.golang.org/appengine v1.6.7 // indirect
96+
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
97+
google.golang.org/grpc v1.51.0 // indirect
98+
google.golang.org/protobuf v1.30.0 // indirect
99+
gopkg.in/inf.v0 v0.9.1 // indirect
100+
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
101+
gopkg.in/yaml.v2 v2.4.0 // indirect
102+
gopkg.in/yaml.v3 v3.0.1 // indirect
103+
k8s.io/apiserver v0.27.2 // indirect
104+
k8s.io/component-helpers v0.27.2 // indirect
105+
k8s.io/controller-manager v0.27.2 // indirect
106+
k8s.io/kms v0.27.2 // indirect
107+
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
108+
k8s.io/utils v0.0.0-20230209194617-a36077c30491 // indirect
109+
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.1.2 // indirect
110+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
111+
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
112+
sigs.k8s.io/yaml v1.3.0 // indirect
33113
)
114+
115+
replace cloud.google.com/go/compute/metadata => cloud.google.com/go/compute/metadata v0.2.1

0 commit comments

Comments
 (0)