@@ -248,6 +248,8 @@ func (t *Translator) ProcessBackendTrafficPolicies(
248248 SectionIndex : make (map [types.NamespacedName ]sets.Set [string ], gatewayMapSize ),
249249 }
250250
251+ policyCopies := backendTrafficPolicyCopiesWithStatusDeepCopy (backendTrafficPolicies )
252+
251253 handledPolicies := make (map [types.NamespacedName ]* egv1a1.BackendTrafficPolicy , policyMapSize )
252254
253255 // Translate
@@ -260,15 +262,15 @@ func (t *Translator) ProcessBackendTrafficPolicies(
260262 t .buildGatewayPolicyMap (backendTrafficPolicies , gateways , gatewayMap , gatewayPolicyMap )
261263
262264 // Process the policies targeting RouteRules
263- for _ , currPolicy := range backendTrafficPolicies {
265+ for i , currPolicy := range backendTrafficPolicies {
264266 policyName := utils .NamespacedName (currPolicy )
265267 targetRefs := getPolicyTargetRefs (currPolicy .Spec .PolicyTargetReferences , routes , currPolicy .Namespace )
266268 for _ , currTarget := range targetRefs {
267269 // If the target is not a gateway, then it's an xRoute. If the section name is defined, then it's a route rule.
268270 if currTarget .Kind != resource .KindGateway && currTarget .SectionName != nil {
269271 policy , found := handledPolicies [policyName ]
270272 if ! found {
271- policy = currPolicy
273+ policy = policyCopies [ i ]
272274 handledPolicies [policyName ] = policy
273275 res = append (res , policy )
274276 }
@@ -280,15 +282,15 @@ func (t *Translator) ProcessBackendTrafficPolicies(
280282 }
281283
282284 // Process the policies targeting Routes
283- for _ , currPolicy := range backendTrafficPolicies {
285+ for i , currPolicy := range backendTrafficPolicies {
284286 policyName := utils .NamespacedName (currPolicy )
285287 targetRefs := getPolicyTargetRefs (currPolicy .Spec .PolicyTargetReferences , routes , currPolicy .Namespace )
286288 for _ , currTarget := range targetRefs {
287289 // If the target is not a gateway, then it's an xRoute. If the section name is not defined, then it's a route.
288290 if currTarget .Kind != resource .KindGateway && currTarget .SectionName == nil {
289291 policy , found := handledPolicies [policyName ]
290292 if ! found {
291- policy = currPolicy
293+ policy = policyCopies [ i ]
292294 handledPolicies [policyName ] = policy
293295 res = append (res , policy )
294296 }
@@ -300,15 +302,15 @@ func (t *Translator) ProcessBackendTrafficPolicies(
300302 }
301303
302304 // Process the policies targeting Listeners
303- for _ , currPolicy := range backendTrafficPolicies {
305+ for i , currPolicy := range backendTrafficPolicies {
304306 policyName := utils .NamespacedName (currPolicy )
305307 targetRefs := getPolicyTargetRefs (currPolicy .Spec .PolicyTargetReferences , gateways , currPolicy .Namespace )
306308 for _ , currTarget := range targetRefs {
307309 // If the target is a gateway and the section name is defined, then it's a listener.
308310 if currTarget .Kind == resource .KindGateway && currTarget .SectionName != nil {
309311 policy , found := handledPolicies [policyName ]
310312 if ! found {
311- policy = currPolicy
313+ policy = policyCopies [ i ]
312314 handledPolicies [policyName ] = policy
313315 res = append (res , policy )
314316 }
@@ -319,15 +321,15 @@ func (t *Translator) ProcessBackendTrafficPolicies(
319321 }
320322
321323 // Process the policies targeting Gateways
322- for _ , currPolicy := range backendTrafficPolicies {
324+ for i , currPolicy := range backendTrafficPolicies {
323325 policyName := utils .NamespacedName (currPolicy )
324326 targetRefs := getPolicyTargetRefs (currPolicy .Spec .PolicyTargetReferences , gateways , currPolicy .Namespace )
325327 for _ , currTarget := range targetRefs {
326328 // If the target is a gateway and the section name is not defined, then it's a gateway.
327329 if currTarget .Kind == resource .KindGateway && currTarget .SectionName == nil {
328330 policy , found := handledPolicies [policyName ]
329331 if ! found {
330- policy = currPolicy
332+ policy = policyCopies [ i ]
331333 handledPolicies [policyName ] = policy
332334 res = append (res , policy )
333335 }
@@ -2077,3 +2079,15 @@ func buildRouteStatName(routeStatName string, metadata *ir.ResourceMetadata) *st
20772079
20782080 return & statName
20792081}
2082+
2083+ // backendTrafficPolicyCopiesWithStatusDeepCopy returns shallow copies with deep-copied Status fields.
2084+ // Status is mutated during translation and shares a pointer with the watchable coalesce goroutine.
2085+ func backendTrafficPolicyCopiesWithStatusDeepCopy (policies []* egv1a1.BackendTrafficPolicy ) []* egv1a1.BackendTrafficPolicy {
2086+ copies := make ([]* egv1a1.BackendTrafficPolicy , len (policies ))
2087+ for i , p := range policies {
2088+ out := * p
2089+ p .Status .DeepCopyInto (& out .Status )
2090+ copies [i ] = & out
2091+ }
2092+ return copies
2093+ }
0 commit comments