Skip to content

Commit 3043d95

Browse files
committed
Correct h2c conditional check
1 parent 2baaaf5 commit 3043d95

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

internal/controller/state/graph/route_common.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -766,13 +766,13 @@ func bindL7RouteToListeners(
766766
continue
767767
}
768768

769-
for _, rule := range route.Spec.Rules {
770-
for _, backendRef := range rule.BackendRefs {
769+
for ruleIdx, rule := range route.Spec.Rules {
770+
for backendRefIdx, backendRef := range rule.BackendRefs {
771771
if cond, ok := backendRef.InvalidForGateways[gwNsName]; ok {
772772
attachment.FailedConditions = append(attachment.FailedConditions, cond)
773773
}
774774

775-
checkAppProtocolH2CConditional(backendRef, gw.EffectiveNginxProxy, route)
775+
checkAppProtocolH2CConditional(backendRef, gw.EffectiveNginxProxy, route, ruleIdx, backendRefIdx)
776776
}
777777
}
778778

@@ -797,15 +797,21 @@ func bindL7RouteToListeners(
797797
}
798798
}
799799

800-
func checkAppProtocolH2CConditional(backendRef BackendRef, npCfg *EffectiveNginxProxy, route *L7Route) {
800+
func checkAppProtocolH2CConditional(
801+
backendRef BackendRef,
802+
npCfg *EffectiveNginxProxy,
803+
route *L7Route,
804+
ruleIdx,
805+
backendRefIdx int,
806+
) {
801807
// For all backendRefs referring to a Service with appProtocol h2c, we need to also check if http2
802808
// is enabled. Don't need to check for RouteTypeGRPC since there are checks before this which fail the
803809
// route from connecting to the Gateway.
804810
if backendRef.ServicePort.AppProtocol != nil &&
805811
*backendRef.ServicePort.AppProtocol == AppProtocolTypeH2C &&
806812
route.RouteType == RouteTypeHTTP &&
807813
isHTTP2Disabled(npCfg) {
808-
backendRef.Valid = false
814+
route.Spec.Rules[ruleIdx].BackendRefs[backendRefIdx].Valid = false
809815
route.Conditions = append(route.Conditions, conditions.NewRouteBackendRefUnsupportedProtocol(
810816
fmt.Errorf("HTTP2 is disabled - cannot support appProtocol h2c on route type %s",
811817
route.RouteType,

internal/controller/state/graph/route_common_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ func TestBindRouteToListeners(t *testing.T) {
403403
{
404404
BackendRefs: []BackendRef{
405405
{
406+
Valid: true,
406407
ServicePort: v1.ServicePort{
407408
AppProtocol: helpers.GetPointer(AppProtocolTypeH2C),
408409
},
@@ -422,6 +423,9 @@ func TestBindRouteToListeners(t *testing.T) {
422423
},
423424
}
424425

426+
invalidBackendRefH2c := *normalHTTPRouteWithH2CBackendRef
427+
invalidBackendRefH2c.Spec.Rules[0].BackendRefs[0].Valid = false
428+
425429
getLastNormalHTTPRoute := func() *L7Route {
426430
return normalHTTPRoute
427431
}
@@ -599,8 +603,9 @@ func TestBindRouteToListeners(t *testing.T) {
599603
tests := []struct {
600604
route *L7Route
601605
gateway *Gateway
602-
expectedGatewayListeners []*Listener
606+
expectedModifiedRoute *L7Route
603607
name string
608+
expectedGatewayListeners []*Listener
604609
expectedSectionNameRefs []ParentRef
605610
expectedConditions []conditions.Condition
606611
}{
@@ -719,7 +724,8 @@ func TestBindRouteToListeners(t *testing.T) {
719724
conditions.NewRouteBackendRefUnsupportedProtocol(
720725
"HTTP2 is disabled - cannot support appProtocol h2c on route type http"),
721726
},
722-
name: "httpRoute with h2c service port protocol in backend and h2c is disabled",
727+
expectedModifiedRoute: &invalidBackendRefH2c,
728+
name: "httpRoute with h2c service port protocol in backend and h2c is disabled",
723729
},
724730
{
725731
route: routeWithMissingSectionName,
@@ -1509,6 +1515,12 @@ func TestBindRouteToListeners(t *testing.T) {
15091515
g.Expect(test.route.ParentRefs).To(Equal(test.expectedSectionNameRefs))
15101516
g.Expect(helpers.Diff(test.gateway.Listeners, test.expectedGatewayListeners)).To(BeEmpty())
15111517
g.Expect(helpers.Diff(test.route.Conditions, test.expectedConditions)).To(BeEmpty())
1518+
1519+
// in situations where bindRouteToListeners modifies the route spec, for instance marking a backendRef
1520+
// as invalid
1521+
if test.expectedModifiedRoute != nil {
1522+
g.Expect(helpers.Diff(test.route.Spec, test.expectedModifiedRoute.Spec)).To(BeEmpty())
1523+
}
15121524
})
15131525
}
15141526
}

tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ GW_SERVICE_TYPE = NodePort## Service type to use for the gateway
1212
NGF_VERSION ?= edge## NGF version to be tested
1313
PULL_POLICY = Never## Pull policy for the images
1414
NGINX_CONF_DIR = internal/controller/nginx/conf
15-
SUPPORTED_EXTENDED_FEATURES = HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect,HTTPRouteHostRewrite,HTTPRoutePathRewrite,GatewayPort8080,HTTPRouteResponseHeaderModification,HTTPRoutePathRedirect,GatewayHTTPListenerIsolation,GatewayInfrastructurePropagation,HTTPRouteRequestMirror,HTTPRouteRequestMultipleMirrors,HTTPRouteBackendProtocolWebSocket,HTTPRouteBackendProtocolH2C
15+
SUPPORTED_EXTENDED_FEATURES = HTTPRouteQueryParamMatching,HTTPRouteMethodMatching,HTTPRoutePortRedirect,HTTPRouteSchemeRedirect,HTTPRouteHostRewrite,HTTPRoutePathRewrite,GatewayPort8080,HTTPRouteResponseHeaderModification,HTTPRoutePathRedirect,GatewayHTTPListenerIsolation,GatewayInfrastructurePropagation,HTTPRouteRequestMirror,HTTPRouteRequestMultipleMirrors,HTTPRouteBackendProtocolWebSocket
1616
STANDARD_CONFORMANCE_PROFILES = GATEWAY-HTTP,GATEWAY-GRPC
1717
EXPERIMENTAL_CONFORMANCE_PROFILES = GATEWAY-TLS
1818
CONFORMANCE_PROFILES = $(STANDARD_CONFORMANCE_PROFILES) # by default we use the standard conformance profiles. If experimental is enabled we override this and add the experimental profiles.

0 commit comments

Comments
 (0)