@@ -352,19 +352,45 @@ func (r *ApisixRouteReconciler) listApisixRoutesForSecret(ctx context.Context, o
352352 }
353353
354354 var (
355- arList apiv2.ApisixRouteList
355+ arList apiv2.ApisixRouteList
356+ pcList apiv2.ApisixPluginConfigList
357+ allRequests = make ([]reconcile.Request , 0 )
356358 )
359+
360+ // First, find ApisixRoutes that directly reference this secret
357361 if err := r .List (ctx , & arList , client.MatchingFields {
358362 indexer .SecretIndexRef : indexer .GenIndexKey (secret .GetNamespace (), secret .GetName ()),
359363 }); err != nil {
360364 r .Log .Error (err , "failed to list apisixroutes by secret" , "secret" , secret .Name )
361365 return nil
362366 }
363- requests := make ([]reconcile.Request , 0 , len (arList .Items ))
364367 for _ , ar := range arList .Items {
365- requests = append (requests , reconcile.Request {NamespacedName : utils .NamespacedName (& ar )})
368+ allRequests = append (allRequests , reconcile.Request {NamespacedName : utils .NamespacedName (& ar )})
366369 }
367- return pkgutils .DedupComparable (requests )
370+
371+ // Second, find ApisixPluginConfigs that reference this secret
372+ if err := r .List (ctx , & pcList , client.MatchingFields {
373+ indexer .SecretIndexRef : indexer .GenIndexKey (secret .GetNamespace (), secret .GetName ()),
374+ }); err != nil {
375+ r .Log .Error (err , "failed to list apisixpluginconfigs by secret" , "secret" , secret .Name )
376+ return nil
377+ }
378+
379+ // Then find ApisixRoutes that reference these PluginConfigs
380+ for _ , pc := range pcList .Items {
381+ var arListForPC apiv2.ApisixRouteList
382+ if err := r .List (ctx , & arListForPC , client.MatchingFields {
383+ indexer .PluginConfigIndexRef : indexer .GenIndexKey (pc .GetNamespace (), pc .GetName ()),
384+ }); err != nil {
385+ r .Log .Error (err , "failed to list apisixroutes by plugin config" , "pluginconfig" , pc .Name )
386+ continue
387+ }
388+ for _ , ar := range arListForPC .Items {
389+ allRequests = append (allRequests , reconcile.Request {NamespacedName : utils .NamespacedName (& ar )})
390+ }
391+ }
392+
393+ return pkgutils .DedupComparable (allRequests )
368394}
369395
370396func (r * ApisixRouteReconciler ) listApiRouteForIngressClass (ctx context.Context , object client.Object ) (requests []reconcile.Request ) {
0 commit comments