Skip to content

Commit

Permalink
core: do not watch resourceversion and heartbeat node updates
Browse files Browse the repository at this point in the history
currently node predicate watches for resourceversion and
heartbeat, which are not critical things so we should
look for the reconcile logic and unnecessary
increasing the predicate cache size,
So with the PR we will ignore conidering for a reconcile
of cephcluster if updates are not cruical

closes: #14070

Signed-off-by: parth-gr <paarora@redhat.com>
  • Loading branch information
parth-gr committed May 9, 2024
1 parent 5e3d623 commit bc98fea
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/operator/ceph/cluster/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,37 @@ import (
"context"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/clusterd"
discoverDaemon "github.com/rook/rook/pkg/daemon/discover"
"github.com/rook/rook/pkg/operator/ceph/controller"
"github.com/rook/rook/pkg/operator/k8sutil"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)

func compareNodes(objOld, objNew *corev1.Node) string {
// do not watch node if only resourceversion got changed
resourceQtyComparer := cmpopts.IgnoreFields(v1.ObjectMeta{}, "ResourceVersion")
diff := cmp.Diff(objOld.Spec, objNew.Spec, resourceQtyComparer)

// do not watch node if only resourceversion got changed
resourceQtyComparer = cmpopts.IgnoreFields(corev1.NodeCondition{}, "LastHeartbeatTime")
diff1 := cmp.Diff(objOld.Spec, objNew.Spec, resourceQtyComparer)

if diff == "" && diff1 == "" {
return diff
}
return "not-equal"
}

// predicateForNodeWatcher is the predicate function to trigger reconcile on Node events
func predicateForNodeWatcher(ctx context.Context, client client.Client, context *clusterd.Context) predicate.Funcs {
return predicate.Funcs{
Expand All @@ -43,6 +61,13 @@ func predicateForNodeWatcher(ctx context.Context, client client.Client, context
},

UpdateFunc: func(e event.UpdateEvent) bool {
objOld := e.ObjectOld.(*corev1.Node)
objNew := e.ObjectNew.(*corev1.Node)
diff := compareNodes(objOld, objNew)
if diff == "" {
return false
}

clientCluster := newClientCluster(client, e.ObjectNew.GetNamespace(), context)
return clientCluster.onK8sNode(ctx, e.ObjectNew)
},
Expand Down

0 comments on commit bc98fea

Please sign in to comment.