diff --git a/internal/gatewayapi/envoyextensionpolicy.go b/internal/gatewayapi/envoyextensionpolicy.go index 607e09b972..cd7a442b24 100644 --- a/internal/gatewayapi/envoyextensionpolicy.go +++ b/internal/gatewayapi/envoyextensionpolicy.go @@ -51,13 +51,13 @@ func (t *Translator) ProcessEnvoyExtensionPolicies(envoyExtensionPolicies []*egv Name: route.GetName(), Namespace: route.GetNamespace(), } - routeMap[key] = &policyRouteTargetContext{RouteContext: route, attachedToRouteRules: make(sets.Set[string])} + routeMap[key] = &policyRouteTargetContext{RouteContext: route} } gatewayMap := map[types.NamespacedName]*policyGatewayTargetContext{} for _, gw := range gateways { key := utils.NamespacedName(gw) - gatewayMap[key] = &policyGatewayTargetContext{GatewayContext: gw, attachedToListeners: make(sets.Set[string])} + gatewayMap[key] = &policyGatewayTargetContext{GatewayContext: gw} } // Map of Gateway to the routes attached to it. @@ -368,7 +368,7 @@ func resolveEEPolicyGatewayTargetRef( gateway.attached = true } else { listenerName := string(*target.SectionName) - if gateway.attachedToListeners.Has(listenerName) { + if gateway.attachedToListeners != nil && gateway.attachedToListeners.Has(listenerName) { message := fmt.Sprintf("Unable to target Listener %s/%s, another EnvoyExtensionPolicy has already attached to it", string(target.Name), listenerName) @@ -377,6 +377,9 @@ func resolveEEPolicyGatewayTargetRef( Message: message, } } + if gateway.attachedToListeners == nil { + gateway.attachedToListeners = make(sets.Set[string]) + } gateway.attachedToListeners.Insert(listenerName) } @@ -424,7 +427,7 @@ func resolveEEPolicyRouteTargetRef( route.attached = true } else { routeRuleName := string(*target.SectionName) - if route.attachedToRouteRules.Has(routeRuleName) { + if route.attachedToRouteRules != nil && route.attachedToRouteRules.Has(routeRuleName) { message := fmt.Sprintf("Unable to target RouteRule %s/%s, another EnvoyExtensionPolicy has already attached to it", string(target.Name), routeRuleName) @@ -433,6 +436,9 @@ func resolveEEPolicyRouteTargetRef( Message: message, } } + if route.attachedToRouteRules == nil { + route.attachedToRouteRules = make(sets.Set[string]) + } route.attachedToRouteRules.Insert(routeRuleName) } diff --git a/internal/gatewayapi/securitypolicy.go b/internal/gatewayapi/securitypolicy.go index b2930b2701..4f6be63667 100644 --- a/internal/gatewayapi/securitypolicy.go +++ b/internal/gatewayapi/securitypolicy.go @@ -73,19 +73,13 @@ func (t *Translator) ProcessSecurityPolicies(securityPolicies []*egv1a1.Security Name: route.GetName(), Namespace: route.GetNamespace(), } - routeMap[key] = &policyRouteTargetContext{ - RouteContext: route, - attachedToRouteRules: make(sets.Set[string]), - } + routeMap[key] = &policyRouteTargetContext{RouteContext: route} } gatewayMap := make(map[types.NamespacedName]*policyGatewayTargetContext, gatewayMapSize) for _, gw := range gateways { key := utils.NamespacedName(gw) - gatewayMap[key] = &policyGatewayTargetContext{ - GatewayContext: gw, - attachedToListeners: make(sets.Set[string]), - } + gatewayMap[key] = &policyGatewayTargetContext{GatewayContext: gw} } // Map of Gateway to the routes attached to it. @@ -465,7 +459,7 @@ func resolveSecurityPolicyGatewayTargetRef( gateway.attached = true } else { listenerName := string(*target.SectionName) - if gateway.attachedToListeners.Has(listenerName) { + if gateway.attachedToListeners != nil && gateway.attachedToListeners.Has(listenerName) { message := fmt.Sprintf("Unable to target Listener %s/%s, another SecurityPolicy has already attached to it", string(target.Name), listenerName) @@ -474,6 +468,9 @@ func resolveSecurityPolicyGatewayTargetRef( Message: message, } } + if gateway.attachedToListeners == nil { + gateway.attachedToListeners = make(sets.Set[string]) + } gateway.attachedToListeners.Insert(listenerName) } @@ -524,7 +521,7 @@ func resolveSecurityPolicyRouteTargetRef( route.attached = true } else { routeRuleName := string(*target.SectionName) - if route.attachedToRouteRules.Has(routeRuleName) { + if route.attachedToRouteRules != nil && route.attachedToRouteRules.Has(routeRuleName) { message := fmt.Sprintf("Unable to target RouteRule %s/%s, another SecurityPolicy has already attached to it", string(target.Name), routeRuleName) return route.RouteContext, &status.PolicyResolveError{ @@ -532,6 +529,9 @@ func resolveSecurityPolicyRouteTargetRef( Message: message, } } + if route.attachedToRouteRules == nil { + route.attachedToRouteRules = make(sets.Set[string]) + } route.attachedToRouteRules.Insert(routeRuleName) }