From 2561a5d15259f475100be827046439a80843a9bf Mon Sep 17 00:00:00 2001 From: Philipp Eberle Date: Thu, 24 Oct 2024 15:05:48 +0200 Subject: [PATCH] Finally filter for partition id when watching postgres resources --- controllers/postgres_controller.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/controllers/postgres_controller.go b/controllers/postgres_controller.go index 15c92999..0c0f27cd 100644 --- a/controllers/postgres_controller.go +++ b/controllers/postgres_controller.go @@ -356,9 +356,22 @@ func (r *PostgresReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c // SetupWithManager informs mgr when this reconciler should be called. func (r *PostgresReconciler) SetupWithManager(mgr ctrl.Manager) error { r.recorder = mgr.GetEventRecorderFor("PostgresController") + + l := map[string]string{ + pg.PartitionIDLabelName: r.PartitionID, + } + s := metav1.LabelSelector{ + MatchLabels: l, + } + lsp, err := predicate.LabelSelectorPredicate(s) + if err != nil { + return fmt.Errorf("failed to create LabelSelectorPredicate: %w", err) + } + return ctrl.NewControllerManagedBy(mgr). For(&pg.Postgres{}). WithEventFilter(predicate.GenerationChangedPredicate{}). + WithEventFilter(lsp). Complete(r) }