Skip to content

Commit

Permalink
controller: add delete event filter for vpc
Browse files Browse the repository at this point in the history
Updates the `LinodeVPCReconciler` to ignore self-generated delete events.
  • Loading branch information
cbang-akamai committed Feb 9, 2024
1 parent 1b008f0 commit 3e4b62d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions controller/linodevpc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 3e4b62d

Please sign in to comment.