Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
sjberman committed Jun 30, 2023
1 parent 9c677a9 commit e8d9463
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
9 changes: 1 addition & 8 deletions internal/events/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions internal/manager/predicate/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/manager/predicate/gatewayclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

0 comments on commit e8d9463

Please sign in to comment.