@@ -37,6 +37,7 @@ import (
3737 gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3838
3939 "github.com/apache/apisix-ingress-controller/api/v1alpha1"
40+ "github.com/apache/apisix-ingress-controller/internal/controller/config"
4041 "github.com/apache/apisix-ingress-controller/internal/controller/indexer"
4142 "github.com/apache/apisix-ingress-controller/internal/provider"
4243 "github.com/apache/apisix-ingress-controller/internal/utils"
@@ -154,9 +155,24 @@ func (r *GatewayProxyController) Reconcile(ctx context.Context, req ctrl.Request
154155 r .Log .Error (err , "failed to list GatewayList" )
155156 return ctrl.Result {}, nil
156157 }
158+ var gatewayclassList gatewayv1.GatewayClassList
159+ if err := r .List (ctx , & gatewayclassList , client.MatchingFields {indexer .ControllerName : config .GetControllerName ()}); err != nil {
160+ r .Log .Error (err , "failed to list GatewayClassList" )
161+ return ctrl.Result {}, nil
162+ }
163+ gcMatched := make (map [string ]* gatewayv1.GatewayClass )
164+ for _ , item := range gatewayclassList .Items {
165+ gcMatched [item .Name ] = & item
166+ }
157167 // append referrers to translate context
158168 for _ , item := range gatewayList .Items {
159- tctx .GatewayProxyReferrers [req .NamespacedName ] = append (tctx .GatewayProxyReferrers [req .NamespacedName ], utils .NamespacedNameKind (& item ))
169+ gcName := string (item .Spec .GatewayClassName )
170+ if gcName == "" {
171+ continue
172+ }
173+ if _ , ok := gcMatched [gcName ]; ok {
174+ tctx .GatewayProxyReferrers [req .NamespacedName ] = append (tctx .GatewayProxyReferrers [req .NamespacedName ], utils .NamespacedNameKind (& item ))
175+ }
160176 }
161177 }
162178
@@ -170,6 +186,9 @@ func (r *GatewayProxyController) Reconcile(ctx context.Context, req ctrl.Request
170186 }
171187
172188 for _ , item := range ingressClassList .Items {
189+ if item .Spec .Controller != config .GetControllerName () {
190+ continue
191+ }
173192 tctx .GatewayProxyReferrers [req .NamespacedName ] = append (tctx .GatewayProxyReferrers [req .NamespacedName ], utils .NamespacedNameKind (& item ))
174193 }
175194 default :
@@ -181,9 +200,15 @@ func (r *GatewayProxyController) Reconcile(ctx context.Context, req ctrl.Request
181200 }
182201
183202 for _ , item := range ingressClassList .Items {
203+ if item .Spec .Controller != config .GetControllerName () {
204+ continue
205+ }
184206 tctx .GatewayProxyReferrers [req .NamespacedName ] = append (tctx .GatewayProxyReferrers [req .NamespacedName ], utils .NamespacedNameKind (& item ))
185207 }
186208 }
209+ if len (tctx .GatewayProxyReferrers [req .NamespacedName ]) == 0 {
210+ return ctrl.Result {}, nil
211+ }
187212
188213 if err := r .Provider .Update (ctx , tctx , & gp ); err != nil {
189214 return reconcile.Result {}, err
0 commit comments