Skip to content

Commit e1d6416

Browse files
author
joehu
committed
Add dynamic namespace selection by label
Introduce --namespace-label-selector with dynamic per-namespace watch sessions. Namespace label changes update the watched resource set without restarting the controller, while whitelist and blacklist configurations retain precedence. Add stale-session protection, lifecycle handling, documentation, and unit and end-to-end coverage for Kubernetes and Gateway API resources. Refs #853.
1 parent e064fe1 commit e1d6416

65 files changed

Lines changed: 5902 additions & 288 deletions

Some content is hidden

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

.github/workflows/actions.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,3 +198,37 @@ jobs:
198198
run: go test ./... -v --tags=e2e_parallel --tags=e2e_https
199199
- name: Run sequential e2e tests
200200
run: go test ./... -v -p 1 --tags=e2e_sequential
201+
e2e-gateway:
202+
strategy:
203+
matrix:
204+
k8s-version: ["v1.34.0"]
205+
needs: ["build"]
206+
runs-on: ubuntu-latest
207+
steps:
208+
- name: Check out code
209+
uses: actions/checkout@v4
210+
with:
211+
persist-credentials: false
212+
- name: Set up Go
213+
uses: actions/setup-go@v5
214+
with:
215+
go-version-file: "go.mod"
216+
check-latest: true
217+
- uses: actions/cache@v4
218+
with:
219+
path: |
220+
~/.cache/go-build
221+
~/go/pkg/mod
222+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
223+
restore-keys: |
224+
${{ runner.os }}-go-
225+
- uses: helm/kind-action@v1
226+
with:
227+
cluster_name: dev
228+
config: deploy/tests/kind-config.yaml
229+
node_image: kindest/node:${{ matrix.k8s-version }}
230+
version: v0.33.0
231+
- name: Setup with Gateway API
232+
run: CI_ENV=github EXPERIMENTAL_GWAPI=1 GWAPI_SAMPLE=0 deploy/tests/create.sh
233+
- name: Run namespace-selector Gateway e2e
234+
run: go test ./deploy/tests/e2e/namespace-selector/ -v -p 1 --tags=e2e_sequential -run 'TestNamespaceSelectorSuite/Test_GatewayAllowedRoutesFollowNamespaceLabel'

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ example-dev: build-dev
5353

5454
.PHONY: example-experimental-gwapi
5555
example-experimental-gwapi:
56-
EXPERIMENTAL_GWAPI=1 deploy/tests/create.sh
56+
EXPERIMENTAL_GWAPI=1 GWAPI_SAMPLE=1 deploy/tests/create.sh
5757

5858
.PHONY: example-rebuild
5959
example-rebuild:

cmd/docs/readme.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var headerREADME = `
3232
### Documentation
3333
3434
- [Controller options](controller.md)
35+
- [Namespace selection](namespace-selection.md)
3536
- [Custom resource definitions](custom-resources.md)
3637
- [Annotations](annotations.md)
3738
- [Prometheus](prometheus.md)

deploy/tests/create.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,14 @@ if [ "$EXPERIMENTAL_GWAPI" = "1" ]; then
8181
####################################################
8282
kubectl wait --for=condition=ready --timeout=5m pod -l name=gateway-api-admission-server -n gateway-system
8383
printf %80s |tr " " "="; echo ""
84-
kubectl apply -f $DIR/../../deploy/tests/config/experimental/gwapi-resources.yaml
85-
kubectl apply -f $DIR/../../deploy/tests/config/experimental/gwapi-echo-app.yaml
84+
# Demo Gateway/TCPRoute in default are not required to enable Gateway API.
85+
# They race the echo Service (applied later) and can leave a frontend with a
86+
# missing default_backend, so the first HAProxy commit fails and the IC never
87+
# becomes Ready. Set GWAPI_SAMPLE=1 to install them (make example-experimental-gwapi).
88+
if [ "$GWAPI_SAMPLE" = "1" ]; then
89+
kubectl apply -f $DIR/../../deploy/tests/config/experimental/gwapi-resources.yaml
90+
kubectl apply -f $DIR/../../deploy/tests/config/experimental/gwapi-echo-app.yaml
91+
fi
8692
fi
8793

8894
printf %80s |tr " " "="; echo ""
@@ -119,4 +125,10 @@ while [ $COUNTER -lt 150 ]; do
119125
fi
120126
done
121127

122-
time kubectl wait --for=condition=ready --timeout=10m pod -l run=haproxy-ingress -n haproxy-controller
128+
if ! time kubectl wait --for=condition=ready --timeout=10m pod -l run=haproxy-ingress -n haproxy-controller; then
129+
echo "ingress controller not ready"
130+
kubectl get pods -A
131+
kubectl describe pod -l run=haproxy-ingress -n haproxy-controller
132+
kubectl logs -l run=haproxy-ingress -n haproxy-controller --tail=200
133+
exit 1
134+
fi
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
kind: Deployment
2+
apiVersion: apps/v1
3+
metadata:
4+
name: http-echo
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: http-echo
10+
template:
11+
metadata:
12+
labels:
13+
app: http-echo
14+
spec:
15+
containers:
16+
- name: http-echo
17+
image: haproxytech/http-echo:latest
18+
imagePullPolicy: IfNotPresent
19+
ports:
20+
- name: http
21+
containerPort: 8888
22+
protocol: TCP
23+
---
24+
kind: Service
25+
apiVersion: v1
26+
metadata:
27+
name: http-echo
28+
spec:
29+
ports:
30+
- name: http
31+
protocol: TCP
32+
port: 80
33+
targetPort: http
34+
selector:
35+
app: http-echo
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
apiVersion: gateway.networking.k8s.io/v1alpha2
3+
kind: GatewayClass
4+
metadata:
5+
name: {{ .ClassName }}
6+
spec:
7+
controllerName: haproxy.org/gateway-controller
8+
---
9+
apiVersion: gateway.networking.k8s.io/v1alpha2
10+
kind: Gateway
11+
metadata:
12+
name: {{ .GatewayName }}
13+
spec:
14+
gatewayClassName: {{ .ClassName }}
15+
listeners:
16+
- name: {{ .ListenerName }}
17+
port: {{ .Port }}
18+
protocol: TCP
19+
allowedRoutes:
20+
kinds:
21+
- group: gateway.networking.k8s.io
22+
kind: TCPRoute
23+
namespaces:
24+
from: Selector
25+
selector:
26+
matchLabels:
27+
routes: allowed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
kind: Ingress
3+
apiVersion: networking.k8s.io/v1
4+
metadata:
5+
name: http-echo
6+
spec:
7+
ingressClassName: haproxy
8+
rules:
9+
- host: {{ .Host }}
10+
http:
11+
paths:
12+
- path: /
13+
pathType: Prefix
14+
backend:
15+
service:
16+
name: http-echo
17+
port:
18+
name: http
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: ingress.v1.haproxy.org/v1
2+
kind: TCP
3+
metadata:
4+
name: namespace-selector-late-tcp
5+
annotations:
6+
ingress.class: haproxy
7+
spec:
8+
- name: {{ .Namespace }}-late-http
9+
frontend:
10+
name: {{ .Namespace }}-late-http
11+
binds:
12+
- name: v4
13+
port: {{ .Port }}
14+
service:
15+
name: http-echo
16+
port: 80
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: ingress.v3.haproxy.org/v3
2+
kind: TCP
3+
metadata:
4+
name: namespace-selector-tcp
5+
annotations:
6+
ingress.class: haproxy
7+
spec:
8+
- name: namespace-selector-http
9+
frontend:
10+
name: namespace-selector-http
11+
binds:
12+
v4:
13+
name: v4
14+
port: 32766
15+
service:
16+
name: http-echo
17+
port: 80
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
apiVersion: gateway.networking.k8s.io/v1alpha2
3+
kind: TCPRoute
4+
metadata:
5+
name: {{ .RouteName }}
6+
spec:
7+
parentRefs:
8+
- group: gateway.networking.k8s.io
9+
kind: Gateway
10+
name: {{ .GatewayName }}
11+
rules:
12+
- backendRefs:
13+
- group: ""
14+
kind: Service
15+
name: http-echo
16+
port: 80

0 commit comments

Comments
 (0)