From 8c2f06c91bfe14fa0b36cd1c63a6677ae36c9fb2 Mon Sep 17 00:00:00 2001 From: Varsha Prasad Narsing Date: Wed, 1 May 2024 16:20:12 -0700 Subject: [PATCH] [Fix] Fix constant reconciles due to Catalog Due to the polling feature in the Catalog, the `lastPolledInterval` in the Catalog's status gets updated. Because of this there is a reconcile is trigrred every time the catalog is polled, even though there is no change in the resolved image ref SHA. This causes unnecessary continuous reconciles in the CE. To overcome this, a Predicate is added to accept update events only when there is a change in Resolved reference. Signed-off-by: Varsha Prasad Narsing --- .../controllers/clusterextension_controller.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/controllers/clusterextension_controller.go b/internal/controllers/clusterextension_controller.go index b71baaf2c..885556d96 100644 --- a/internal/controllers/clusterextension_controller.go +++ b/internal/controllers/clusterextension_controller.go @@ -32,10 +32,13 @@ import ( "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" + "sigs.k8s.io/controller-runtime/pkg/predicate" "sigs.k8s.io/controller-runtime/pkg/reconcile" + "github.com/operator-framework/catalogd/api/core/v1alpha1" catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1" "github.com/operator-framework/deppy/pkg/deppy" "github.com/operator-framework/deppy/pkg/deppy/solver" @@ -409,6 +412,17 @@ func (r *ClusterExtensionReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&ocv1alpha1.ClusterExtension{}). Watches(&catalogd.Catalog{}, handler.EnqueueRequestsFromMapFunc(clusterExtensionRequestsForCatalog(mgr.GetClient(), mgr.GetLogger()))). + WithEventFilter(predicate.Funcs{ + UpdateFunc: func(ue event.UpdateEvent) bool { + oldObject, isOldCatalog := ue.ObjectOld.(*v1alpha1.Catalog) + newObject, isNewCatalog := ue.ObjectNew.(*v1alpha1.Catalog) + + if !isOldCatalog || !isNewCatalog { + return true + } + return oldObject.Status.ResolvedSource.Image.Ref != newObject.Status.ResolvedSource.Image.Ref + }, + }). Owns(&rukpakv1alpha2.BundleDeployment{}). Complete(r)