Skip to content

Commit 6d49ccb

Browse files
feat(common): add GatewayClass support with targetSelector linking (#45012)
Adds support for Kubernetes Gateway API GatewayClass resources, enabling declaration of gateway controller classes that can be referenced by Gateway objects. ## Implementation - **GatewayClass resource**: New template class, spawner, and helper functions for creating GatewayClass objects with full spec support (controllerName, description, parametersRef) - **Automatic linking**: Gateway objects support `targetSelector` field to reference GatewayClass by name, generating the full resource name automatically - **Backward compatibility**: Direct `gatewayClassName` configuration remains functional - **Helper extraction**: Shared full-name generation logic extracted to `tc.v1.common.lib.util.gatewayclass.getFullName` ## Configuration ```yaml gatewayClass: main: enabled: true controllerName: traefik.io/gateway-controller description: "Traefik-based gateway class" gateway: main: enabled: true targetSelector: main # References gatewayClass.main listeners: - name: http port: 80 protocol: HTTP ``` ## Files - Templates: `class/_gatewayclass.tpl`, `spawner/_gatewayclass.tpl`, `lib/util/_primary_gatewayclass.tpl` - Configuration: `values.yaml`, `schemas/gatewayclass.json`, `docs/gatewayclass.md` - Tests: `common-test/ci/gatewayclass-values.yaml` - Updated: `loader/_apply.tpl`, `class/_gateway.tpl`, structure files - Version: 29.1.0 → 29.2.0 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --------- 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 9b9000f commit 6d49ccb

File tree

14 files changed

+564
-2
lines changed

14 files changed

+564
-2
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
gatewayClass:
29+
main:
30+
enabled: true
31+
controllerName: test.io/gateway-controller
32+
description: Test gateway class
33+
34+
gateway:
35+
main:
36+
enabled: true
37+
targetSelector: main
38+
listeners:
39+
- name: http
40+
port: 80
41+
protocol: HTTP
42+
allowedRoutes:
43+
namespaces:
44+
from: Same
45+
kinds:
46+
- group: gateway.networking.k8s.io
47+
kind: HTTPRoute
48+
49+
route:
50+
main:
51+
enabled: true
52+
targetSelector: main
53+
hostnames:
54+
- chart-example.local
55+
rules:
56+
- backendRefs:
57+
- kind: Service
58+
name: main
59+
port: 8080

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.1.0
53+
version: 29.2.0

charts/library/common/complete-values-structure.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,11 @@ configMapsFromFolder:
29472947
test-label: ''
29482948
annotations:
29492949
test-annotation: ''
2950+
fileAttributeOverrides:
2951+
template.tpl:
2952+
escaped: true
2953+
.gitkeep:
2954+
exclude: true
29502955
test-scripts:
29512956
labels:
29522957
test-label: ''
@@ -3196,6 +3201,31 @@ ingress:
31963201
customkv: null
31973202
version: 2
31983203
certificate: {}
3204+
gatewayClass:
3205+
main:
3206+
enabled: false
3207+
annotations: {}
3208+
labels: {}
3209+
controllerName: ''
3210+
description: ''
3211+
gateway:
3212+
main:
3213+
enabled: false
3214+
annotations: {}
3215+
labels: {}
3216+
gatewayClassName: ''
3217+
listeners:
3218+
- name: ''
3219+
hostname: null
3220+
port: 80
3221+
protocol: ''
3222+
allowedRoutes:
3223+
namespaces:
3224+
from: ''
3225+
kinds:
3226+
- group: ''
3227+
kind: ''
3228+
targetSelector: ''
31993229
route:
32003230
objectname:
32013231
enabled: false
@@ -3222,6 +3252,7 @@ route:
32223252
- path:
32233253
type: ''
32243254
value: ''
3255+
targetSelector: ''
32253256
podDisruptionBudget:
32263257
main:
32273258
enabled: false

charts/library/common/docs/gateway.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ gateway:
8787

8888
---
8989

90+
### `gateway.$name.targetSelector`
91+
92+
Configuration for `gateway.main.targetSelector`. Name-based selector for automatic GatewayClass linking. When set, automatically references the specified `gatewayClass.$name`.
93+
94+
| Field | Value |
95+
| ---------- | ------------------------------- |
96+
| Key | `gateway.$name.targetSelector` |
97+
| Type | `string` |
98+
| Required | ❌ |
99+
| Helm `tpl` | ❌ |
100+
| Default | unset |
101+
102+
Example
103+
104+
```yaml
105+
gateway:
106+
$name:
107+
targetSelector: main # Links to gatewayClass.main
108+
```
109+
110+
---
111+
90112
### `gateway.$name.labels`
91113

92114
Configuration for `gateway.main.labels`.
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
---
2+
title: GatewayClass
3+
---
4+
5+
:::note
6+
7+
- This page is generated from JSON schema.
8+
- See the [Full Examples](/truecharts-common/gatewayclass#full-examples) section for complete examples.
9+
10+
:::
11+
12+
## Appears in
13+
14+
- `.Values.gatewayClass`
15+
16+
---
17+
18+
## `gatewayClass`
19+
20+
Configuration for `gatewayClass`.
21+
22+
| Field | Value |
23+
| ---------- | -------------- |
24+
| Key | `gatewayClass` |
25+
| Type | `map` |
26+
| Required ||
27+
| Helm `tpl` ||
28+
| Default | unset |
29+
30+
---
31+
32+
### `gatewayClass.$name.annotations`
33+
34+
Configuration for `gatewayClass.main.annotations`.
35+
36+
| Field | Value |
37+
| ---------- | ---------------------------------- |
38+
| Key | `gatewayClass.$name.annotations` |
39+
| Type | `map` |
40+
| Required ||
41+
| Helm `tpl` ||
42+
| Default | unset |
43+
44+
---
45+
46+
### `gatewayClass.$name.enabled`
47+
48+
Configuration for `gatewayClass.main.enabled`.
49+
50+
| Field | Value |
51+
| ---------- | ------------------------------ |
52+
| Key | `gatewayClass.$name.enabled` |
53+
| Type | `boolean, string` |
54+
| Required ||
55+
| Helm `tpl` ||
56+
| Default | `false` |
57+
58+
Example
59+
60+
```yaml
61+
gatewayClass:
62+
$name:
63+
enabled: false
64+
```
65+
66+
---
67+
68+
### `gatewayClass.$name.labels`
69+
70+
Configuration for `gatewayClass.main.labels`.
71+
72+
| Field | Value |
73+
| ---------- | ------------------------------- |
74+
| Key | `gatewayClass.$name.labels` |
75+
| Type | `map` |
76+
| Required | ❌ |
77+
| Helm `tpl` | ❌ |
78+
| Default | unset |
79+
80+
---
81+
82+
### `gatewayClass.$name.controllerName`
83+
84+
Configuration for `gatewayClass.main.controllerName`. The name of the controller that will manage Gateways of this class.
85+
86+
| Field | Value |
87+
| ---------- | -------------------------------------- |
88+
| Key | `gatewayClass.$name.controllerName` |
89+
| Type | `string` |
90+
| Required | ✅ (when gatewayClass is enabled) |
91+
| Helm `tpl` | ❌ |
92+
| Default | unset |
93+
94+
Example
95+
96+
```yaml
97+
gatewayClass:
98+
$name:
99+
controllerName: traefik.io/gateway-controller
100+
```
101+
102+
---
103+
104+
### `gatewayClass.$name.description`
105+
106+
Configuration for `gatewayClass.main.description`. Description helps describe a GatewayClass with more details.
107+
108+
| Field | Value |
109+
| ---------- | ----------------------------------- |
110+
| Key | `gatewayClass.$name.description` |
111+
| Type | `string` |
112+
| Required | ❌ |
113+
| Helm `tpl` | ❌ |
114+
| Default | unset |
115+
116+
Example
117+
118+
```yaml
119+
gatewayClass:
120+
$name:
121+
description: "Traefik-based gateway class"
122+
```
123+
124+
---
125+
126+
### `gatewayClass.$name.parametersRef`
127+
128+
Configuration for `gatewayClass.main.parametersRef`. ParametersRef is a reference to a resource that contains the configuration parameters corresponding to the GatewayClass.
129+
130+
| Field | Value |
131+
| ---------- | ------------------------------------ |
132+
| Key | `gatewayClass.$name.parametersRef` |
133+
| Type | `map` |
134+
| Required | ❌ |
135+
| Helm `tpl` | ❌ |
136+
| Default | unset |
137+
138+
Fields for parametersRef:
139+
- `group`: API group of the referenced resource (required)
140+
- `kind`: Kind of the referenced resource (required)
141+
- `name`: Name of the referenced resource (required)
142+
- `namespace`: Optional namespace of the referenced resource
143+
144+
---
145+
146+
## Full Examples
147+
148+
### Basic GatewayClass
149+
150+
```yaml
151+
gatewayClass:
152+
main:
153+
enabled: true
154+
controllerName: traefik.io/gateway-controller
155+
```
156+
157+
### GatewayClass with Description
158+
159+
```yaml
160+
gatewayClass:
161+
main:
162+
enabled: true
163+
controllerName: traefik.io/gateway-controller
164+
description: "Traefik-based gateway class for HTTP/HTTPS traffic"
165+
```
166+
167+
### GatewayClass with ParametersRef
168+
169+
```yaml
170+
gatewayClass:
171+
main:
172+
enabled: true
173+
controllerName: traefik.io/gateway-controller
174+
parametersRef:
175+
group: traefik.io
176+
kind: GatewayClassConfig
177+
name: traefik-config
178+
namespace: traefik-system
179+
```
180+
181+
### Using GatewayClass with Gateway via targetSelector
182+
183+
```yaml
184+
gatewayClass:
185+
main:
186+
enabled: true
187+
controllerName: traefik.io/gateway-controller
188+
189+
gateway:
190+
main:
191+
enabled: true
192+
targetSelector: main # Automatically links to gatewayClass.main
193+
listeners:
194+
- name: http
195+
port: 80
196+
protocol: HTTP
197+
```
198+
199+
### Multiple GatewayClasses
200+
201+
```yaml
202+
gatewayClass:
203+
traefik:
204+
enabled: true
205+
controllerName: traefik.io/gateway-controller
206+
description: "Traefik gateway class"
207+
208+
nginx:
209+
enabled: true
210+
controllerName: nginx.org/gateway-controller
211+
description: "NGINX gateway class"
212+
213+
gateway:
214+
traefik-gw:
215+
enabled: true
216+
targetSelector: traefik # Links to gatewayClass.traefik
217+
listeners:
218+
- name: http
219+
port: 80
220+
protocol: HTTP
221+
222+
nginx-gw:
223+
enabled: true
224+
targetSelector: nginx # Links to gatewayClass.nginx
225+
listeners:
226+
- name: https
227+
port: 443
228+
protocol: HTTPS
229+
```

charts/library/common/schemas/gateway.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"description": "Configuration for `gateway.main.gatewayClassName`.",
3333
"minLength": 1
3434
},
35+
"targetSelector": {
36+
"type": "string",
37+
"description": "Configuration for `gateway.main.targetSelector`. Name-based selector for automatic GatewayClass linking."
38+
},
3539
"listeners": {
3640
"type": "array",
3741
"items": {

0 commit comments

Comments
 (0)