Skip to content

Commit e8da0ca

Browse files
committed
resolve comments
1 parent bdb2058 commit e8da0ca

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

internal/controller/gateway_controller.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type GatewayReconciler struct { //nolint:revive
4949

5050
// SetupWithManager sets up the controller with the Manager.
5151
func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
52-
return ctrl.NewControllerManagedBy(mgr).
52+
bdr := ctrl.NewControllerManagedBy(mgr).
5353
For(
5454
&gatewayv1.Gateway{},
5555
builder.WithPredicates(
@@ -83,12 +83,16 @@ func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
8383
Watches(
8484
&corev1.Secret{},
8585
handler.EnqueueRequestsFromMapFunc(r.listGatewaysForSecret),
86-
).
87-
Watches(&v1beta1.ReferenceGrant{},
86+
)
87+
88+
if GetEnableReferenceGrant() {
89+
bdr.Watches(&v1beta1.ReferenceGrant{},
8890
handler.EnqueueRequestsFromMapFunc(r.listReferenceGrantsForGateway),
8991
builder.WithPredicates(referenceGrantPredicates(KindGateway)),
90-
).
91-
Complete(r)
92+
)
93+
}
94+
95+
return bdr.Complete(r)
9296
}
9397

9498
func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

internal/controller/httproute_controller.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type HTTPRouteReconciler struct { //nolint:revive
6161
func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
6262
r.genericEvent = make(chan event.GenericEvent, 100)
6363

64-
return ctrl.NewControllerManagedBy(mgr).
64+
bdr := ctrl.NewControllerManagedBy(mgr).
6565
For(&gatewayv1.HTTPRoute{}).
6666
WithEventFilter(predicate.GenerationChangedPredicate{}).
6767
Watches(&discoveryv1.EndpointSlice{},
@@ -102,17 +102,21 @@ func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
102102
Watches(&v1alpha1.GatewayProxy{},
103103
handler.EnqueueRequestsFromMapFunc(r.listHTTPRoutesForGatewayProxy),
104104
).
105-
Watches(&v1beta1.ReferenceGrant{},
106-
handler.EnqueueRequestsFromMapFunc(r.listHTTPRoutesForReferenceGrant),
107-
builder.WithPredicates(referenceGrantPredicates(KindHTTPRoute)),
108-
).
109105
WatchesRawSource(
110106
source.Channel(
111107
r.genericEvent,
112108
handler.EnqueueRequestsFromMapFunc(r.listHTTPRouteForGenericEvent),
113109
),
114-
).
115-
Complete(r)
110+
)
111+
112+
if GetEnableReferenceGrant() {
113+
bdr.Watches(&v1beta1.ReferenceGrant{},
114+
handler.EnqueueRequestsFromMapFunc(r.listHTTPRoutesForReferenceGrant),
115+
builder.WithPredicates(referenceGrantPredicates(KindHTTPRoute)),
116+
)
117+
}
118+
119+
return bdr.Complete(r)
116120
}
117121

118122
func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

0 commit comments

Comments
 (0)