Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set GatewayClass status for ignored GatewayClasses #804

Merged
merged 5 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/events/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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 @@ -48,6 +49,8 @@ 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 @@ -121,7 +124,11 @@ func (h *EventHandlerImpl) updateNginx(ctx context.Context, conf dataplane.Confi
func (h *EventHandlerImpl) propagateUpsert(e *UpsertEvent) {
switch r := e.Resource.(type) {
case *v1beta1.GatewayClass:
h.cfg.Processor.CaptureUpsertChange(r)
if string(r.Spec.ControllerName) != h.cfg.ControllerName {
sjberman marked this conversation as resolved.
Show resolved Hide resolved
h.cfg.Processor.CaptureDeleteChange(r, client.ObjectKeyFromObject(r))
} else {
h.cfg.Processor.CaptureUpsertChange(r)
}
case *v1beta1.Gateway:
h.cfg.Processor.CaptureUpsertChange(r)
case *v1beta1.HTTPRoute:
Expand Down
1 change: 1 addition & 0 deletions internal/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func Start(cfg config.Config) error {
NginxFileMgr: nginxFileMgr,
NginxRuntimeMgr: nginxRuntimeMgr,
StatusUpdater: statusUpdater,
ControllerName: cfg.GatewayCtlrName,
})

objects, objectLists := prepareFirstEventBatchPreparerArgs(cfg.GatewayClassName, cfg.GatewayNsName)
Expand Down
17 changes: 11 additions & 6 deletions internal/manager/predicate/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@ func (gcp GatewayClassPredicate) Create(e event.CreateEvent) bool {

// Update implements default UpdateEvent filter for validating a GatewayClass controllerName.
func (gcp GatewayClassPredicate) Update(e event.UpdateEvent) bool {
if e.ObjectNew == nil {
return false
if e.ObjectOld != nil {
gcOld, ok := e.ObjectOld.(*v1beta1.GatewayClass)
if ok {
return string(gcOld.Spec.ControllerName) == gcp.ControllerName
}
}

gc, ok := e.ObjectNew.(*v1beta1.GatewayClass)
if !ok {
return false
if e.ObjectNew != nil {
gcNew, ok := e.ObjectNew.(*v1beta1.GatewayClass)
if ok {
return string(gcNew.Spec.ControllerName) == gcp.ControllerName
}
}

return string(gc.Spec.ControllerName) == gcp.ControllerName
return false
sjberman marked this conversation as resolved.
Show resolved Hide resolved
}
10 changes: 7 additions & 3 deletions internal/manager/predicate/gatewayclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ func TestGatewayClassPredicate(t *testing.T) {
g.Expect(p.Create(event.CreateEvent{Object: gc})).To(BeTrue())
g.Expect(p.Update(event.UpdateEvent{ObjectNew: gc})).To(BeTrue())

gc.Spec.ControllerName = "unknown"
g.Expect(p.Create(event.CreateEvent{Object: gc})).To(BeFalse())
g.Expect(p.Update(event.UpdateEvent{ObjectNew: gc})).To(BeFalse())
gc2 := &v1beta1.GatewayClass{
Spec: v1beta1.GatewayClassSpec{
ControllerName: "unknown",
},
}
g.Expect(p.Create(event.CreateEvent{Object: gc2})).To(BeFalse())
g.Expect(p.Update(event.UpdateEvent{ObjectOld: gc, ObjectNew: gc2})).To(BeTrue())
}
2 changes: 1 addition & 1 deletion internal/state/graph/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type processedGatewayClasses struct {
// processGatewayClasses returns the "Winner" GatewayClass, which is defined in
// the command-line argument and references this controller, and a list of "Ignored" GatewayClasses
// that reference this controller, but are not named in the command-line argument.
// Also returns a boolean that says whether or not the GatewayClasa defined
// Also returns a boolean that says whether or not the GatewayClass defined
// in the command-line argument exists, regardless of which controller it references.
func processGatewayClasses(
gcs map[types.NamespacedName]*v1beta1.GatewayClass,
Expand Down