Skip to content

Commit

Permalink
Add delete predicate for gateway class (nginxinc#1696)
Browse files Browse the repository at this point in the history
Problem: The controller reconciles delete events for 
GatewayClasses that are not owned by NGF.

Solution: Add a delete function to the GatewayClass 
predicate that ignores delete events for GatewayClasses
with the wrong controller name.
  • Loading branch information
hckuo authored and amimimor committed Apr 3, 2024
1 parent d578c32 commit bf500ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/framework/controller/predicate/gatewayclass.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions internal/framework/controller/predicate/gatewayclass_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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())
}

0 comments on commit bf500ce

Please sign in to comment.