From 1198e2f8edb09210cd5b59c5c5d1fba88a616347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Mac=C3=ADk?= Date: Fri, 5 Jul 2024 15:30:31 +0200 Subject: [PATCH] fix(RHIDP-2920): switch Secret and ConfigMap watches to WatchMetadata to reduce memory consumption (#396) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel MacĂ­k --- controllers/backstage_controller.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/controllers/backstage_controller.go b/controllers/backstage_controller.go index f3957bb6..115f8960 100644 --- a/controllers/backstage_controller.go +++ b/controllers/backstage_controller.go @@ -354,10 +354,24 @@ func (r *BackstageReconciler) SetupWithManager(mgr ctrl.Manager) error { return fmt.Errorf("failed to construct the predicate for matching secrets. This should not happen: %w", err) } + secretMeta := &metav1.PartialObjectMetadata{} + secretMeta.SetGroupVersionKind(schema.GroupVersionKind{ + Group: "", + Version: "v1", + Kind: "Secret", + }) + + configMapMeta := &metav1.PartialObjectMetadata{} + configMapMeta.SetGroupVersionKind(schema.GroupVersionKind{ + Group: "", + Version: "v1", + Kind: "ConfigMap", + }) + b := ctrl.NewControllerManagedBy(mgr). For(&bs.Backstage{}). - Watches( - &corev1.Secret{}, + WatchesMetadata( + secretMeta, handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request { return r.requestByLabel(ctx, o) }), @@ -367,8 +381,8 @@ func (r *BackstageReconciler) SetupWithManager(mgr ctrl.Manager) error { //CreateFunc: func(e event.CreateEvent) bool { return true }, }), ). - Watches( - &corev1.ConfigMap{}, + WatchesMetadata( + configMapMeta, handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request { return r.requestByLabel(ctx, o) }),