@@ -76,6 +76,23 @@ func (l *loaderImpl) LoadRoutesForGateway(ctx context.Context, gw gwv1.Gateway,
7676 // 1. Load all relevant routes according to the filter
7777
7878 loadedRoutes := make ([]preLoadRouteDescriptor , 0 )
79+
80+ routeStatusUpdates := make ([]RouteData , 0 )
81+
82+ defer func () {
83+ seenCache := sets .NewString ()
84+ // As we process the failures first, we ensure that we don't flip flop the route status from
85+ // failed -> ok.
86+ for _ , v := range routeStatusUpdates {
87+ k := generateRouteDataCacheKey (v )
88+ if seenCache .Has (k ) {
89+ continue
90+ }
91+ seenCache .Insert (k )
92+ l .routeSubmitter .Enqueue (v )
93+ }
94+ }()
95+
7996 for route , loader := range l .allRouteLoaders {
8097 applicable := filter .IsApplicable (route )
8198 l .logger .V (1 ).Info ("Processing route" , "route" , route , "is applicable" , applicable )
@@ -90,35 +107,37 @@ func (l *loaderImpl) LoadRoutesForGateway(ctx context.Context, gw gwv1.Gateway,
90107
91108 // 2. Remove routes that aren't granted attachment by the listener.
92109 // Map any routes that are granted attachment to the listener port that allows the attachment.
93- mappedRoutes , err := l .mapper .mapGatewayAndRoutes (ctx , gw , loadedRoutes , l .routeSubmitter )
110+ mappedRoutes , statusUpdates , err := l .mapper .mapGatewayAndRoutes (ctx , gw , loadedRoutes )
111+
112+ routeStatusUpdates = append (routeStatusUpdates , statusUpdates ... )
113+
94114 if err != nil {
95115 return nil , err
96116 }
97117
98118 // 3. Load the underlying resource(s) for each route that is configured.
99- loadedRoute , err := l .loadChildResources (ctx , mappedRoutes , gw )
119+ loadedRoute , childRouteLoadUpdates , err := l .loadChildResources (ctx , mappedRoutes , gw )
120+ routeStatusUpdates = append (routeStatusUpdates , childRouteLoadUpdates ... )
100121 if err != nil {
101122 return nil , err
102123 }
103124
104125 // update status for accepted routes
105126 for _ , routeList := range loadedRoute {
106127 for _ , route := range routeList {
107- l .routeSubmitter .Enqueue (
108- GenerateRouteData (true , true , string (gwv1 .RouteConditionAccepted ), RouteStatusInfoAcceptedMessage , route .GetRouteNamespacedName (), route .GetRouteKind (), route .GetRouteGeneration (), gw ),
109- )
128+ routeStatusUpdates = append (routeStatusUpdates , GenerateRouteData (true , true , string (gwv1 .RouteConditionAccepted ), RouteStatusInfoAcceptedMessage , route .GetRouteNamespacedName (), route .GetRouteKind (), route .GetRouteGeneration (), gw ))
110129 }
111130 }
112131 return loadedRoute , nil
113132}
114133
115134// loadChildResources responsible for loading all resources that a route descriptor references.
116- func (l * loaderImpl ) loadChildResources (ctx context.Context , preloadedRoutes map [int ][]preLoadRouteDescriptor , gw gwv1.Gateway ) (map [int32 ][]RouteDescriptor , error ) {
135+ func (l * loaderImpl ) loadChildResources (ctx context.Context , preloadedRoutes map [int ][]preLoadRouteDescriptor , gw gwv1.Gateway ) (map [int32 ][]RouteDescriptor , [] RouteData , error ) {
117136 // Cache to reduce duplicate route lookups.
118137 // Kind -> [NamespacedName:Previously Loaded Descriptor]
119138 resourceCache := make (map [string ]RouteDescriptor )
120-
121139 loadedRouteData := make (map [int32 ][]RouteDescriptor )
140+ failedRoutes := make ([]RouteData , 0 )
122141
123142 for port , preloadedRouteList := range preloadedRoutes {
124143 for _ , preloadedRoute := range preloadedRouteList {
@@ -137,12 +156,10 @@ func (l *loaderImpl) loadChildResources(ctx context.Context, preloadedRoutes map
137156 for _ , lare := range loadAttachedRulesErrors {
138157 var loaderErr LoaderError
139158 if errors .As (lare .Err , & loaderErr ) {
140- l .routeSubmitter .Enqueue (
141- GenerateRouteData (false , false , string (loaderErr .GetRouteReason ()), loaderErr .GetRouteMessage (), preloadedRoute .GetRouteNamespacedName (), preloadedRoute .GetRouteKind (), preloadedRoute .GetRouteGeneration (), gw ),
142- )
159+ failedRoutes = append (failedRoutes , GenerateRouteData (false , false , string (loaderErr .GetRouteReason ()), loaderErr .GetRouteMessage (), preloadedRoute .GetRouteNamespacedName (), preloadedRoute .GetRouteKind (), preloadedRoute .GetRouteGeneration (), gw ))
143160 }
144161 if lare .Fatal {
145- return nil , lare .Err
162+ return nil , failedRoutes , lare .Err
146163 }
147164 }
148165 }
@@ -151,5 +168,9 @@ func (l *loaderImpl) loadChildResources(ctx context.Context, preloadedRoutes map
151168 }
152169 }
153170
154- return loadedRouteData , nil
171+ return loadedRouteData , failedRoutes , nil
172+ }
173+
174+ func generateRouteDataCacheKey (rd RouteData ) string {
175+ return fmt .Sprintf ("%s-%s-%s-%s-%s" , rd .RouteMetadata .RouteName , rd .RouteMetadata .RouteNamespace , rd .RouteMetadata .RouteKind , rd .ParentRefGateway .Name , rd .ParentRefGateway .Namespace )
155176}
0 commit comments