@@ -17,6 +17,7 @@ import (
17
17
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
18
18
19
19
"github.com/api7/api7-ingress-controller/internal/controller/config"
20
+ "github.com/api7/api7-ingress-controller/internal/controller/indexer"
20
21
)
21
22
22
23
const (
@@ -61,20 +62,18 @@ func (r *GatewayClassReconciler) Reconcile(ctx context.Context, req ctrl.Request
61
62
} else {
62
63
if controllerutil .ContainsFinalizer (gc , FinalizerGatewayClassProtection ) {
63
64
var gatewayList gatewayv1.GatewayList
64
- if err := r .List (ctx , & gatewayList ); err != nil {
65
+ if err := r .List (ctx , & gatewayList , client. MatchingFields { indexer . GatewayClassIndexRef : gc . Name } ); err != nil {
65
66
r .Log .Error (err , "failed to list gateways" )
66
67
return ctrl.Result {}, err
67
68
}
68
- var gateways []types. NamespacedName
69
- for _ , gateway := range gatewayList . Items {
70
- if string ( gateway . Spec . GatewayClassName ) == gc . GetName () {
69
+ if len ( gatewayList . Items ) > 0 {
70
+ var gateways []types. NamespacedName
71
+ for _ , item := range gatewayList . Items {
71
72
gateways = append (gateways , types.NamespacedName {
72
- Namespace : gateway .GetNamespace (),
73
- Name : gateway .GetName (),
73
+ Namespace : item .GetNamespace (),
74
+ Name : item .GetName (),
74
75
})
75
76
}
76
- }
77
- if len (gateways ) > 0 {
78
77
r .Eventf (gc , "Warning" , "DeletionBlocked" , "the GatewayClass is still used by Gateways: %v" , gateways )
79
78
return ctrl.Result {RequeueAfter : 5 * time .Second }, nil
80
79
} else {
0 commit comments