Skip to content

Commit

Permalink
Fix attachedRoutes computation
Browse files Browse the repository at this point in the history
* Fixes: envoyproxy#2077
* Fixes: envoyproxy#1916

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg committed Nov 1, 2023
1 parent 2b3bc9f commit 374569e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 36 deletions.
54 changes: 20 additions & 34 deletions internal/gatewayapi/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,6 @@ func (t *Translator) processHTTPRouteParentRefListener(route RouteContext, route
}
irListener.Routes = append(irListener.Routes, perHostRoutes...)
}
// Theoretically there should only be one parent ref per
// Route that attaches to a given Listener, so fine to just increment here, but we
// might want to check to ensure we're not double-counting.
if len(routeRoutes) > 0 {
listener.IncrementAttachedRoutes()
}
}

return hasHostnameIntersection
Expand Down Expand Up @@ -680,12 +674,6 @@ func (t *Translator) processTLSRouteParentRefs(tlsRoute *TLSRouteContext, resour
gwXdsIR := xdsIR[irKey]
gwXdsIR.TCP = append(gwXdsIR.TCP, irListener)

// Theoretically there should only be one parent ref per
// Route that attaches to a given Listener, so fine to just increment here, but we
// might want to check to ensure we're not double-counting.
if len(irListener.Destination.Settings) > 0 {
listener.IncrementAttachedRoutes()
}
}

if !hasHostnameIntersection {
Expand Down Expand Up @@ -817,12 +805,6 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour
gwXdsIR := xdsIR[irKey]
gwXdsIR.UDP = append(gwXdsIR.UDP, irListener)

// Theoretically there should only be one parent ref per
// Route that attaches to a given Listener, so fine to just increment here, but we
// might want to check to ensure we're not double-counting.
if len(irListener.Destination.Settings) > 0 {
listener.IncrementAttachedRoutes()
}
}

// If no negative conditions have been set, the route is considered "Accepted=True".
Expand Down Expand Up @@ -954,12 +936,6 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour
gwXdsIR := xdsIR[irKey]
gwXdsIR.TCP = append(gwXdsIR.TCP, irListener)

// Theoretically there should only be one parent ref per
// Route that attaches to a given Listener, so fine to just increment here, but we
// might want to check to ensure we're not double-counting.
if len(irListener.Destination.Settings) > 0 {
listener.IncrementAttachedRoutes()
}
}

// If no negative conditions have been set, the route is considered "Accepted=True".
Expand Down Expand Up @@ -1086,16 +1062,6 @@ func (t *Translator) processAllowedListenersForParentRefs(routeContext RouteCont
continue
}

if !HasReadyListener(selectedListeners) {
parentRefCtx.SetCondition(routeContext,
gwapiv1.RouteConditionAccepted,
metav1.ConditionFalse,
"NoReadyListeners",
"There are no ready listeners for this parent ref",
)
continue
}

var allowedListeners []*ListenerContext
for _, listener := range selectedListeners {
acceptedKind := GetRouteType(routeContext)
Expand All @@ -1117,6 +1083,26 @@ func (t *Translator) processAllowedListenersForParentRefs(routeContext RouteCont

parentRefCtx.SetListeners(allowedListeners...)

// Its safe to increment AttachedRoutes since we've found a valid parentRef
// and the listener allows this Route kind

// Theoretically there should only be one parent ref per
// Route that attaches to a given Listener, so fine to just increment here, but we
// might want to check to ensure we're not double-counting.
for _, listener := range allowedListeners {
listener.IncrementAttachedRoutes()
}

if !HasReadyListener(selectedListeners) {
parentRefCtx.SetCondition(routeContext,
gwapiv1.RouteConditionAccepted,
metav1.ConditionFalse,
"NoReadyListeners",
"There are no ready listeners for this parent ref",
)
continue
}

parentRefCtx.SetCondition(routeContext,
gwapiv1.RouteConditionAccepted,
metav1.ConditionTrue,
Expand Down
1 change: 0 additions & 1 deletion test/conformance/conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func TestGatewayAPIConformance(t *testing.T) {
SupportedFeatures: suite.AllFeatures,
SkipTests: []string{
tests.GatewayStaticAddresses.ShortName,
tests.GatewayWithAttachedRoutes.ShortName,
tests.HTTPRouteBackendProtocolH2C.ShortName,
},
ExemptFeatures: suite.MeshCoreFeatures,
Expand Down
1 change: 0 additions & 1 deletion test/conformance/experimental_conformance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func experimentalConformance(t *testing.T) {
SupportedFeatures: suite.AllFeatures,
SkipTests: []string{
tests.GatewayStaticAddresses.ShortName,
tests.GatewayWithAttachedRoutes.ShortName,
tests.HTTPRouteBackendProtocolH2C.ShortName,
},
ExemptFeatures: suite.MeshCoreFeatures,
Expand Down

0 comments on commit 374569e

Please sign in to comment.