Skip to content

Commit af59e6c

Browse files
authored
fix: gatewayproxy does not match controllername (#231)
1 parent c7a09b1 commit af59e6c

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

internal/controller/gatewayproxy_controller.go

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)