@@ -62,7 +62,7 @@ func buildListeners(
62
62
}
63
63
64
64
type listenerConfiguratorFactory struct {
65
- http , https , unsupportedProtocol * listenerConfigurator
65
+ http , https , tls , unsupportedProtocol * listenerConfigurator
66
66
}
67
67
68
68
func (f * listenerConfiguratorFactory ) getConfiguratorForListener (l v1.Listener ) * listenerConfigurator {
@@ -71,6 +71,8 @@ func (f *listenerConfiguratorFactory) getConfiguratorForListener(l v1.Listener)
71
71
return f .http
72
72
case v1 .HTTPSProtocolType :
73
73
return f .https
74
+ case v1 .TLSProtocolType :
75
+ return f .tls
74
76
default :
75
77
return f .unsupportedProtocol
76
78
}
@@ -122,6 +124,15 @@ func newListenerConfiguratorFactory(
122
124
createExternalReferencesForTLSSecretsResolver (gw .Namespace , secretResolver , refGrantResolver ),
123
125
},
124
126
},
127
+ tls : & listenerConfigurator {
128
+ validators : []listenerValidator {
129
+ validateListenerAllowedRouteKind ,
130
+ validateListenerLabelSelector ,
131
+ validateListenerHostname ,
132
+ },
133
+ conflictResolvers : []listenerConflictResolver {},
134
+ externalReferenceResolvers : []listenerExternalReferenceResolver {},
135
+ },
125
136
}
126
137
}
127
138
@@ -185,6 +196,7 @@ func (c *listenerConfigurator) configure(listener v1.Listener) *Listener {
185
196
Conditions : conds ,
186
197
AllowedRouteLabelSelector : allowedRouteSelector ,
187
198
Routes : make (map [RouteKey ]* L7Route ),
199
+ L4Routes : make (map [L4RouteKey ]* L4Route ),
188
200
Valid : valid ,
189
201
Attachable : attachable ,
190
202
SupportedKinds : supportedKinds ,
@@ -196,7 +208,8 @@ func (c *listenerConfigurator) configure(listener v1.Listener) *Listener {
196
208
197
209
// resolvers might add different conditions to the listener, so we run them all.
198
210
199
- for _ , resolver := range c .conflictResolvers {
211
+ for _ , resolver := range c .
212
+ conflictResolvers {
200
213
resolver (l )
201
214
}
202
215
@@ -231,37 +244,74 @@ func getAndValidateListenerSupportedKinds(listener v1.Listener) (
231
244
[]v1.RouteGroupKind ,
232
245
) {
233
246
if listener .AllowedRoutes == nil || listener .AllowedRoutes .Kinds == nil {
234
- return nil , []v1.RouteGroupKind {
235
- {
236
- Kind : kinds .HTTPRoute ,
237
- },
247
+ switch listener .Protocol {
248
+ case v1 .HTTPProtocolType , v1 .HTTPSProtocolType :
249
+ return nil , []v1.RouteGroupKind {
250
+ {
251
+ Kind : kinds .HTTPRoute ,
252
+ },
253
+ {
254
+ Kind : kinds .GRPCRoute ,
255
+ },
256
+ }
257
+ case v1 .TLSProtocolType :
258
+ return nil , []v1.RouteGroupKind {
259
+ {
260
+ Kind : kinds .TLSRoute ,
261
+ },
262
+ }
263
+ default :
264
+ return nil , []v1.RouteGroupKind {
265
+ {
266
+ Kind : kinds .HTTPRoute ,
267
+ },
268
+ {
269
+ Kind : kinds .GRPCRoute ,
270
+ },
271
+ }
238
272
}
239
273
}
240
274
var conds []conditions.Condition
241
275
242
276
supportedKinds := make ([]v1.RouteGroupKind , 0 , len (listener .AllowedRoutes .Kinds ))
243
277
244
- validHTTPProtocolRouteKind := func (kind v1.RouteGroupKind ) bool {
245
- if kind .Kind != v1 .Kind (kinds .HTTPRoute ) && kind .Kind != v1 .Kind (kinds .GRPCRoute ) {
278
+ validProtocolRouteKind := func (kind v1.RouteGroupKind , validKinds []v1.Kind ) bool {
279
+ matchedKind := false
280
+ for _ , k := range validKinds {
281
+ if k == kind .Kind {
282
+ matchedKind = true
283
+ break
284
+ }
285
+ }
286
+ if ! matchedKind {
246
287
return false
247
288
}
248
- if kind .Group == nil || * kind .Group != v1 .GroupName {
289
+ if kind .Group != nil && * kind .Group != v1 .GroupName {
249
290
return false
250
291
}
251
292
return true
252
293
}
253
294
254
- switch listener .Protocol {
255
- case v1 .HTTPProtocolType , v1 .HTTPSProtocolType :
295
+ validateProtocolRouteKinds := func (validKinds []v1.Kind ) {
256
296
for _ , kind := range listener .AllowedRoutes .Kinds {
257
- if ! validHTTPProtocolRouteKind (kind ) {
297
+ if ! validProtocolRouteKind (kind , validKinds ) {
258
298
msg := fmt .Sprintf ("Unsupported route kind \" %s/%s\" " , * kind .Group , kind .Kind )
259
299
conds = append (conds , staticConds .NewListenerInvalidRouteKinds (msg )... )
260
300
continue
261
301
}
262
302
supportedKinds = append (supportedKinds , kind )
263
303
}
264
304
}
305
+
306
+ switch listener .Protocol {
307
+ case v1 .HTTPProtocolType , v1 .HTTPSProtocolType :
308
+ validKinds := []v1.Kind {kinds .GRPCRoute , kinds .HTTPRoute }
309
+ validateProtocolRouteKinds (validKinds )
310
+
311
+ case v1 .TLSProtocolType :
312
+ validKinds := []v1.Kind {kinds .TLSRoute }
313
+ validateProtocolRouteKinds (validKinds )
314
+ }
265
315
return conds , supportedKinds
266
316
}
267
317
0 commit comments