diff --git a/internal/framework/controller/predicate/gatewayclass.go b/internal/framework/controller/predicate/gatewayclass.go index 3e915b0117..bef910ed5b 100644 --- a/internal/framework/controller/predicate/gatewayclass.go +++ b/internal/framework/controller/predicate/gatewayclass.go @@ -45,3 +45,17 @@ func (gcp GatewayClassPredicate) Update(e event.UpdateEvent) bool { return false } + +// Delete implements default DeleteEvent filter for validating a GatewayClass controllerName. +func (gcp GatewayClassPredicate) Delete(e event.DeleteEvent) bool { + if e.Object == nil { + return false + } + + gc, ok := e.Object.(*v1.GatewayClass) + if !ok { + return false + } + + return string(gc.Spec.ControllerName) == gcp.ControllerName +} diff --git a/internal/framework/controller/predicate/gatewayclass_test.go b/internal/framework/controller/predicate/gatewayclass_test.go index be5c8c32c0..e89d974f00 100644 --- a/internal/framework/controller/predicate/gatewayclass_test.go +++ b/internal/framework/controller/predicate/gatewayclass_test.go @@ -21,6 +21,7 @@ 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()) + g.Expect(p.Delete(event.DeleteEvent{Object: gc})).To(BeTrue()) gc2 := &v1.GatewayClass{ Spec: v1.GatewayClassSpec{ @@ -31,4 +32,7 @@ func TestGatewayClassPredicate(t *testing.T) { g.Expect(p.Update(event.UpdateEvent{ObjectOld: gc, ObjectNew: gc2})).To(BeTrue()) g.Expect(p.Update(event.UpdateEvent{ObjectOld: gc2, ObjectNew: gc})).To(BeTrue()) g.Expect(p.Update(event.UpdateEvent{ObjectOld: gc2, ObjectNew: gc2})).To(BeFalse()) + g.Expect(p.Delete(event.DeleteEvent{Object: nil})).To(BeFalse()) + g.Expect(p.Delete(event.DeleteEvent{Object: gc2})).To(BeFalse()) + g.Expect(p.Delete(event.DeleteEvent{Object: &v1.HTTPRoute{}})).To(BeFalse()) }