Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions internal/gatewayapi/envoyextensionpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -377,6 +377,9 @@ func resolveEEPolicyGatewayTargetRef(
Message: message,
}
}
if gateway.attachedToListeners == nil {
gateway.attachedToListeners = make(sets.Set[string])
}
gateway.attachedToListeners.Insert(listenerName)
}

Expand Down Expand Up @@ -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)

Expand All @@ -433,6 +436,9 @@ func resolveEEPolicyRouteTargetRef(
Message: message,
}
}
if route.attachedToRouteRules == nil {
route.attachedToRouteRules = make(sets.Set[string])
}
route.attachedToRouteRules.Insert(routeRuleName)
}

Expand Down
20 changes: 10 additions & 10 deletions internal/gatewayapi/securitypolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)

Expand All @@ -474,6 +468,9 @@ func resolveSecurityPolicyGatewayTargetRef(
Message: message,
}
}
if gateway.attachedToListeners == nil {
gateway.attachedToListeners = make(sets.Set[string])
}
gateway.attachedToListeners.Insert(listenerName)
}

Expand Down Expand Up @@ -524,14 +521,17 @@ 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{
Reason: gwapiv1a2.PolicyReasonConflicted,
Message: message,
}
}
if route.attachedToRouteRules == nil {
route.attachedToRouteRules = make(sets.Set[string])
}
route.attachedToRouteRules.Insert(routeRuleName)
}

Expand Down
Loading