@@ -17,6 +17,12 @@ import (
17
17
"github.com/nginx/nginx-gateway-fabric/internal/framework/helpers"
18
18
)
19
19
20
+ const (
21
+ AppProtocolTypeH2C string = "kubernetes.io/h2c"
22
+ AppProtocolTypeWS string = "kubernetes.io/ws"
23
+ AppProtocolTypeWSS string = "kubernetes.io/wss"
24
+ )
25
+
20
26
// BackendRef is an internal representation of a backendRef in an HTTP/GRPC/TLSRoute.
21
27
type BackendRef struct {
22
28
// BackendTLSPolicy is the BackendTLSPolicy of the Service which is referenced by the backendRef.
@@ -200,6 +206,33 @@ func createBackendRef(
200
206
return backendRef , append (conds , conditions .NewRouteBackendRefUnsupportedValue (err .Error ()))
201
207
}
202
208
209
+ if svcPort .AppProtocol != nil {
210
+ valid = validateRouteBackendRefAppProtocol (route .RouteType , * svcPort .AppProtocol , backendTLSPolicy )
211
+ if ! valid {
212
+ backendRef := BackendRef {
213
+ SvcNsName : svcNsName ,
214
+ BackendTLSPolicy : backendTLSPolicy ,
215
+ ServicePort : svcPort ,
216
+ Weight : weight ,
217
+ Valid : false ,
218
+ IsMirrorBackend : ref .MirrorBackendIdx != nil ,
219
+ InvalidForGateways : invalidForGateways ,
220
+ }
221
+
222
+ err := fmt .Errorf (
223
+ "route type %s does not support service port appProtocol %s" ,
224
+ route .RouteType ,
225
+ * svcPort .AppProtocol ,
226
+ ).Error ()
227
+
228
+ if route .RouteType == RouteTypeHTTP && * svcPort .AppProtocol == AppProtocolTypeWSS && backendTLSPolicy == nil {
229
+ err += "; missing corresponding BackendTLSPolicy"
230
+ }
231
+
232
+ return backendRef , append (conds , conditions .NewRouteBackendRefUnsupportedProtocol (err ))
233
+ }
234
+ }
235
+
203
236
backendRef := BackendRef {
204
237
SvcNsName : svcNsName ,
205
238
BackendTLSPolicy : backendTLSPolicy ,
@@ -414,6 +447,24 @@ func validateBackendRef(
414
447
return true , conditions.Condition {}
415
448
}
416
449
450
+ func validateRouteBackendRefAppProtocol (
451
+ routeType RouteType ,
452
+ appProtocol string ,
453
+ backendTLSPolicy * BackendTLSPolicy ,
454
+ ) (valid bool ) {
455
+ // Currently we only support recognition of the Kubernetes Standard Application Protocols defined in KEP-3726.
456
+ switch appProtocol {
457
+ case AppProtocolTypeH2C :
458
+ return routeType == RouteTypeHTTP || routeType == RouteTypeGRPC
459
+ case AppProtocolTypeWS :
460
+ return routeType == RouteTypeHTTP
461
+ case AppProtocolTypeWSS :
462
+ return (routeType == RouteTypeHTTP && backendTLSPolicy != nil ) || routeType == RouteTypeTLS
463
+ }
464
+
465
+ return true
466
+ }
467
+
417
468
func validateWeight (weight int32 ) error {
418
469
const (
419
470
minWeight = 0
0 commit comments