Skip to content

Commit

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

Signed-off-by: Arko Dasgupta <arko@tetrate.io>
  • Loading branch information
arkodg committed Oct 27, 2023
1 parent c3ee960 commit d6ddf78
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 @@ -580,12 +580,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 @@ -688,12 +682,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 @@ -825,12 +813,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 @@ -962,12 +944,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 @@ -1094,16 +1070,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 @@ -1125,6 +1091,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 @@ -50,7 +50,6 @@ func TestGatewayAPIConformance(t *testing.T) {
SkipTests: []string{
tests.HTTPRouteRewritePath.ShortName,
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 @@ -99,7 +99,6 @@ func experimentalConformance(t *testing.T) {
SkipTests: []string{
tests.HTTPRouteRewritePath.ShortName,
tests.GatewayStaticAddresses.ShortName,
tests.GatewayWithAttachedRoutes.ShortName,
tests.HTTPRouteBackendProtocolH2C.ShortName,
},
ExemptFeatures: suite.MeshCoreFeatures,
Expand Down

0 comments on commit d6ddf78

Please sign in to comment.