@@ -36,30 +36,22 @@ type GatewayReconciler struct { //nolint:revive
3636 Provider provider.Provider
3737}
3838
39- func (r * GatewayReconciler ) setupIndexer (mgr ctrl.Manager ) error {
40- if err := mgr .GetFieldIndexer ().IndexField (
41- context .Background (),
42- & gatewayv1.Gateway {},
43- indexer .ParametersRef ,
44- indexer .GatewayParametersRefIndexFunc ,
45- ); err != nil {
46- return err
47- }
48- return nil
49- }
50-
5139// SetupWithManager sets up the controller with the Manager.
5240func (r * GatewayReconciler ) SetupWithManager (mgr ctrl.Manager ) error {
53- if err := r .setupIndexer (mgr ); err != nil {
54- return err
55- }
5641 return ctrl .NewControllerManagedBy (mgr ).
57- For (& gatewayv1.Gateway {}).
42+ For (
43+ & gatewayv1.Gateway {},
44+ builder .WithPredicates (
45+ predicate .NewPredicateFuncs (r .checkGatewayClass ),
46+ ),
47+ ).
5848 WithEventFilter (predicate.GenerationChangedPredicate {}).
5949 Watches (
6050 & gatewayv1.GatewayClass {},
6151 handler .EnqueueRequestsFromMapFunc (r .listGatewayForGatewayClass ),
62- builder .WithPredicates (predicate .NewPredicateFuncs (r .matchesGatewayClass )),
52+ builder .WithPredicates (
53+ predicate .NewPredicateFuncs (r .matchesGatewayClass ),
54+ ),
6355 ).
6456 Watches (
6557 & gatewayv1.HTTPRoute {},
@@ -90,11 +82,6 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
9082 }
9183 return ctrl.Result {}, err
9284 }
93- ns := gateway .GetNamespace ()
94- if ! r .checkGatewayClass (gateway ) {
95- return ctrl.Result {}, nil
96- }
97-
9885 conditionProgrammedStatus , conditionProgrammedMsg := true , "Programmed"
9986
10087 cfg := config .GetFirstGatewayConfig ()
@@ -126,8 +113,8 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
126113 tctx := & provider.TranslateContext {
127114 Secrets : make (map [types.NamespacedName ]* corev1.Secret ),
128115 }
129- r .processListenerConfig (tctx , gateway , ns )
130- if err := r .processInfrastructure (tctx , gateway , ns ); err != nil {
116+ r .processListenerConfig (tctx , gateway )
117+ if err := r .processInfrastructure (tctx , gateway ); err != nil {
131118 acceptStatus = status {
132119 status : false ,
133120 msg : err .Error (),
@@ -208,7 +195,8 @@ func (r *GatewayReconciler) listGatewayForGatewayClass(ctx context.Context, gate
208195 return reconcileGatewaysMatchGatewayClass (gatewayClass , gatewayList .Items )
209196}
210197
211- func (r * GatewayReconciler ) checkGatewayClass (gateway * gatewayv1.Gateway ) bool {
198+ func (r * GatewayReconciler ) checkGatewayClass (obj client.Object ) bool {
199+ gateway := obj .(* gatewayv1.Gateway )
212200 gatewayClass := & gatewayv1.GatewayClass {}
213201 if err := r .Client .Get (context .Background (), client.ObjectKey {Name : string (gateway .Spec .GatewayClassName )}, gatewayClass ); err != nil {
214202 r .Log .Error (err , "failed to get gateway class" , "gateway" , gateway .GetName (), "gatewayclass" , gateway .Spec .GatewayClassName )
@@ -281,12 +269,13 @@ func (r *GatewayReconciler) listGatewaysForHTTPRoute(_ context.Context, obj clie
281269 return recs
282270}
283271
284- func (r * GatewayReconciler ) processInfrastructure (tctx * provider.TranslateContext , gateway * gatewayv1.Gateway , ns string ) error {
272+ func (r * GatewayReconciler ) processInfrastructure (tctx * provider.TranslateContext , gateway * gatewayv1.Gateway ) error {
285273 infra := gateway .Spec .Infrastructure
286274 if infra == nil || infra .ParametersRef == nil {
287275 return nil
288276 }
289277
278+ ns := gateway .GetNamespace ()
290279 paramRef := infra .ParametersRef
291280 if string (paramRef .Group ) == v1alpha1 .GroupVersion .Group && string (paramRef .Kind ) == "GatewayProxy" {
292281 gatewayProxy := & v1alpha1.GatewayProxy {}
@@ -305,14 +294,15 @@ func (r *GatewayReconciler) processInfrastructure(tctx *provider.TranslateContex
305294 return nil
306295}
307296
308- func (r * GatewayReconciler ) processListenerConfig (tctx * provider.TranslateContext , gateway * gatewayv1.Gateway , ns string ) {
297+ func (r * GatewayReconciler ) processListenerConfig (tctx * provider.TranslateContext , gateway * gatewayv1.Gateway ) {
309298 listeners := gateway .Spec .Listeners
310299 for _ , listener := range listeners {
311300 if listener .TLS == nil || listener .TLS .CertificateRefs == nil {
312301 continue
313302 }
314303 secret := corev1.Secret {}
315304 for _ , ref := range listener .TLS .CertificateRefs {
305+ ns := gateway .GetNamespace ()
316306 if ref .Namespace != nil {
317307 ns = string (* ref .Namespace )
318308 }
0 commit comments