From 3e4b62d868f3866836fdaa6b534f741862b1ea7e Mon Sep 17 00:00:00 2001 From: Cindy Bang Date: Thu, 8 Feb 2024 09:30:02 -0500 Subject: [PATCH] controller: add delete event filter for vpc Updates the `LinodeVPCReconciler` to ignore self-generated delete events. --- controller/linodevpc_controller.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/controller/linodevpc_controller.go b/controller/linodevpc_controller.go index 12dac4dec..b5bf8ca12 100644 --- a/controller/linodevpc_controller.go +++ b/controller/linodevpc_controller.go @@ -34,6 +34,8 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/event" + "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" "github.com/go-logr/logr" @@ -260,8 +262,16 @@ func (r *LinodeVPCReconciler) reconcileDelete(ctx context.Context, logger logr.L func (r *LinodeVPCReconciler) SetupWithManager(mgr ctrl.Manager) error { _, err := ctrl.NewControllerManagedBy(mgr). For(&infrav1alpha1.LinodeVPC{}). - WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetLogger(), r.WatchFilterValue)). - Build(r) + WithEventFilter( + predicate.And( + // Filter for objects with a specific WatchLabel. + predicates.ResourceNotPausedAndHasFilterLabel(mgr.GetLogger(), r.WatchFilterValue), + // Do not reconcile the Delete events generated by the + // controller itself. + predicate.Funcs{ + DeleteFunc: func(e event.DeleteEvent) bool { return false }, + }, + )).Build(r) if err != nil { return fmt.Errorf("failed to build controller: %w", err) }