Skip to content

Commit dcea94f

Browse files
authoredFeb 5, 2025··
Merge pull request #5333 from giantswarm/filter-unnecesary-events
✨ Avoid reconciling AWSMachinePools when only the status field has changed
2 parents 051284c + 3f75244 commit dcea94f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
 

‎exp/controllers/awsmachinepool_controller.go

+24
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ import (
3434
"sigs.k8s.io/controller-runtime/pkg/client"
3535
"sigs.k8s.io/controller-runtime/pkg/controller"
3636
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
37+
"sigs.k8s.io/controller-runtime/pkg/event"
3738
"sigs.k8s.io/controller-runtime/pkg/handler"
39+
"sigs.k8s.io/controller-runtime/pkg/predicate"
3840
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3941

4042
infrav1 "sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2"
@@ -199,6 +201,28 @@ func (r *AWSMachinePoolReconciler) SetupWithManager(ctx context.Context, mgr ctr
199201
handler.EnqueueRequestsFromMapFunc(machinePoolToInfrastructureMapFunc(expinfrav1.GroupVersion.WithKind("AWSMachinePool"))),
200202
).
201203
WithEventFilter(predicates.ResourceNotPausedAndHasFilterLabel(logger.FromContext(ctx).GetLogger(), r.WatchFilterValue)).
204+
WithEventFilter(
205+
predicate.Funcs{
206+
// Avoid reconciling if the event triggering the reconciliation is related to incremental status updates
207+
// for AWSMachinePool resources only
208+
UpdateFunc: func(e event.UpdateEvent) bool {
209+
if e.ObjectOld.GetObjectKind().GroupVersionKind().Kind != "AWSMachinePool" {
210+
return true
211+
}
212+
213+
oldCluster := e.ObjectOld.(*expinfrav1.AWSMachinePool).DeepCopy()
214+
newCluster := e.ObjectNew.(*expinfrav1.AWSMachinePool).DeepCopy()
215+
216+
oldCluster.Status = expinfrav1.AWSMachinePoolStatus{}
217+
newCluster.Status = expinfrav1.AWSMachinePoolStatus{}
218+
219+
oldCluster.ObjectMeta.ResourceVersion = ""
220+
newCluster.ObjectMeta.ResourceVersion = ""
221+
222+
return !cmp.Equal(oldCluster, newCluster)
223+
},
224+
},
225+
).
202226
Complete(r)
203227
}
204228

0 commit comments

Comments
 (0)
Please sign in to comment.