@@ -69,16 +69,19 @@ func (r *ApisixRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
6969 // Check and store EndpointSlice API support
7070 r .supportsEndpointSlice = pkgutils .HasAPIResource (mgr , & discoveryv1.EndpointSlice {})
7171
72+ eventFilters := []predicate.Predicate {
73+ predicate.GenerationChangedPredicate {},
74+ predicate.AnnotationChangedPredicate {},
75+ predicate .NewPredicateFuncs (TypePredicate [* corev1.Secret ]()),
76+ }
77+
78+ if ! r .supportsEndpointSlice {
79+ eventFilters = append (eventFilters , predicate .NewPredicateFuncs (TypePredicate [* corev1.Endpoints ]()))
80+ }
81+
7282 bdr := ctrl .NewControllerManagedBy (mgr ).
7383 For (& apiv2.ApisixRoute {}).
74- WithEventFilter (
75- predicate .Or (
76- predicate.GenerationChangedPredicate {},
77- predicate.AnnotationChangedPredicate {},
78- predicate .NewPredicateFuncs (TypePredicate [* corev1.Endpoints ]()),
79- predicate .NewPredicateFuncs (TypePredicate [* corev1.Secret ]()),
80- ),
81- ).
84+ WithEventFilter (predicate .Or (eventFilters ... )).
8285 Watches (
8386 & networkingv1.IngressClass {},
8487 handler .EnqueueRequestsFromMapFunc (r .listApisixRouteForIngressClass ),
@@ -91,16 +94,10 @@ func (r *ApisixRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
9194 )
9295
9396 // Conditionally watch EndpointSlice or Endpoints based on cluster API support
94- if r .supportsEndpointSlice {
95- bdr = bdr .Watches (& discoveryv1.EndpointSlice {},
96- handler .EnqueueRequestsFromMapFunc (r .listApisixRoutesForService ),
97- )
98- } else {
99- r .Log .Info ("EndpointSlice API not available, falling back to Endpoints API for service discovery" )
100- bdr = bdr .Watches (& corev1.Endpoints {},
101- handler .EnqueueRequestsFromMapFunc (r .listApisixRoutesForEndpoints ),
102- )
103- }
97+ bdr = watchEndpointSliceOrEndpoints (bdr , r .supportsEndpointSlice ,
98+ r .listApisixRoutesForService ,
99+ r .listApisixRoutesForEndpoints ,
100+ r .Log )
104101
105102 return bdr .
106103 Watches (& corev1.Secret {},
0 commit comments