@@ -207,8 +207,8 @@ func createBackendRef(
207
207
}
208
208
209
209
if svcPort .AppProtocol != nil {
210
- valid = validateRouteBackendRefAppProtocol (route .RouteType , * svcPort .AppProtocol , backendTLSPolicy )
211
- if ! valid {
210
+ err = validateRouteBackendRefAppProtocol (route .RouteType , * svcPort .AppProtocol , backendTLSPolicy )
211
+ if err != nil {
212
212
backendRef := BackendRef {
213
213
SvcNsName : svcNsName ,
214
214
BackendTLSPolicy : backendTLSPolicy ,
@@ -219,17 +219,7 @@ func createBackendRef(
219
219
InvalidForGateways : invalidForGateways ,
220
220
}
221
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 ))
222
+ return backendRef , append (conds , conditions .NewRouteBackendRefUnsupportedProtocol (err .Error ()))
233
223
}
234
224
}
235
225
@@ -447,22 +437,50 @@ func validateBackendRef(
447
437
return true , conditions.Condition {}
448
438
}
449
439
440
+ // validateRouteBackendRefAppProtocol checks if a given RouteType supports sending traffic to a service AppProtocol.
441
+ // Returns nil if true or AppProtocol is not a Kubernetes Standard Application Protocol.
450
442
func validateRouteBackendRefAppProtocol (
451
443
routeType RouteType ,
452
444
appProtocol string ,
453
445
backendTLSPolicy * BackendTLSPolicy ,
454
- ) (valid bool ) {
446
+ ) error {
447
+ err := fmt .Errorf (
448
+ "route type %s does not support service port appProtocol %s" ,
449
+ routeType ,
450
+ appProtocol ,
451
+ )
452
+
455
453
// Currently we only support recognition of the Kubernetes Standard Application Protocols defined in KEP-3726.
456
454
switch appProtocol {
457
455
case AppProtocolTypeH2C :
458
- return routeType == RouteTypeHTTP || routeType == RouteTypeGRPC
456
+ if routeType == RouteTypeHTTP || routeType == RouteTypeGRPC {
457
+ return nil
458
+ }
459
+
460
+ return err
459
461
case AppProtocolTypeWS :
460
- return routeType == RouteTypeHTTP
462
+ if routeType == RouteTypeHTTP {
463
+ return nil
464
+ }
465
+
466
+ return err
461
467
case AppProtocolTypeWSS :
462
- return (routeType == RouteTypeHTTP && backendTLSPolicy != nil ) || routeType == RouteTypeTLS
468
+ if routeType == RouteTypeHTTP {
469
+ if backendTLSPolicy != nil {
470
+ return nil
471
+ }
472
+
473
+ return fmt .Errorf ("%w; missing corresponding BackendTLSPolicy" , err )
474
+ }
475
+
476
+ if routeType == RouteTypeTLS {
477
+ return nil
478
+ }
479
+
480
+ return err
463
481
}
464
482
465
- return true
483
+ return nil
466
484
}
467
485
468
486
func validateWeight (weight int32 ) error {
0 commit comments