@@ -70,8 +70,34 @@ func (r *Reconciler) reconcileNodeRefs(ctx context.Context, s *scope) (ctrl.Resu
7070 readyReplicas = mp .Status .Deprecated .V1Beta1 .ReadyReplicas
7171 }
7272 if ptr .Deref (mp .Status .Replicas , 0 ) == readyReplicas && len (mp .Status .NodeRefs ) == int (readyReplicas ) {
73- v1beta1conditions .MarkTrue (mp , clusterv1 .ReplicasReadyV1Beta1Condition )
74- return ctrl.Result {}, nil
73+ // Validate that the UIDs in NodeRefs are still valid
74+ if s .nodeRefMap != nil {
75+ // Create a name-to-node mapping for efficient lookup
76+ nodeNameMap := make (map [string ]* corev1.Node , len (s .nodeRefMap ))
77+ for _ , node := range s .nodeRefMap {
78+ nodeNameMap [node .Name ] = node
79+ }
80+
81+ validNodeRefs := true
82+ for _ , nodeRef := range mp .Status .NodeRefs {
83+ foundNode , exists := nodeNameMap [nodeRef .Name ]
84+
85+ // If node not found or UID doesn't match, mark as invalid
86+ if ! exists || foundNode .UID != nodeRef .UID {
87+ log .V (1 ).Info ("NodeRefs do not match current Nodes, will reassign" )
88+ validNodeRefs = false
89+ break
90+ }
91+ }
92+
93+ if validNodeRefs {
94+ v1beta1conditions .MarkTrue (mp , clusterv1 .ReplicasReadyV1Beta1Condition )
95+ return ctrl.Result {}, nil
96+ }
97+ } else {
98+ // If nodeRefMap is nil, we can't validate UIDs, so proceed with reconciliation
99+ log .V (2 ).Info ("NodeRefMap is nil, proceeding with reconciliation to validate NodeRefs" )
100+ }
75101 }
76102
77103 // Check that the MachinePool has valid ProviderIDList.
0 commit comments