@@ -216,7 +216,7 @@ func (r *routeReconciler) getRoute(ctx context.Context, req ctrl.Request) (core.
216216}
217217
218218func 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 )
220220 if len (gws ) <= 0 {
221221 return fmt .Errorf ("failed to get gateway for route %s: %w" , route .Name (), err )
222222 }
@@ -233,43 +233,10 @@ func (r *routeReconciler) isRouteRelevant(ctx context.Context, route core.Route)
233233 }
234234 // if route has gateway parentRef that is controlled by lattice gateway controller,
235235 // then it is relevant
236- gws , _ := findControlledParents (ctx , r .client , route )
236+ gws , _ := k8s . FindControlledParents (ctx , r .client , route )
237237 return len (gws ) > 0
238238}
239239
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-
273240func (r * routeReconciler ) buildAndDeployModel (
274241 ctx context.Context ,
275242 route core.Route ,
@@ -308,7 +275,7 @@ func (r *routeReconciler) buildAndDeployModel(
308275}
309276
310277func (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 )
312279 if len (gws ) <= 0 {
313280 return gwv1.ParentReference {}, fmt .Errorf ("failed to get gateway for route %s: %w" , route .Name (), err )
314281 }
@@ -528,7 +495,7 @@ func (r *routeReconciler) validateRouteParentRefs(ctx context.Context, route cor
528495 }
529496
530497 parentStatuses := []gwv1.RouteParentStatus {}
531- gws , err := findControlledParents (ctx , r .client , route )
498+ gws , err := k8s . FindControlledParents (ctx , r .client , route )
532499 if len (gws ) <= 0 {
533500 return nil , fmt .Errorf ("failed to get gateway for route %s: %w" , route .Name (), err )
534501 }
0 commit comments