Skip to content

Commit

Permalink
[Fix] Fix constant reconciles due to Catalog
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
varshaprasad96 committed May 2, 2024
1 parent 79d64e8 commit 22962fd
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions internal/controllers/clusterextension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.Ref != newObject.Status.ResolvedSource.Image.Ref
}
}
return true
},
}).
Owns(&rukpakv1alpha2.BundleDeployment{}).
Complete(r)

Expand Down

0 comments on commit 22962fd

Please sign in to comment.