@@ -156,35 +156,34 @@ func (d *routeReconcilerImpl) updateRouteStatus(route client.Object, routeData r
156156 originalRouteStatus = r .Status .Parents
157157 ParentRefs = r .Spec .ParentRefs
158158 }
159+ routeNamespace := route .GetNamespace ()
159160
160161 // set conditions
161162 var newRouteStatus []gwv1.RouteParentStatus
162- originalRouteStatusMap := createOriginalRouteStatusMap (originalRouteStatus )
163-
163+ originalRouteStatusMap := createOriginalRouteStatusMap (originalRouteStatus , routeNamespace )
164164 for _ , parentRef := range ParentRefs {
165165 newRouteParentStatus := gwv1.RouteParentStatus {
166166 ParentRef : parentRef ,
167167 ControllerName : gwv1 .GatewayController (controllerName ),
168168 Conditions : []metav1.Condition {},
169169 }
170170 // if status related to parentRef exists, keep the condition first
171- if status , exists := originalRouteStatusMap [getParentStatusKey (parentRef )]; exists {
171+ if status , exists := originalRouteStatusMap [getParentStatusKey (parentRef , routeNamespace )]; exists {
172172 newRouteParentStatus .Conditions = status .Conditions
173173 }
174- // Namespace is the namespace of the referent. When unspecified, this refers to the local namespace of the Route.
175- namespace := route .GetNamespace ()
176- if parentRef .Namespace != nil {
177- namespace = string (* parentRef .Namespace )
178- }
174+
175+ // Generate key for routeData's parentRef
176+ routeDataParentRefKey := getParentRefKeyFromRouteData (routeData .ParentRefGateway )
179177
180178 // do not allow backward generation update, Accepted and ResolvedRef always have same generation based on our implementation
181179 if (len (newRouteParentStatus .Conditions ) != 0 && newRouteParentStatus .Conditions [0 ].ObservedGeneration <= routeData .RouteMetadata .RouteGeneration ) || len (newRouteParentStatus .Conditions ) == 0 {
182180 // for a given parentRef, if it has a statusInfo, this means condition is updated, override route condition based on route status info
183- if namespace == routeData .ParentRefGateway .Namespace && string (parentRef .Name ) == routeData .ParentRefGateway .Name {
181+ parentRefKey := getParentStatusKey (parentRef , routeNamespace )
182+ if parentRefKey == routeDataParentRefKey {
184183 d .setConditionsWithRouteStatusInfo (route , & newRouteParentStatus , routeData .RouteStatusInfo )
185184 }
186185
187- // resolve ref Gateway, if parentRef does not have namespace, getting it from Route
186+ // handle parentRefNotExist: resolve ref Gateway, if parentRef does not have namespace, getting it from Route
188187 if _ , err := d .resolveRefGateway (parentRef , route .GetNamespace ()); err != nil {
189188 // set conditions if resolvedRef = false
190189 d .setConditionsBasedOnResolveRefGateway (route , & newRouteParentStatus , err )
@@ -283,9 +282,9 @@ func (d *routeReconcilerImpl) setConditionsBasedOnResolveRefGateway(route client
283282 },
284283 {
285284 Type : string (gwv1 .RouteConditionResolvedRefs ),
286- Status : metav1 .ConditionFalse ,
287- Reason : routeutils . RouteStatusInfoRejectedParentRefNotExist ,
288- Message : resolveErr . Error () ,
285+ Status : metav1 .ConditionTrue ,
286+ Reason : string ( gwv1 . RouteConditionResolvedRefs ) ,
287+ Message : "" ,
289288 LastTransitionTime : timeNow ,
290289 ObservedGeneration : route .GetGeneration (),
291290 },
@@ -310,12 +309,12 @@ func (d *routeReconcilerImpl) isRouteStatusIdentical(routeOld client.Object, rou
310309
311310 // build maps, key is a string which is combined from parentRef fields
312311 for _ , status := range routeOldStatus {
313- key := getParentStatusKey (status .ParentRef )
312+ key := getParentStatusKey (status .ParentRef , routeOld . GetNamespace () )
314313 oldStatusMap [key ] = status
315314 }
316315
317316 for _ , status := range routeNewStatus {
318- key := getParentStatusKey (status .ParentRef )
317+ key := getParentStatusKey (status .ParentRef , route . GetNamespace () )
319318 newStatusMap [key ] = status
320319 }
321320
@@ -359,11 +358,37 @@ func getRouteStatus(route client.Object) []gwv1.RouteParentStatus {
359358 return routeStatus
360359}
361360
361+ // Helper function to generate key from RouteData's ParentRefGateway, use same format as getParentStatusKey
362+ func getParentRefKeyFromRouteData (gatewayRef routeutils.ParentRefGateway ) string {
363+
364+ namespace := gatewayRef .Namespace
365+
366+ sectionName := ""
367+ if gatewayRef .SectionName != nil {
368+ sectionName = string (* gatewayRef .SectionName )
369+ }
370+
371+ port := ""
372+ if gatewayRef .Port != nil {
373+ port = strconv .Itoa (int (* gatewayRef .Port ))
374+ }
375+
376+ key := fmt .Sprintf ("%s/%s/%s/%s" ,
377+ namespace ,
378+ gatewayRef .Name ,
379+ sectionName ,
380+ port )
381+
382+ return key
383+ }
384+
362385// Helper function to generate a unique key for a RouteParentStatus
363- func getParentStatusKey (ref gwv1.ParentReference ) string {
386+ func getParentStatusKey (ref gwv1.ParentReference , routeNamespace string ) string {
364387 namespace := ""
365388 if ref .Namespace != nil {
366389 namespace = string (* ref .Namespace )
390+ } else {
391+ namespace = routeNamespace
367392 }
368393
369394 sectionName := ""
@@ -376,19 +401,7 @@ func getParentStatusKey(ref gwv1.ParentReference) string {
376401 port = strconv .Itoa (int (* ref .Port ))
377402 }
378403
379- group := ""
380- if ref .Group != nil {
381- group = string (* ref .Group )
382- }
383-
384- kind := ""
385- if ref .Kind != nil {
386- kind = string (* ref .Kind )
387- }
388-
389- key := fmt .Sprintf ("%s/%s/%s/%s/%s/%s" ,
390- group ,
391- kind ,
404+ key := fmt .Sprintf ("%s/%s/%s/%s" ,
392405 namespace ,
393406 string (ref .Name ),
394407 sectionName ,
@@ -427,10 +440,10 @@ func areConditionsEqual(oldConditions, newConditions []metav1.Condition) bool {
427440 return true
428441}
429442
430- func createOriginalRouteStatusMap (originalRouteStatus []gwv1.RouteParentStatus ) map [string ]gwv1.RouteParentStatus {
443+ func createOriginalRouteStatusMap (originalRouteStatus []gwv1.RouteParentStatus , routeNamespace string ) map [string ]gwv1.RouteParentStatus {
431444 originalStatusMap := make (map [string ]gwv1.RouteParentStatus )
432445 for i := range originalRouteStatus {
433- key := getParentStatusKey (originalRouteStatus [i ].ParentRef )
446+ key := getParentStatusKey (originalRouteStatus [i ].ParentRef , routeNamespace )
434447 originalStatusMap [key ] = originalRouteStatus [i ]
435448 }
436449 return originalStatusMap
0 commit comments