Skip to content

🐛 Fix MachinePool nodeRef UID mismatch after K8s upgrade #12392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
nodeNameMap := make(map[string]*corev1.Node)
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 {
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