Skip to content

Commit 9b9000f

Browse files
feat(common): add Gateway API Gateway resource with automatic route linking (#45010)
Adds support for creating Kubernetes Gateway API Gateway objects from values.yaml, with optional name-based dynamic linking between routes and gateways via `targetSelector`. ## Gateway Resource Support - Full Gateway API v1 object creation with gatewayClassName, listeners, TLS, and allowedRoutes - Multi-protocol listeners (HTTP, HTTPS, TCP, TLS, UDP) with per-listener hostname filtering - TLS termination/passthrough with certificate references ## Dynamic Route Linking - Routes can use `targetSelector` to automatically generate `parentRefs` pointing to a named gateway - Manual `parentRefs` still supported when `targetSelector` is omitted - Backward compatible with existing route configurations ## Example Usage ```yaml gateway: main: enabled: true gatewayClassName: traefik listeners: - name: https hostname: "*.example.com" port: 443 protocol: HTTPS tls: mode: Terminate certificateRefs: - kind: Secret name: tls-cert route: main: enabled: true targetSelector: main # Auto-links to gateway.main hostnames: - app.example.com ``` ## Implementation - Gateway class template (`templates/class/_gateway.tpl`) - Gateway spawner (`templates/spawner/_gateway.tpl`) - Route template updated for `targetSelector` parentRef generation - Primary gateway helper for selection logic - Fixed route primary helper to handle missing values - JSON schemas and documentation for both resources Version bumped to 29.1.0. <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/trueforge-org/truecharts/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: PrivatePuffin <7613738+PrivatePuffin@users.noreply.github.com>
1 parent db7baee commit 9b9000f

File tree

15 files changed

+899
-4
lines changed

15 files changed

+899
-4
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
workload:
2+
main:
3+
enabled: true
4+
podSpec:
5+
containers:
6+
main:
7+
enabled: true
8+
args:
9+
- --port
10+
- "8080"
11+
probes:
12+
liveness:
13+
enabled: true
14+
readiness:
15+
enabled: true
16+
startup:
17+
enabled: true
18+
19+
service:
20+
main:
21+
enabled: true
22+
ports:
23+
main:
24+
enabled: true
25+
port: 8080
26+
protocol: http
27+
28+
gateway:
29+
main:
30+
enabled: true
31+
gatewayClassName: test-gateway-class
32+
listeners:
33+
- name: http
34+
port: 80
35+
protocol: HTTP
36+
allowedRoutes:
37+
namespaces:
38+
from: Same
39+
kinds:
40+
- group: gateway.networking.k8s.io
41+
kind: HTTPRoute
42+
43+
route:
44+
main:
45+
enabled: true
46+
targetSelector: main
47+
hostnames:
48+
- chart-example.local
49+
rules:
50+
- backendRefs:
51+
- kind: Service
52+
name: main
53+
port: 8080
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
suite: gateway basic test
2+
templates:
3+
- common.yaml
4+
release:
5+
name: test-release-name
6+
namespace: test-release-namespace
7+
tests:
8+
- it: should create a gateway when enabled
9+
set:
10+
gateway:
11+
main:
12+
enabled: true
13+
gatewayClassName: test-gateway-class
14+
listeners:
15+
- name: http
16+
port: 80
17+
protocol: HTTP
18+
asserts:
19+
- documentIndex: &gatewayDoc 0
20+
isKind:
21+
of: Gateway
22+
- documentIndex: *gatewayDoc
23+
isAPIVersion:
24+
of: gateway.networking.k8s.io/v1
25+
- documentIndex: *gatewayDoc
26+
equal:
27+
path: metadata.name
28+
value: test-release-name-common-test
29+
- documentIndex: *gatewayDoc
30+
equal:
31+
path: spec.gatewayClassName
32+
value: test-gateway-class
33+
- documentIndex: *gatewayDoc
34+
equal:
35+
path: spec.listeners[0].name
36+
value: http
37+
- documentIndex: *gatewayDoc
38+
equal:
39+
path: spec.listeners[0].port
40+
value: 80
41+
- documentIndex: *gatewayDoc
42+
equal:
43+
path: spec.listeners[0].protocol
44+
value: HTTP
45+
46+
- it: should not create a gateway when disabled
47+
set:
48+
gateway:
49+
main:
50+
enabled: false
51+
gatewayClassName: test-gateway-class
52+
listeners:
53+
- name: http
54+
port: 80
55+
protocol: HTTP
56+
asserts:
57+
- hasDocuments:
58+
count: 0
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
suite: gateway and route integration test
2+
templates:
3+
- common.yaml
4+
release:
5+
name: test-release-name
6+
namespace: test-release-namespace
7+
tests:
8+
- it: should link route to gateway via targetSelector
9+
set:
10+
gateway:
11+
main:
12+
enabled: true
13+
gatewayClassName: test-gateway-class
14+
listeners:
15+
- name: http
16+
port: 80
17+
protocol: HTTP
18+
service:
19+
main:
20+
enabled: true
21+
ports:
22+
main:
23+
enabled: true
24+
port: 8080
25+
route:
26+
main:
27+
enabled: true
28+
targetSelector: main
29+
hostnames:
30+
- chart-example.local
31+
rules:
32+
- backendRefs:
33+
- kind: Service
34+
name: main
35+
port: 8080
36+
asserts:
37+
- documentIndex: &gatewayDoc 0
38+
isKind:
39+
of: Gateway
40+
- documentIndex: *gatewayDoc
41+
equal:
42+
path: metadata.name
43+
value: test-release-name-common-test
44+
- documentIndex: &routeDoc 2
45+
isKind:
46+
of: HTTPRoute
47+
- documentIndex: *routeDoc
48+
equal:
49+
path: spec.parentRefs[0].kind
50+
value: Gateway
51+
- documentIndex: *routeDoc
52+
equal:
53+
path: spec.parentRefs[0].name
54+
value: test-release-name-common-test
55+
- documentIndex: *routeDoc
56+
equal:
57+
path: spec.parentRefs[0].namespace
58+
value: test-release-namespace
59+
60+
- it: should use manual parentRefs when targetSelector is not set
61+
set:
62+
service:
63+
main:
64+
enabled: true
65+
ports:
66+
main:
67+
enabled: true
68+
port: 8080
69+
route:
70+
main:
71+
enabled: true
72+
parentRefs:
73+
- group: gateway.networking.k8s.io
74+
kind: Gateway
75+
name: external-gateway
76+
namespace: external-namespace
77+
hostnames:
78+
- chart-example.local
79+
rules:
80+
- backendRefs:
81+
- kind: Service
82+
name: main
83+
port: 8080
84+
asserts:
85+
- documentIndex: &routeDoc 1
86+
isKind:
87+
of: HTTPRoute
88+
- documentIndex: *routeDoc
89+
equal:
90+
path: spec.parentRefs[0].kind
91+
value: Gateway
92+
- documentIndex: *routeDoc
93+
equal:
94+
path: spec.parentRefs[0].name
95+
value: external-gateway
96+
- documentIndex: *routeDoc
97+
equal:
98+
path: spec.parentRefs[0].namespace
99+
value: external-namespace

charts/library/common/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ sources:
5050
- https://github.com/trueforge-org/truecharts/tree/master/charts/library/common
5151
- https://hub.docker.com/_/
5252
type: library
53-
version: 29.0.2
53+
version: 29.1.0

0 commit comments

Comments
 (0)