From f1da0d96c8d44a39bcefabcae32f6de3945aca9e 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 --- .../clusterextension_controller.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/internal/controllers/clusterextension_controller.go b/internal/controllers/clusterextension_controller.go index b71baaf2c..d85f3586d 100644 --- a/internal/controllers/clusterextension_controller.go +++ b/internal/controllers/clusterextension_controller.go @@ -32,8 +32,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" @@ -409,6 +411,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)