Skip to content

Commit cdb5038

Browse files
jhorwit2prydie
authored andcommitted
Add support for idle connection timeout (#179)
* Add support for idle connection timeout * Upgrade oci-go-sdk to v1.2.0 * Add failure test * Document idle timeout annotation Fixes: #134
1 parent c9c5377 commit cdb5038

File tree

326 files changed

+14078
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

326 files changed

+14078
-391
lines changed

Gopkg.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474

7575
[[constraint]]
7676
name = "github.com/oracle/oci-go-sdk"
77-
version = "1.0.0"
77+
version = "1.2.0"
7878

7979
[prune]
8080
non-go = true

docs/load-balancer-annotations.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ spec:
2020
2121
## Load balancer properties
2222
23-
| Name | Description | Default |
24-
| ---- | ----------- | ------- |
25-
| `oci-load-balancer-internal` | Create an [internal load balancer][1]. Cannot be modified after load balancer creation. | `false` |
26-
| `oci-load-balancer-shape` | A template that determines the load balancer's total pre-provisioned maximum capacity (bandwidth) for ingress plus egress traffic. Available shapes include `100Mbps`, `400Mbps`, and `8000Mbps.` Cannot be modified after load balancer creation. | `"100Mbps"` |
27-
| `oci-load-balancer-subnet1` | The OCID of the first [subnet][2] of the two required subnets to attach the load balancer to. Must be in separate Availability Domains. | Value provided in config file |
28-
| `oci-load-balancer-subnet2` | The OCID of the second [subnet][2] of the two required subnets to attach the load balancer to. Must be in separate Availability Domains. | Value provided in config file |
23+
| Name | Description | Default |
24+
| ----- | ----------- | ------- |
25+
| `oci-load-balancer-internal` | Create an [internal load balancer][1]. Cannot be modified after load balancer creation. | `false` |
26+
| `oci-load-balancer-shape` | A template that determines the load balancer's total pre-provisioned maximum capacity (bandwidth) for ingress plus egress traffic. Available shapes include `100Mbps`, `400Mbps`, and `8000Mbps.` Cannot be modified after load balancer creation. | `"100Mbps"` |
27+
| `oci-load-balancer-subnet1` | The OCID of the first [subnet][2] of the two required subnets to attach the load balancer to. Must be in separate Availability Domains. | Value provided in config file |
28+
| `oci-load-balancer-subnet2` | The OCID of the second [subnet][2] of the two required subnets to attach the load balancer to. Must be in separate Availability Domains. | Value provided in config file |
29+
| `oci-load-balancer-connection-idle-timeout` | The maximum idle time, in seconds, allowed between two successive receive or two successive send operations between the client and backend servers. | `300` for TCP listeners, `60` for HTTP listeners |
2930

3031
## TLS-related
3132

pkg/oci/load_balancer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ const (
6262
// have SSL enabled.
6363
// See: https://kubernetes.io/docs/concepts/services-networking/ingress/#tls
6464
ServiceAnnotationLoadBalancerTLSSecret = "service.beta.kubernetes.io/oci-load-balancer-tls-secret"
65+
66+
// ServiceAnnotationLoadBalancerConnectionIdleTimeout is the annotation used
67+
// on the service to specify the idle connection timeout.
68+
ServiceAnnotationLoadBalancerConnectionIdleTimeout = "service.beta.kubernetes.io/oci-load-balancer-connection-idle-timeout"
6569
)
6670

6771
// DefaultLoadBalancerPolicy defines the default traffic policy for load

pkg/oci/load_balancer_spec.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package oci
1616

1717
import (
1818
"fmt"
19+
"strconv"
1920

2021
"github.com/oracle/oci-go-sdk/common"
2122
"github.com/oracle/oci-go-sdk/loadbalancer"
@@ -120,12 +121,17 @@ func NewLBSpec(svc *v1.Service, nodes []*v1.Node, defaultSubnets []string, sslCf
120121
subnets = subnets[:1]
121122
}
122123

124+
listeners, err := getListeners(svc, sslCfg)
125+
if err != nil {
126+
return nil, err
127+
}
128+
123129
return &LBSpec{
124130
Name: GetLoadBalancerName(svc),
125131
Shape: shape,
126132
Internal: internal,
127133
Subnets: subnets,
128-
Listeners: getListeners(svc, sslCfg),
134+
Listeners: listeners,
129135
BackendSets: getBackendSets(svc, nodes),
130136

131137
Ports: getPorts(svc),
@@ -268,19 +274,44 @@ func getSSLConfiguration(cfg *SSLConfig, port int) *loadbalancer.SslConfiguratio
268274
}
269275
}
270276

271-
func getListeners(svc *v1.Service, sslCfg *SSLConfig) map[string]loadbalancer.ListenerDetails {
277+
func getListeners(svc *v1.Service, sslCfg *SSLConfig) (map[string]loadbalancer.ListenerDetails, error) {
278+
// Determine if connection idle timeout has been specified
279+
var connectionIdleTimeout int
280+
connectionIdleTimeoutAnnotation := svc.Annotations[ServiceAnnotationLoadBalancerConnectionIdleTimeout]
281+
if connectionIdleTimeoutAnnotation != "" {
282+
timeout, err := strconv.ParseInt(connectionIdleTimeoutAnnotation, 10, 64)
283+
if err != nil {
284+
return nil, fmt.Errorf("error parsing service annotation: %s=%s",
285+
ServiceAnnotationLoadBalancerConnectionIdleTimeout,
286+
connectionIdleTimeoutAnnotation,
287+
)
288+
}
289+
290+
connectionIdleTimeout = int(timeout)
291+
}
292+
272293
listeners := make(map[string]loadbalancer.ListenerDetails)
273294
for _, servicePort := range svc.Spec.Ports {
274295
protocol := string(servicePort.Protocol)
275296
port := int(servicePort.Port)
276297
sslConfiguration := getSSLConfiguration(sslCfg, port)
277298
name := getListenerName(protocol, port, sslConfiguration)
278-
listeners[name] = loadbalancer.ListenerDetails{
299+
300+
listener := loadbalancer.ListenerDetails{
279301
DefaultBackendSetName: common.String(getBackendSetName(string(servicePort.Protocol), int(servicePort.Port))),
280302
Protocol: &protocol,
281303
Port: &port,
282304
SslConfiguration: sslConfiguration,
283305
}
306+
307+
if connectionIdleTimeout > 0 {
308+
listener.ConnectionConfiguration = &loadbalancer.ConnectionConfiguration{
309+
IdleTimeout: common.Int(int(connectionIdleTimeout)),
310+
}
311+
}
312+
313+
listeners[name] = listener
284314
}
285-
return listeners
315+
316+
return listeners, nil
286317
}

pkg/oci/load_balancer_spec_test.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,63 @@ func TestNewLBSpecSuccess(t *testing.T) {
248248
},
249249
},
250250
},
251+
"custom idle connection timeout": {
252+
defaultSubnetOne: "one",
253+
defaultSubnetTwo: "two",
254+
service: &v1.Service{
255+
ObjectMeta: metav1.ObjectMeta{
256+
Namespace: "kube-system",
257+
Name: "testservice",
258+
UID: "test-uid",
259+
Annotations: map[string]string{
260+
ServiceAnnotationLoadBalancerConnectionIdleTimeout: "404",
261+
},
262+
},
263+
Spec: v1.ServiceSpec{
264+
SessionAffinity: v1.ServiceAffinityNone,
265+
Ports: []v1.ServicePort{
266+
v1.ServicePort{
267+
Protocol: v1.ProtocolTCP,
268+
Port: int32(80),
269+
},
270+
},
271+
},
272+
},
273+
expected: &LBSpec{
274+
Name: "test-uid",
275+
Shape: "100Mbps",
276+
Internal: false,
277+
Subnets: []string{"one", "two"},
278+
Listeners: map[string]loadbalancer.ListenerDetails{
279+
"TCP-80": loadbalancer.ListenerDetails{
280+
DefaultBackendSetName: common.String("TCP-80"),
281+
Port: common.Int(80),
282+
Protocol: common.String("TCP"),
283+
ConnectionConfiguration: &loadbalancer.ConnectionConfiguration{
284+
IdleTimeout: common.Int(404),
285+
},
286+
},
287+
},
288+
BackendSets: map[string]loadbalancer.BackendSetDetails{
289+
"TCP-80": loadbalancer.BackendSetDetails{
290+
Backends: []loadbalancer.BackendDetails{},
291+
HealthChecker: &loadbalancer.HealthCheckerDetails{
292+
Protocol: common.String("HTTP"),
293+
Port: common.Int(10256),
294+
UrlPath: common.String("/healthz"),
295+
},
296+
Policy: common.String("ROUND_ROBIN"),
297+
},
298+
},
299+
SourceCIDRs: []string{"0.0.0.0/0"},
300+
Ports: map[string]portSpec{
301+
"TCP-80": portSpec{
302+
ListenerPort: 80,
303+
HealthCheckerPort: 10256,
304+
},
305+
},
306+
},
307+
},
251308
}
252309

253310
for name, tc := range testCases {
@@ -266,6 +323,7 @@ func TestNewLBSpecSuccess(t *testing.T) {
266323
})
267324
}
268325
}
326+
269327
func TestNewLBSpecFailure(t *testing.T) {
270328
testCases := map[string]struct {
271329
defaultSubnetOne string
@@ -307,6 +365,25 @@ func TestNewLBSpecFailure(t *testing.T) {
307365
},
308366
expectedErrMsg: "invalid service: OCI only supports SessionAffinity \"None\" currently",
309367
},
368+
"invalid idle connection timeout": {
369+
service: &v1.Service{
370+
ObjectMeta: metav1.ObjectMeta{
371+
Namespace: "kube-system",
372+
Name: "testservice",
373+
UID: "test-uid",
374+
Annotations: map[string]string{
375+
ServiceAnnotationLoadBalancerConnectionIdleTimeout: "whoops",
376+
},
377+
},
378+
Spec: v1.ServiceSpec{
379+
SessionAffinity: v1.ServiceAffinityNone,
380+
Ports: []v1.ServicePort{
381+
{Protocol: v1.ProtocolTCP},
382+
},
383+
},
384+
},
385+
expectedErrMsg: "error parsing service annotation: service.beta.kubernetes.io/oci-load-balancer-connection-idle-timeout=whoops",
386+
},
310387
}
311388

312389
for name, tc := range testCases {

vendor/github.com/oracle/oci-go-sdk/common/auth/certificate_retriever.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/oracle/oci-go-sdk/common/auth/certificate_retriever_test.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/oracle/oci-go-sdk/common/auth/configuration.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/oracle/oci-go-sdk/common/auth/instance_principal_key_provider.go

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)