From d66bdc635081217a147dddf39ec9463ad874f742 Mon Sep 17 00:00:00 2001 From: Austin Kuo Date: Thu, 14 Mar 2024 17:52:10 -0700 Subject: [PATCH 1/3] add predicate --- .../framework/controller/predicate/gatewayclass.go | 14 ++++++++++++++ .../controller/predicate/gatewayclass_test.go | 2 ++ 2 files changed, 16 insertions(+) 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..b42687dbf0 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,5 @@ 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: gc2})).To(BeFalse()) } From 77c6c5ceac7215a3d0ea0b64e9e5a7fb32b3ea20 Mon Sep 17 00:00:00 2001 From: Austin Kuo Date: Sat, 16 Mar 2024 19:39:10 -0700 Subject: [PATCH 2/3] address comments --- internal/framework/controller/predicate/gatewayclass_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/framework/controller/predicate/gatewayclass_test.go b/internal/framework/controller/predicate/gatewayclass_test.go index b42687dbf0..dad498ecad 100644 --- a/internal/framework/controller/predicate/gatewayclass_test.go +++ b/internal/framework/controller/predicate/gatewayclass_test.go @@ -32,5 +32,6 @@ 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()) } From 3c0399d74128c8f308342f59949d55a1f4513f9e Mon Sep 17 00:00:00 2001 From: Austin Kuo Date: Fri, 29 Mar 2024 19:24:58 -0700 Subject: [PATCH 3/3] fixes --- internal/framework/controller/predicate/gatewayclass_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/framework/controller/predicate/gatewayclass_test.go b/internal/framework/controller/predicate/gatewayclass_test.go index dad498ecad..e89d974f00 100644 --- a/internal/framework/controller/predicate/gatewayclass_test.go +++ b/internal/framework/controller/predicate/gatewayclass_test.go @@ -34,4 +34,5 @@ func TestGatewayClassPredicate(t *testing.T) { 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()) }