Skip to content

Commit 2cc41a7

Browse files
PCP-4630: Fix MachinePool nodeRef UID mismatch after K8s upgrade (#244)
1 parent 32a338b commit 2cc41a7

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

exp/internal/controllers/machinepool_controller_noderef.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,34 @@ func (r *MachinePoolReconciler) reconcileNodeRefs(ctx context.Context, s *scope)
6565
// Check that the Machine doesn't already have a NodeRefs.
6666
// Return early if there is no work to do.
6767
if mp.Status.Replicas == mp.Status.ReadyReplicas && len(mp.Status.NodeRefs) == int(mp.Status.ReadyReplicas) {
68-
conditions.MarkTrue(mp, expv1.ReplicasReadyCondition)
69-
return ctrl.Result{}, nil
68+
// Validate that the UIDs in NodeRefs are still valid
69+
if s.nodeRefMap != nil {
70+
// Create a name-to-node mapping for efficient lookup
71+
nodeNameMap := make(map[string]*corev1.Node, len(s.nodeRefMap))
72+
for _, node := range s.nodeRefMap {
73+
nodeNameMap[node.Name] = node
74+
}
75+
76+
validNodeRefs := true
77+
for _, nodeRef := range mp.Status.NodeRefs {
78+
foundNode, exists := nodeNameMap[nodeRef.Name]
79+
80+
// If node not found or UID doesn't match, mark as invalid
81+
if !exists || foundNode.UID != nodeRef.UID {
82+
log.V(1).Info("NodeRefs do not match current Nodes, will reassign")
83+
validNodeRefs = false
84+
break
85+
}
86+
}
87+
88+
if validNodeRefs {
89+
conditions.MarkTrue(mp, expv1.ReplicasReadyCondition)
90+
return ctrl.Result{}, nil
91+
}
92+
} else {
93+
// If nodeRefMap is nil, we can't validate UIDs, so proceed with reconciliation
94+
log.V(2).Info("NodeRefMap is nil, proceeding with reconciliation to validate NodeRefs")
95+
}
7096
}
7197

7298
// Check that the MachinePool has valid ProviderIDList.

0 commit comments

Comments
 (0)