Skip to content

Commit 22962fd

Browse files
[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 <[email protected]>
1 parent 79d64e8 commit 22962fd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

internal/controllers/clusterextension_controller.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ import (
3232
"k8s.io/utils/ptr"
3333
ctrl "sigs.k8s.io/controller-runtime"
3434
"sigs.k8s.io/controller-runtime/pkg/client"
35+
"sigs.k8s.io/controller-runtime/pkg/event"
3536
"sigs.k8s.io/controller-runtime/pkg/handler"
3637
"sigs.k8s.io/controller-runtime/pkg/log"
38+
"sigs.k8s.io/controller-runtime/pkg/predicate"
3739
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3840

3941
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
@@ -409,6 +411,23 @@ func (r *ClusterExtensionReconciler) SetupWithManager(mgr ctrl.Manager) error {
409411
For(&ocv1alpha1.ClusterExtension{}).
410412
Watches(&catalogd.Catalog{},
411413
handler.EnqueueRequestsFromMapFunc(clusterExtensionRequestsForCatalog(mgr.GetClient(), mgr.GetLogger()))).
414+
WithEventFilter(predicate.Funcs{
415+
UpdateFunc: func(ue event.UpdateEvent) bool {
416+
oldObject, isOldCatalog := ue.ObjectOld.(*catalogd.Catalog)
417+
newObject, isNewCatalog := ue.ObjectNew.(*catalogd.Catalog)
418+
419+
if !isOldCatalog || !isNewCatalog {
420+
return true
421+
}
422+
423+
if oldObject.Status.ResolvedSource != nil && newObject.Status.ResolvedSource != nil {
424+
if oldObject.Status.ResolvedSource.Image != nil && newObject.Status.ResolvedSource.Image != nil {
425+
return oldObject.Status.ResolvedSource.Image.Ref != newObject.Status.ResolvedSource.Image.Ref
426+
}
427+
}
428+
return true
429+
},
430+
}).
412431
Owns(&rukpakv1alpha2.BundleDeployment{}).
413432
Complete(r)
414433

0 commit comments

Comments
 (0)