@@ -12,7 +12,9 @@ import (
1212 "k8s.io/apimachinery/pkg/runtime"
1313 "k8s.io/apimachinery/pkg/types"
1414 ctrl "sigs.k8s.io/controller-runtime"
15+ "sigs.k8s.io/controller-runtime/pkg/builder"
1516 "sigs.k8s.io/controller-runtime/pkg/client"
17+ "sigs.k8s.io/controller-runtime/pkg/event"
1618 "sigs.k8s.io/controller-runtime/pkg/handler"
1719 "sigs.k8s.io/controller-runtime/pkg/predicate"
1820 "sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -47,6 +49,25 @@ func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
4749 Watches (& v1alpha1.PluginConfig {},
4850 handler .EnqueueRequestsFromMapFunc (r .listHTTPRoutesByExtensionRef ),
4951 ).
52+ Watches (& gatewayv1.Gateway {},
53+ handler .EnqueueRequestsFromMapFunc (r .listHTTPRoutesForGateway ),
54+ builder .WithPredicates (
55+ predicate.Funcs {
56+ GenericFunc : func (e event.GenericEvent ) bool {
57+ return false
58+ },
59+ DeleteFunc : func (e event.DeleteEvent ) bool {
60+ return false
61+ },
62+ CreateFunc : func (e event.CreateEvent ) bool {
63+ return true
64+ },
65+ UpdateFunc : func (e event.UpdateEvent ) bool {
66+ return true
67+ },
68+ },
69+ ),
70+ ).
5071 Complete (r )
5172}
5273
@@ -190,6 +211,30 @@ func (r *HTTPRouteReconciler) listHTTPRoutesByExtensionRef(ctx context.Context,
190211 return requests
191212}
192213
214+ func (r * HTTPRouteReconciler ) listHTTPRoutesForGateway (ctx context.Context , obj client.Object ) []reconcile.Request {
215+ gateway , ok := obj .(* gatewayv1.Gateway )
216+ if ! ok {
217+ r .Log .Error (fmt .Errorf ("unexpected object type" ), "failed to convert object to Gateway" )
218+ }
219+ hrList := & gatewayv1.HTTPRouteList {}
220+ if err := r .List (ctx , hrList , client.MatchingFields {
221+ indexer .ParentRefs : indexer .GenIndexKey (gateway .Namespace , gateway .Name ),
222+ }); err != nil {
223+ r .Log .Error (err , "failed to list httproutes by gateway" , "gateway" , gateway .Name )
224+ return nil
225+ }
226+ requests := make ([]reconcile.Request , 0 , len (hrList .Items ))
227+ for _ , hr := range hrList .Items {
228+ requests = append (requests , reconcile.Request {
229+ NamespacedName : client.ObjectKey {
230+ Namespace : hr .Namespace ,
231+ Name : hr .Name ,
232+ },
233+ })
234+ }
235+ return requests
236+ }
237+
193238func (r * HTTPRouteReconciler ) processHTTPRouteBackendRefs (tctx * provider.TranslateContext ) error {
194239 var terr error
195240 for _ , backend := range tctx .BackendRefs {
0 commit comments