Skip to content

Commit d5ea0a4

Browse files
committed
fix test
Signed-off-by: Huabing (Robin) Zhao <zhaohuabing@gmail.com>
1 parent d347e43 commit d5ea0a4

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

internal/gatewayapi/backendtrafficpolicy.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,7 @@ func (t *Translator) processBackendTrafficPolicyForRoute(
295295
// Do need a section name since the policy is targeting to a route.
296296
ancestorRef := getAncestorRefForPolicy(mapKey.NamespacedName, p.SectionName)
297297
ancestorRefs = append(ancestorRefs, &ancestorRef)
298-
299-
// Only process parentRefs that were handled by this translator
300-
// (skip those referencing Gateways with different GatewayClasses)
301-
if parentRefCtx := targetedRoute.GetRouteParentContext(p); parentRefCtx != nil {
302-
parentRefCtxs = append(parentRefCtxs, parentRefCtx)
303-
}
298+
parentRefCtxs = append(parentRefCtxs, targetedRoute.GetRouteParentContext(p))
304299
}
305300
}
306301

internal/gatewayapi/securitypolicy_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,23 @@ func hasParentFalseCondition(p *egv1a1.SecurityPolicy) bool {
884884
return false
885885
}
886886

887+
func SetRouteParentContext(route RouteContext, parentRef gwapiv1.ParentReference) {
888+
ctx := &RouteParentContext{ParentReference: &parentRef}
889+
switch r := route.(type) {
890+
case *HTTPRouteContext:
891+
ctx.HTTPRoute = r.HTTPRoute
892+
case *GRPCRouteContext:
893+
ctx.GRPCRoute = r.GRPCRoute
894+
case *TLSRouteContext:
895+
ctx.TLSRoute = r.TLSRoute
896+
case *TCPRouteContext:
897+
ctx.TCPRoute = r.TCPRoute
898+
case *UDPRouteContext:
899+
ctx.UDPRoute = r.UDPRoute
900+
}
901+
route.SetRouteParentContext(parentRef, ctx)
902+
}
903+
887904
// --- TCP branch: validateSecurityPolicyForTCP(...) returns err -> SetTranslationErrorForPolicyAncestors(...) + return
888905
func Test_SecurityPolicy_TCP_Invalid_setsStatus_and_returns(t *testing.T) {
889906
tr := &Translator{GatewayControllerName: "gateway.envoyproxy.io/gatewayclass-controller"}
@@ -923,6 +940,7 @@ func Test_SecurityPolicy_TCP_Invalid_setsStatus_and_returns(t *testing.T) {
923940
},
924941
},
925942
}
943+
SetRouteParentContext(tcpRoute, tcpRoute.Spec.ParentRefs[0])
926944

927945
// Create the target reference
928946
target := gwapiv1.LocalPolicyTargetReferenceWithSectionName{
@@ -1000,6 +1018,7 @@ func Test_SecurityPolicy_HTTP_Invalid_setsStatus_and_returns(t *testing.T) {
10001018
},
10011019
},
10021020
}
1021+
SetRouteParentContext(httpRoute, httpRoute.Spec.ParentRefs[0])
10031022

10041023
// Create the target reference
10051024
target := gwapiv1.LocalPolicyTargetReferenceWithSectionName{

0 commit comments

Comments
 (0)