Skip to content

Commit 11843c9

Browse files
[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 <varshaprasad96@gmail.com>
1 parent 4383624 commit 11843c9

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

internal/controllers/clusterextension_controller.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ import (
3535
"k8s.io/utils/ptr"
3636
ctrl "sigs.k8s.io/controller-runtime"
3737
"sigs.k8s.io/controller-runtime/pkg/client"
38+
"sigs.k8s.io/controller-runtime/pkg/event"
3839
"sigs.k8s.io/controller-runtime/pkg/handler"
3940
"sigs.k8s.io/controller-runtime/pkg/log"
41+
"sigs.k8s.io/controller-runtime/pkg/predicate"
4042
"sigs.k8s.io/controller-runtime/pkg/reconcile"
4143

4244
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
@@ -469,6 +471,23 @@ func (r *ClusterExtensionReconciler) SetupWithManager(mgr ctrl.Manager) error {
469471
For(&ocv1alpha1.ClusterExtension{}).
470472
Watches(&catalogd.Catalog{},
471473
handler.EnqueueRequestsFromMapFunc(clusterExtensionRequestsForCatalog(mgr.GetClient(), mgr.GetLogger()))).
474+
WithEventFilter(predicate.Funcs{
475+
UpdateFunc: func(ue event.UpdateEvent) bool {
476+
oldObject, isOldCatalog := ue.ObjectOld.(*catalogd.Catalog)
477+
newObject, isNewCatalog := ue.ObjectNew.(*catalogd.Catalog)
478+
479+
if !isOldCatalog || !isNewCatalog {
480+
return true
481+
}
482+
483+
if oldObject.Status.ResolvedSource != nil && newObject.Status.ResolvedSource != nil {
484+
if oldObject.Status.ResolvedSource.Image != nil && newObject.Status.ResolvedSource.Image != nil {
485+
return oldObject.Status.ResolvedSource.Image.ResolvedRef != newObject.Status.ResolvedSource.Image.ResolvedRef
486+
}
487+
}
488+
return true
489+
},
490+
}).
472491
Owns(&rukpakv1alpha2.BundleDeployment{}).
473492
Complete(r)
474493

0 commit comments

Comments
 (0)