Skip to content

Commit 7e5cdf9

Browse files
hdurand0710oktalz
authored andcommitted
MEDIUM: add ingress.class annotation to TCP CR
1 parent ecf8a20 commit 7e5cdf9

14 files changed

+219
-10
lines changed

deploy/tests/e2e/crd-tcp/config/tcp-cr-add-services.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apiVersion: ingress.v1.haproxy.org/v1
22
kind: TCP
33
metadata:
44
name: tcp-1
5+
annotations:
6+
ingress.class: haproxy
57
spec:
68
- name: tcp-http-echo-80
79
frontend:

deploy/tests/e2e/crd-tcp/config/tcp-cr-backend-switching-rule-acls.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apiVersion: ingress.v1.haproxy.org/v1
22
kind: TCP
33
metadata:
44
name: tcp-1
5+
annotations:
6+
ingress.class: haproxy
57
spec:
68
- name: tcp-test
79
frontend:

deploy/tests/e2e/crd-tcp/config/tcp-cr-backend-switching-rule.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apiVersion: ingress.v1.haproxy.org/v1
22
kind: TCP
33
metadata:
44
name: tcp-1
5+
annotations:
6+
ingress.class: haproxy
57
spec:
68
- name: tcp-test
79
frontend:

deploy/tests/e2e/crd-tcp/config/tcp-cr-full.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apiVersion: ingress.v1.haproxy.org/v1
22
kind: TCP
33
metadata:
44
name: tcp-1
5+
annotations:
6+
ingress.class: haproxy
57
spec:
68
- name: tcp-test
79
frontend:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: ingress.v1.haproxy.org/v1
2+
kind: TCP
3+
metadata:
4+
name: tcp-1
5+
spec:
6+
- name: tcp-http-echo-80
7+
frontend:
8+
name: fe-http-echo-80
9+
tcplog: true
10+
log_format: "%{+Q}o %t %s"
11+
binds:
12+
- name: v4
13+
port: 32766
14+
- name: v4v6
15+
address: "::"
16+
port: 32766
17+
v4v6: true
18+
service:
19+
name: "http-echo"
20+
port: 80
21+
services:
22+
- name: "http-echo-2"
23+
port: 443
24+
- name: "http-echo-2"
25+
port: 80

deploy/tests/e2e/crd-tcp/config/tcp-cr-ssl.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apiVersion: ingress.v1.haproxy.org/v1
22
kind: TCP
33
metadata:
44
name: tcp-1
5+
annotations:
6+
ingress.class: haproxy
57
spec:
68
- name: tcp-http-echo-443
79
frontend:

deploy/tests/e2e/crd-tcp/config/tcp-cr.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apiVersion: ingress.v1.haproxy.org/v1
22
kind: TCP
33
metadata:
44
name: tcp-1
5+
annotations:
6+
ingress.class: haproxy
57
spec:
68
- name: tcp-http-echo-80
79
frontend:
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2019 HAProxy Technologies LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build e2e_sequential
16+
17+
package crdtcp
18+
19+
import (
20+
"strings"
21+
"testing"
22+
23+
parser "github.com/haproxytech/config-parser/v5"
24+
"github.com/haproxytech/config-parser/v5/options"
25+
"github.com/haproxytech/kubernetes-ingress/deploy/tests/e2e"
26+
"github.com/stretchr/testify/suite"
27+
)
28+
29+
type TCPSuiteNoIngressClass struct {
30+
CRDTCPSuite
31+
}
32+
33+
func TestTCPSuiteNoIngressClasss(t *testing.T) {
34+
suite.Run(t, new(TCPSuiteNoIngressClass))
35+
}
36+
37+
// Expected configuration:
38+
// frontend tcpcr_e2e-tests-crd-tcp_fe-http-echo-80
39+
// backend e2e-tests-crd-tcp_http-echo-2_http ## from service/http-echo-2 (port 80)
40+
// backend e2e-tests-crd-tcp_http-echo-2_https ## from service/http-echo-2 (port 443)
41+
// backend e2e-tests-crd-tcp_http-echo_http ## from service/http-echo (port 80)
42+
// SHOULD NOT be created
43+
44+
func (suite *TCPSuiteNoIngressClass) Test_CRD_TCP_No_Ingress_Class() {
45+
suite.Run("TCP CR Additional Services", func() {
46+
var err error
47+
suite.Require().NoError(suite.test.Apply("config/tcp-cr-no-ingress-class.yaml", suite.test.GetNS(), nil))
48+
client2, err := e2e.NewHTTPClient(suite.tmplData.Host2, 32766)
49+
suite.Require().Eventually(func() bool {
50+
_, _, err := client2.Do()
51+
return err != nil // should return an error!
52+
}, e2e.WaitDuration, e2e.TickDuration)
53+
54+
// Get updated config and check it
55+
cfg, err := suite.test.GetIngressControllerFile("/etc/haproxy/haproxy.cfg")
56+
suite.NoError(err, "Could not get Haproxy config")
57+
reader := strings.NewReader(cfg)
58+
p, err := parser.New(options.Reader(reader))
59+
suite.NoError(err, "Could not get Haproxy config parser")
60+
61+
_, err = p.Get(parser.Frontends, "tcpcr_e2e-tests-crd-tcp_fe-http-echo-80", "bind")
62+
suite.Require().Equal(err.Error(), "section missing")
63+
_, err = p.Get(parser.Backends, "e2e-tests-crd-tcp_http-echo-2_http", "mode")
64+
suite.Require().Equal(err.Error(), "section missing")
65+
_, err = p.Get(parser.Backends, "e2e-tests-crd-tcp_http-echo-2_https", "mode")
66+
suite.Require().Equal(err.Error(), "section missing")
67+
_, err = p.Get(parser.Backends, "e2e-tests-crd-tcp_http-echo_http", "mode")
68+
suite.Require().Equal(err.Error(), "section missing")
69+
})
70+
}

documentation/custom-resource-tcp.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ kind: TCP
3535
metadata:
3636
name: tcp-1
3737
namespace: test
38+
annotations:
39+
ingress.class: haproxy
3840
spec:
3941
- name: tcp-http-echo-8443
4042
frontend:
@@ -103,6 +105,30 @@ Note that in the TCP CR :
103105

104106
Except the frontend keyword `default_backend`, all other lines are not automatically generated but are in a flexible way handled by the `frontend` section in the TCP CR.
105107

108+
## ingress.class
109+
110+
Starting `3.1`, the TCP Custom Resource managed by the Ingress Controller can be filtered using the `ingress.class` annotation.
111+
It behaves the same way as `Ingress`:
112+
113+
| ingress.class controller flag | TCP CR ingress.class annotation | Behavior |
114+
|------------------|---------------------|-----------------|
115+
| '' (not set) | * (any value) | TCP CR managed by IC |
116+
| \<igclass\> | Same value as controller | TCP CR managed by IC |
117+
| \<igclass\> | Value different from controller | TCP CR not managed by IC, frontend and backend deleted if existing |
118+
| \<igclass\> | '' (empty, not set)| if controller `empty-ingress-class` flag is set, TCP CR managed by IC, otherwise ignored (and frontend and backend are deleted)|
119+
120+
121+
### Migration 3.0 to 3.1: action required regarding ingress.class annotation
122+
123+
If some TCP CRs were deployed with Ingress Controller version <= v3.0, and the Ingress Controller has a `ingress.class` flag for the controller, the TCP CRs need to have the same value for the `ingress.class` annotation in the TCP CR.
124+
125+
If the annotation is not set, the corresponding backends and frontends in the haproxy configuration would be deleted:
126+
- except if the controller `empty-ingress-class` flag is set (same behavior as for `Ingress`).
127+
128+
The setting of the `ingress.class` to the TCP CRs should be done **prior to the upgrade to** `v3.1`. It will not be used in v3.0 but needs to be there starting v3.1.
129+
130+
131+
106132
## Pod and Service definitions
107133

108134
with the following Kubernetes Service and Pod manifests:
@@ -258,6 +284,8 @@ kind: TCP
258284
metadata:
259285
name: tcp-2
260286
namespace: test
287+
annotations:
288+
ingress.class: haproxy
261289
spec:
262290
- name: tcp-http-echo-test2-8443
263291
frontend:
@@ -297,6 +325,8 @@ kind: TCP
297325
metadata:
298326
name: tcp-1
299327
namespace: test
328+
annotations:
329+
ingress.class: haproxy
300330
spec:
301331
- name: tcp-http-echo-443
302332
frontend:

documentation/tcp-cr-full-example/tcp-cr-full.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apiVersion: ingress.v1.haproxy.org/v1
22
kind: TCP
33
metadata:
44
name: tcp-1
5+
annotations:
6+
ingress.class: haproxy
57
spec:
68
- name: tcp-test
79
frontend:

0 commit comments

Comments
 (0)