From e8d94632f94be1506a5167596d51ecf59ad05291 Mon Sep 17 00:00:00 2001 From: Saylor Berman Date: Fri, 30 Jun 2023 11:58:40 -0600 Subject: [PATCH] Code review --- internal/events/handler.go | 9 +-------- internal/manager/manager.go | 1 - internal/manager/predicate/gatewayclass.go | 8 ++++---- internal/manager/predicate/gatewayclass_test.go | 1 + 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/internal/events/handler.go b/internal/events/handler.go index 6bbfc90f76..f324d09658 100644 --- a/internal/events/handler.go +++ b/internal/events/handler.go @@ -7,7 +7,6 @@ import ( "github.com/go-logr/logr" apiv1 "k8s.io/api/core/v1" discoveryV1 "k8s.io/api/discovery/v1" - "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/gateway-api/apis/v1beta1" "github.com/nginxinc/nginx-kubernetes-gateway/internal/nginx/config" @@ -49,8 +48,6 @@ type EventHandlerConfig struct { StatusUpdater status.Updater // Logger is the logger to be used by the EventHandler. Logger logr.Logger - // ControllerName is the name of this controller. - ControllerName string } // EventHandlerImpl implements EventHandler. @@ -124,11 +121,7 @@ func (h *EventHandlerImpl) updateNginx(ctx context.Context, conf dataplane.Confi func (h *EventHandlerImpl) propagateUpsert(e *UpsertEvent) { switch r := e.Resource.(type) { case *v1beta1.GatewayClass: - if string(r.Spec.ControllerName) != h.cfg.ControllerName { - h.cfg.Processor.CaptureDeleteChange(r, client.ObjectKeyFromObject(r)) - } else { - h.cfg.Processor.CaptureUpsertChange(r) - } + h.cfg.Processor.CaptureUpsertChange(r) case *v1beta1.Gateway: h.cfg.Processor.CaptureUpsertChange(r) case *v1beta1.HTTPRoute: diff --git a/internal/manager/manager.go b/internal/manager/manager.go index 34ba05a604..994e0e40a2 100644 --- a/internal/manager/manager.go +++ b/internal/manager/manager.go @@ -175,7 +175,6 @@ func Start(cfg config.Config) error { NginxFileMgr: nginxFileMgr, NginxRuntimeMgr: nginxRuntimeMgr, StatusUpdater: statusUpdater, - ControllerName: cfg.GatewayCtlrName, }) objects, objectLists := prepareFirstEventBatchPreparerArgs(cfg.GatewayClassName, cfg.GatewayNsName) diff --git a/internal/manager/predicate/gatewayclass.go b/internal/manager/predicate/gatewayclass.go index 56a792d259..1a69d86d2a 100644 --- a/internal/manager/predicate/gatewayclass.go +++ b/internal/manager/predicate/gatewayclass.go @@ -31,15 +31,15 @@ func (gcp GatewayClassPredicate) Create(e event.CreateEvent) bool { func (gcp GatewayClassPredicate) Update(e event.UpdateEvent) bool { if e.ObjectOld != nil { gcOld, ok := e.ObjectOld.(*v1beta1.GatewayClass) - if ok { - return string(gcOld.Spec.ControllerName) == gcp.ControllerName + if ok && string(gcOld.Spec.ControllerName) == gcp.ControllerName { + return true } } if e.ObjectNew != nil { gcNew, ok := e.ObjectNew.(*v1beta1.GatewayClass) - if ok { - return string(gcNew.Spec.ControllerName) == gcp.ControllerName + if ok && string(gcNew.Spec.ControllerName) == gcp.ControllerName { + return true } } diff --git a/internal/manager/predicate/gatewayclass_test.go b/internal/manager/predicate/gatewayclass_test.go index febcdc0089..b56f530af7 100644 --- a/internal/manager/predicate/gatewayclass_test.go +++ b/internal/manager/predicate/gatewayclass_test.go @@ -29,4 +29,5 @@ func TestGatewayClassPredicate(t *testing.T) { } g.Expect(p.Create(event.CreateEvent{Object: gc2})).To(BeFalse()) g.Expect(p.Update(event.UpdateEvent{ObjectOld: gc, ObjectNew: gc2})).To(BeTrue()) + g.Expect(p.Update(event.UpdateEvent{ObjectOld: gc2, ObjectNew: gc})).To(BeTrue()) }