@@ -34,7 +34,7 @@ type HTTPRoute struct {
3434 // K8sResource is the source resource.
3535 K8sResource * gatewayv1.HTTPRoute
3636 // selected listener
37- Listeners utils.KeyMap [gatewayv1.ParentReference , * Listener ] // map[parentRef]
37+ Listeners utils.KeyMap [gatewayv1.ParentReference , [] * Listener ] // map[parentRef]
3838 // Rules
3939 Rules []* HTTPRouteRule
4040 // Final Conditions
@@ -70,7 +70,7 @@ func NewRoute(k8sObject *gatewayv1.HTTPRoute, controllerName string) *HTTPRoute
7070 Status : store .StatusUpserted ,
7171 OldTreeResource : nil ,
7272 },
73- Listeners : utils.NewKeyMap [gatewayv1.ParentReference , * Listener ](utils .ParentRefToKey ),
73+ Listeners : utils.NewKeyMap [gatewayv1.ParentReference , [] * Listener ](utils .ParentRefToKey ),
7474 CheckParentRefs : CheckResultRoute {
7575 Valid : false ,
7676 Conditions : rc.RouteConditions {
@@ -176,20 +176,17 @@ func (r *HTTPRoute) checkParentRefs(controllerStore ControllerStore) {
176176 continue
177177 }
178178
179+ routeConditions .MergeOverrideConditionsForParentRef (parentRef , result .Conditions )
179180 // From now on, parentRef is a managed Gateway
180181
181182 // 1- The parentRef is not Valid
182183 if ! result .Valid {
183184 // do not add the parentREf in Listener or check result
184- routeConditions .MergeOverrideConditionsForParentRef (parentRef , result .Conditions )
185185 continue
186186 }
187187
188188 // 2- The parentRef is Valid
189189 atLeastOneValidParentRef = true
190- routeConditions .MergeOverrideConditionsForParentRef (parentRef , result .Conditions )
191- // no specific conditions
192- r .Listeners .Set (parentRef , result .Listener )
193190 }
194191
195192 // Gather all Conditions for all parentRefs in the result
@@ -207,8 +204,6 @@ type checkParentRefResult struct {
207204 // Conditions has a set of failing conditions
208205 // It is set only if Managed is true
209206 Conditions generic.Conditions
210- // Listener is the selected Listener
211- Listener * Listener
212207 // Managed is true if the Gateway is managed by our controller
213208 Managed bool
214209 // Valid is set only if Managed is true
@@ -218,6 +213,7 @@ type checkParentRefResult struct {
218213// checkParentRef checks 1 parentRef and returns:
219214// - a bool indicating if the parentRef is valid, and if it's not, a set of conditions detailing why
220215func (r * HTTPRoute ) checkParentRef (parentRef gatewayv1.ParentReference , controllerStore ControllerStore ) checkParentRefResult {
216+ // Vérifie si le type de parentRef est supporté
221217 if ! isParentRefGroupKindSupported (parentRef , controllerStore .ExtractGVK ) {
222218 return checkParentRefResult {
223219 Managed : false ,
@@ -226,34 +222,27 @@ func (r *HTTPRoute) checkParentRef(parentRef gatewayv1.ParentReference, controll
226222 }
227223 }
228224
225+ // Récupère le Gateway correspondant
229226 gwKey := GetParentRefNamespacedName (parentRef , r .K8sResource )
230-
231227 treeGw , ok := controllerStore .GateTree .Gateways [gwKey ]
232228 if ok && treeGw .TreeStatus .Status == store .StatusDeleted {
233- // gateway exists, but it was deleted
234229 return checkParentRefResult {
235230 Managed : true ,
236231 Valid : false ,
237232 Conditions : rc .ConditionNotAcceptedNoMatchingParent (),
238233 }
239234 }
240235 if ! ok {
241- // It's a whole different story, it means the Gateway does not exists,
242- // we can not know if it's managed by our controller or not
243236 return checkParentRefResult {
244237 Managed : false ,
245238 Valid : false ,
246239 Conditions : generic.Conditions {},
247240 }
248241 }
249242
250- // From now on, the parent references an exising Gateway managed by our controller
251- // SectionName is optional
252- // 1- if set, the only attachable listener is the one references by the sectionName
253- // 2- if not set, all listeners from the Gateway are attachable
243+ // Collecte les listeners attachables
254244 attachableListeners := make ([]* Listener , 0 )
255245 if parentRef .SectionName != nil {
256- // Check if the Gateway has this listener
257246 listener , ok := treeGw .Listeners [string (* parentRef .SectionName )]
258247 if ! ok {
259248 return checkParentRefResult {
@@ -262,94 +251,59 @@ func (r *HTTPRoute) checkParentRef(parentRef gatewayv1.ParentReference, controll
262251 Conditions : rc .ConditionNotAcceptedNoMatchingParent (),
263252 }
264253 }
265- // We found the listener, it does exists
266254 attachableListeners = append (attachableListeners , listener )
267255 } else {
268256 for _ , listener := range treeGw .Listeners {
269257 attachableListeners = append (attachableListeners , listener )
270258 }
271259 }
272260
273- // If we have only 1 attache listener, just check the hostnames
274- if len (attachableListeners ) == 1 {
275- listener := attachableListeners [0 ]
276- if ! listener .Valid {
277- return checkParentRefResult {
278- Managed : true ,
279- Valid : false ,
280- Conditions : rc .ConditionNotAcceptedNoMatchingParent (),
281- }
282- }
283- if matched := matchHostname (r .K8sResource .Spec .Hostnames , listener .K8sResource .Hostname ); matched {
284- // AllowedRouteKind ???
285- allowedRouteKind := r .isAllowedRouteKind (listener , controllerStore .ExtractGVK )
286- if ! allowedRouteKind {
287- return checkParentRefResult {
288- Managed : true ,
289- Valid : false ,
290- Conditions : rc .ConditionNotAcceptedRouteReasonNotAllowedByListeners (),
291- }
292- }
293-
294- // Set the Listener attached Route
295- listener .addAttachedRoute (client .ObjectKeyFromObject (r .K8sResource ), controllerStore )
296-
297- return checkParentRefResult {
298- Managed : true ,
299- Valid : true ,
300- Listener : listener ,
301- Conditions : rc .ConditionAccepted (),
302- }
303- }
304- return checkParentRefResult {
305- Managed : true ,
306- Valid : false ,
307- Conditions : rc .ConditionNotAcceptedNoMatchingHostname (),
308- }
309- }
261+ validListeners := make ([]* Listener , 0 )
262+ conds := generic.Conditions {}
310263
311- // Now, case where we need to find a listener among the list
312- var matched bool
313- var matchedListener * Listener
314264 for _ , listener := range attachableListeners {
265+ // Vérifie la validité du listener
315266 if ! listener .Valid {
267+ conds .MergeOverrideConditions (rc .ConditionNotAcceptedNoMatchingParent ())
316268 continue
317269 }
318270
319- // Match Hostname ?
320- if matchHostname (r .K8sResource .Spec .Hostnames , listener .K8sResource .Hostname ) {
321- matched = true
322- matchedListener = listener
323- break
271+ // Vérifie le hostname
272+ if ! matchHostname (r .K8sResource .Spec .Hostnames , listener .K8sResource .Hostname ) {
273+ conds .MergeOverrideConditions (rc .ConditionNotAcceptedNoMatchingHostname ())
274+ continue
324275 }
325- }
326- if ! matched {
327- return checkParentRefResult {
328- Managed : true ,
329- Valid : false ,
330- Conditions : rc .ConditionNotAcceptedNoMatchingParent (),
276+
277+ // Vérifie le type de route autorisé
278+ if ! r .isAllowedRouteKind (listener , controllerStore .ExtractGVK ) {
279+ conds .MergeOverrideConditions (rc .ConditionNotAcceptedRouteReasonNotAllowedByListeners ())
280+ continue
331281 }
332- }
333282
334- // We have found a listener
335- // Allowed RouteKind ??
336- allowedRouteKind := r .isAllowedRouteKind (matchedListener , controllerStore .ExtractGVK )
337- // Set the Listener attached Route
338- matchedListener .addAttachedRoute (client .ObjectKeyFromObject (r .K8sResource ), controllerStore )
283+ // Listener valide, attache la route
284+ listener .addAttachedRoute (client .ObjectKeyFromObject (r .K8sResource ), controllerStore )
285+ validListeners = append (validListeners , listener )
286+
287+ // Met à jour la KeyMap r.Listeners
288+ existing , _ := r .Listeners .Get (parentRef )
289+ existing = append (existing , listener )
290+ r .Listeners .Set (parentRef , existing )
291+ }
339292
340- if ! allowedRouteKind {
293+ // Si aucun listener valide, retourne les conditions cumulées
294+ if len (validListeners ) == 0 {
341295 return checkParentRefResult {
342296 Managed : true ,
343297 Valid : false ,
344- Conditions : rc . ConditionNotAcceptedRouteReasonNotAllowedByListeners () ,
298+ Conditions : conds ,
345299 }
346300 }
347301
302+ // Au moins un listener valide
348303 return checkParentRefResult {
349304 Managed : true ,
350305 Valid : true ,
351- Listener : matchedListener ,
352- Conditions : generic.Conditions {},
306+ Conditions : rc .ConditionAccepted (),
353307 }
354308}
355309
0 commit comments