Skip to content

Commit

Permalink
Avoid reconciling AWSMachinePools when only the status field has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
fiunchinho committed Feb 4, 2025
1 parent cc12c52 commit 3f75244
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions exp/controllers/awsmachinepool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
Expand Down Expand Up @@ -199,6 +201,28 @@ func (r *AWSMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctr
handler.EnqueueRequestsFromMapFunc(machinePoolToInfrastructureMapFunc(expinfrav1.GroupVersion.WithKind("AWSMachinePool"))),
).
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(logger.FromContext(ctx).GetLogger(), r.WatchFilterValue)).
WithEventFilter(
predicate.Funcs{
// Avoid reconciling if the event triggering the reconciliation is related to incremental status updates
// for AWSMachinePool resources only
UpdateFunc: func(e event.UpdateEvent) bool {
if e.ObjectOld.GetObjectKind().GroupVersionKind().Kind != "AWSMachinePool" {
return true
}

oldCluster := e.ObjectOld.(*expinfrav1.AWSMachinePool).DeepCopy()
newCluster := e.ObjectNew.(*expinfrav1.AWSMachinePool).DeepCopy()

oldCluster.Status = expinfrav1.AWSMachinePoolStatus{}
newCluster.Status = expinfrav1.AWSMachinePoolStatus{}

oldCluster.ObjectMeta.ResourceVersion = ""
newCluster.ObjectMeta.ResourceVersion = ""

return !cmp.Equal(oldCluster, newCluster)
},
},
).
Complete(r)
}

Expand Down

0 comments on commit 3f75244

Please sign in to comment.