Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions internal/provider/kubernetes/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ func newHTTPRouteController(mgr manager.Manager, cfg *config.Server, su status.U
return err
}

// Watch Gateway CRUDs and reconcile affected HTTPRoutes.
if err := c.Watch(
&source.Kind{Type: &gwapiv1b1.Gateway{}},
handler.EnqueueRequestsFromMapFunc(r.getHTTPRoutesForGateway),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious how dequeue/deregister works

); err != nil {
return err
}

// Watch Service CRUDs and reconcile affected HTTPRoutes.
if err := c.Watch(
&source.Kind{Type: &corev1.Service{}},
Expand All @@ -104,6 +112,48 @@ func newHTTPRouteController(mgr manager.Manager, cfg *config.Server, su status.U
return nil
}

// getHTTPRoutesForGateway uses a Gateway obj to fetch HTTPRoutes, iterating
// through them and creating a reconciliation request for each valid HTTPRoute
// that references obj.
func (r *httpRouteReconciler) getHTTPRoutesForGateway(obj client.Object) []reconcile.Request {
ctx := context.Background()

gw, ok := obj.(*gwapiv1b1.Gateway)
if !ok {
r.log.Info("unexpected object type, bypassing reconciliation", "object", obj)
return []reconcile.Request{}
}

routes := &gwapiv1b1.HTTPRouteList{}
if err := r.client.List(ctx, routes); err != nil {
return []reconcile.Request{}
}

requests := []reconcile.Request{}
for i := range routes.Items {
route := routes.Items[i]
gateways, err := r.validateParentRefs(ctx, &route)
if err != nil {
r.log.Info("invalid parentRefs for httproute, bypassing reconciliation", "object", obj)
continue
}
for j := range gateways {
if gateways[j].Namespace == gw.Namespace && gateways[j].Name == gw.Name {
req := reconcile.Request{
NamespacedName: types.NamespacedName{
Namespace: route.Namespace,
Name: route.Name,
},
}
requests = append(requests, req)
break
}
}
}

return requests
}

// getHTTPRoutesForService uses a Service obj to fetch HTTPRoutes that references
// the Service using `.spec.rules.backendRefs`. The affected HTTPRoutes are then
// pushed for reconciliation.
Expand Down
Loading