From 11843c925098e0431116d77105ad829b37ba9830 Mon Sep 17 00:00:00 2001 From: Varsha Date: Fri, 3 May 2024 11:42:41 -0700 Subject: [PATCH] [Fix] Fix constant reconciles due to Catalog (#812) 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 --- .../clusterextension_controller.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/controllers/clusterextension_controller.go b/internal/controllers/clusterextension_controller.go index 75109a228..45298ec85 100644 --- a/internal/controllers/clusterextension_controller.go +++ b/internal/controllers/clusterextension_controller.go @@ -35,8 +35,10 @@ 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" catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1" @@ -469,6 +471,23 @@ 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.(*catalogd.Catalog) + newObject, isNewCatalog := ue.ObjectNew.(*catalogd.Catalog) + + if !isOldCatalog || !isNewCatalog { + return true + } + + if oldObject.Status.ResolvedSource != nil && newObject.Status.ResolvedSource != nil { + if oldObject.Status.ResolvedSource.Image != nil && newObject.Status.ResolvedSource.Image != nil { + return oldObject.Status.ResolvedSource.Image.ResolvedRef != newObject.Status.ResolvedSource.Image.ResolvedRef + } + } + return true + }, + }). Owns(&rukpakv1alpha2.BundleDeployment{}). Complete(r)