Skip to content

Commit e19922a

Browse files
authored
Add support for PROXY protocol (#198)
* Vendor github.com/digitalocean/godo@v1.9.0 for PROXY protocol support * Add support for PROXY protocol Adds a new annotation service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol to toggle PROXY protocol usage on and off.
1 parent e704959 commit e19922a

File tree

10 files changed

+159
-14
lines changed

10 files changed

+159
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## unreleased
44

5+
* loadbalancers: add support for PROXY protocol (@timoreimann)
56
* loadbalancers: support numeric health check parameters (@timoreimann)
67

78
## v0.1.10 (beta) - Feb 26th 2019

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
@@ -43,8 +43,8 @@
4343
revision = "f2b4162afba35581b6d4a50d3b8f34e33c144682"
4444

4545
[[constraint]]
46-
version = "v1.7.5"
4746
name = "github.com/digitalocean/godo"
47+
version = "1.9.0"
4848

4949
[[constraint]]
5050
branch = "master"

cloud-controller-manager/do/loadbalancers.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ const (
108108
// should be redirected to Https. Defaults to false
109109
annDORedirectHTTPToHTTPS = "service.beta.kubernetes.io/do-loadbalancer-redirect-http-to-https"
110110

111+
// annDOEnableProxyProtocol is the annotation specifying whether PROXY protocol should
112+
// be enabled. Defaults to false.
113+
annDOEnableProxyProtocol = "service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol"
114+
111115
// defaultActiveTimeout is the number of seconds to wait for a load balancer to
112116
// reach the active state.
113117
defaultActiveTimeout = 90
@@ -355,6 +359,10 @@ func (l *loadBalancers) buildLoadBalancerRequest(service *v1.Service, nodes []*v
355359
algorithm := getAlgorithm(service)
356360

357361
redirectHTTPToHTTPS := getRedirectHTTPToHTTPS(service)
362+
enableProxyProtocol, err := getEnableProxyProtocol(service)
363+
if err != nil {
364+
return nil, err
365+
}
358366

359367
var tags []string
360368
if l.clusterID != "" {
@@ -371,6 +379,7 @@ func (l *loadBalancers) buildLoadBalancerRequest(service *v1.Service, nodes []*v
371379
Tags: tags,
372380
Algorithm: algorithm,
373381
RedirectHttpToHttps: redirectHTTPToHTTPS,
382+
EnableProxyProtocol: enableProxyProtocol,
374383
}, nil
375384
}
376385

@@ -750,3 +759,19 @@ func getRedirectHTTPToHTTPS(service *v1.Service) bool {
750759

751760
return redirectHTTPToHTTPSBool
752761
}
762+
763+
// getEnableProxyProtocol returns whether PROXY protocol should be enabled.
764+
// False is returned if not specified.
765+
func getEnableProxyProtocol(service *v1.Service) (bool, error) {
766+
enableProxyProtocolStr, ok := service.Annotations[annDOEnableProxyProtocol]
767+
if !ok {
768+
return false, nil
769+
}
770+
771+
enableProxyProtocol, err := strconv.ParseBool(enableProxyProtocolStr)
772+
if err != nil {
773+
return false, fmt.Errorf("failed to parse proxy protocol flag %q from annotation %q: %s", enableProxyProtocolStr, annDOEnableProxyProtocol, err)
774+
}
775+
776+
return enableProxyProtocol, nil
777+
}

cloud-controller-manager/do/loadbalancers_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,82 @@ func Test_getRedirectHTTPToHTTPS(t *testing.T) {
13701370

13711371
}
13721372

1373+
func Test_getEnableProxyProtocol(t *testing.T) {
1374+
testcases := []struct {
1375+
name string
1376+
service *v1.Service
1377+
wantErr bool
1378+
wantEnableProxyProtocol bool
1379+
}{
1380+
{
1381+
name: "enabled",
1382+
service: &v1.Service{
1383+
ObjectMeta: metav1.ObjectMeta{
1384+
Name: "test",
1385+
UID: "abc123",
1386+
Annotations: map[string]string{
1387+
annDOEnableProxyProtocol: "true",
1388+
},
1389+
},
1390+
},
1391+
wantErr: false,
1392+
wantEnableProxyProtocol: true,
1393+
},
1394+
{
1395+
name: "disabled",
1396+
service: &v1.Service{
1397+
ObjectMeta: metav1.ObjectMeta{
1398+
Name: "test",
1399+
UID: "abc123",
1400+
Annotations: map[string]string{
1401+
annDOEnableProxyProtocol: "false",
1402+
},
1403+
},
1404+
},
1405+
wantErr: false,
1406+
wantEnableProxyProtocol: false,
1407+
},
1408+
{
1409+
name: "annotation missing",
1410+
service: &v1.Service{
1411+
ObjectMeta: metav1.ObjectMeta{
1412+
Name: "test",
1413+
UID: "abc123",
1414+
},
1415+
},
1416+
wantErr: false,
1417+
wantEnableProxyProtocol: false,
1418+
},
1419+
{
1420+
name: "illegal value",
1421+
service: &v1.Service{
1422+
ObjectMeta: metav1.ObjectMeta{
1423+
Name: "test",
1424+
UID: "abc123",
1425+
Annotations: map[string]string{
1426+
annDOEnableProxyProtocol: "42",
1427+
},
1428+
},
1429+
},
1430+
wantErr: true,
1431+
wantEnableProxyProtocol: false,
1432+
},
1433+
}
1434+
1435+
for _, test := range testcases {
1436+
t.Run(test.name, func(t *testing.T) {
1437+
gotEnabledProxyProtocol, err := getEnableProxyProtocol(test.service)
1438+
if test.wantErr != (err != nil) {
1439+
t.Errorf("got error %q, want error: %t", err, test.wantErr)
1440+
}
1441+
1442+
if gotEnabledProxyProtocol != test.wantEnableProxyProtocol {
1443+
t.Fatalf("got enabled proxy protocol %t, want %t", gotEnabledProxyProtocol, test.wantEnableProxyProtocol)
1444+
}
1445+
})
1446+
}
1447+
}
1448+
13731449
func Test_buildLoadBalancerRequest(t *testing.T) {
13741450
testcases := []struct {
13751451
name string

docs/controllers/services/annotations.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Service Annotations
22

3-
DigitalOcean cloud controller manager watches for Services of type `LoadBalancer` and will create corresponding DigitalOcean Load Balancers matching the Kubernetes service. The Load Balancer can be configured by applying annotations to the Service resource. The following annotations can be used:
3+
DigitalOcean cloud controller manager watches for Services of type `LoadBalancer` and will create corresponding DigitalOcean Load Balancers matching the Kubernetes service. The Load Balancer can be configured by applying annotations to the Service resource. The annotations listed below can be used.
4+
5+
See example Kubernetes Services using LoadBalancers [here](examples/).
46

57
## service.beta.kubernetes.io/do-loadbalancer-protocol
68

@@ -62,4 +64,6 @@ Specifies the TTL of cookies used for loadbalancer sticky sessions. This annotat
6264

6365
Indicates whether or not http traffic should be redirected to https. Options are `true` or `false`. Defaults to `false`.
6466

65-
See example Kubernetes Services using LoadBalancers [here](examples/).
67+
## service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol
68+
69+
Indicates whether PROXY protocol should be enabled. Options are `true` or `false`. Defaults to `false`.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
kind: Service
3+
apiVersion: v1
4+
metadata:
5+
name: http-lb
6+
annotations:
7+
service.beta.kubernetes.io/do-loadbalancer-enable-proxy-protocol: "true"
8+
spec:
9+
type: LoadBalancer
10+
selector:
11+
app: nginx-example
12+
ports:
13+
- name: http
14+
protocol: TCP
15+
port: 80
16+
17+
---
18+
apiVersion: extensions/v1beta1
19+
kind: Deployment
20+
metadata:
21+
name: nginx-example
22+
spec:
23+
replicas: 2
24+
template:
25+
metadata:
26+
labels:
27+
app: nginx-example
28+
spec:
29+
containers:
30+
- name: nginx
31+
image: nginx
32+
ports:
33+
- containerPort: 80
34+
protocol: TCP

vendor/github.com/digitalocean/godo/godo.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/digitalocean/godo/load_balancers.go

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

vendor/github.com/digitalocean/godo/storage.go

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

0 commit comments

Comments
 (0)