@@ -216,7 +216,7 @@ func (r *routeReconciler) getRoute(ctx context.Context, req ctrl.Request) (core.
216
216
}
217
217
218
218
func updateRouteListenerStatus (ctx context.Context , k8sClient client.Client , route core.Route ) error {
219
- gws , err := findControlledParents (ctx , k8sClient , route )
219
+ gws , err := k8s . FindControlledParents (ctx , k8sClient , route )
220
220
if len (gws ) <= 0 {
221
221
return fmt .Errorf ("failed to get gateway for route %s: %w" , route .Name (), err )
222
222
}
@@ -233,43 +233,10 @@ func (r *routeReconciler) isRouteRelevant(ctx context.Context, route core.Route)
233
233
}
234
234
// if route has gateway parentRef that is controlled by lattice gateway controller,
235
235
// then it is relevant
236
- gws , _ := findControlledParents (ctx , r .client , route )
236
+ gws , _ := k8s . FindControlledParents (ctx , r .client , route )
237
237
return len (gws ) > 0
238
238
}
239
239
240
- // findControlledParents returns parent gateways that are controlled by lattice gateway controller
241
- func findControlledParents (
242
- ctx context.Context ,
243
- client client.Client ,
244
- route core.Route ,
245
- ) ([]* gwv1.Gateway , error ) {
246
- var result []* gwv1.Gateway
247
- gwNamespace := route .Namespace ()
248
- misses := []string {}
249
- for _ , parentRef := range route .Spec ().ParentRefs () {
250
- gw := & gwv1.Gateway {}
251
- if parentRef .Namespace != nil {
252
- gwNamespace = string (* parentRef .Namespace )
253
- }
254
- gwName := types.NamespacedName {
255
- Namespace : gwNamespace ,
256
- Name : string (parentRef .Name ),
257
- }
258
- if err := client .Get (ctx , gwName , gw ); err != nil {
259
- misses = append (misses , gwName .String ())
260
- continue
261
- }
262
- if k8s .IsControlledByLatticeGatewayController (ctx , client , gw ) {
263
- result = append (result , gw )
264
- }
265
- }
266
- var err error
267
- if len (misses ) > 0 {
268
- err = fmt .Errorf ("failed to get gateway, name %s" , misses )
269
- }
270
- return result , err
271
- }
272
-
273
240
func (r * routeReconciler ) buildAndDeployModel (
274
241
ctx context.Context ,
275
242
route core.Route ,
@@ -308,7 +275,7 @@ func (r *routeReconciler) buildAndDeployModel(
308
275
}
309
276
310
277
func (r * routeReconciler ) findControlledParentRef (ctx context.Context , route core.Route ) (gwv1.ParentReference , error ) {
311
- gws , err := findControlledParents (ctx , r .client , route )
278
+ gws , err := k8s . FindControlledParents (ctx , r .client , route )
312
279
if len (gws ) <= 0 {
313
280
return gwv1.ParentReference {}, fmt .Errorf ("failed to get gateway for route %s: %w" , route .Name (), err )
314
281
}
@@ -528,7 +495,7 @@ func (r *routeReconciler) validateRouteParentRefs(ctx context.Context, route cor
528
495
}
529
496
530
497
parentStatuses := []gwv1.RouteParentStatus {}
531
- gws , err := findControlledParents (ctx , r .client , route )
498
+ gws , err := k8s . FindControlledParents (ctx , r .client , route )
532
499
if len (gws ) <= 0 {
533
500
return nil , fmt .Errorf ("failed to get gateway for route %s: %w" , route .Name (), err )
534
501
}
0 commit comments