Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions exp/internal/controllers/machinepool_controller_noderef.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,33 @@ func (r *MachinePoolReconciler) reconcileNodeRefs(ctx context.Context, s *scope)
readyReplicas = mp.Status.Deprecated.V1Beta1.ReadyReplicas
}
if ptr.Deref(mp.Status.Replicas, 0) == readyReplicas && len(mp.Status.NodeRefs) == int(readyReplicas) {
v1beta1conditions.MarkTrue(mp, clusterv1.ReplicasReadyV1Beta1Condition)
return ctrl.Result{}, nil
// Validate that the UIDs in NodeRefs are still valid
if s.nodeRefMap != nil {
// Create a name-to-node mapping for efficient lookup
nodeNameMap := make(map[string]*corev1.Node, len(s.nodeRefMap))
for _, node := range s.nodeRefMap {
nodeNameMap[node.Name] = node
}

validNodeRefs := true
for _, nodeRef := range mp.Status.NodeRefs {
foundNode, exists := nodeNameMap[nodeRef.Name]

// If node not found or UID doesn't match, mark as invalid
if !exists || foundNode.UID != nodeRef.UID {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to have a higher verbosity log entry if the node names are the same but the UIDs are different.

validNodeRefs = false
break
}
}

if validNodeRefs {
v1beta1conditions.MarkTrue(mp, clusterv1.ReplicasReadyV1Beta1Condition)
return ctrl.Result{}, nil
}
} else {
// If nodeRefMap is nil, we can't validate UIDs, so proceed with reconciliation
log.V(2).Info("NodeRefMap is nil, proceeding with reconciliation to validate NodeRefs")
}
}

// Check that the MachinePool has valid ProviderIDList.
Expand Down