Skip to content

Commit bdc5417

Browse files
aaronferngagan16k
andauthored
Skip finalizers for non-MCM nodes (#1065) (#1066)
Co-authored-by: Gagan <[email protected]>
1 parent aa6fd98 commit bdc5417

File tree

1 file changed

+22
-13
lines changed
  • pkg/util/provider/machinecontroller

1 file changed

+22
-13
lines changed

pkg/util/provider/machinecontroller/node.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ func (c *controller) updateNode(oldObj, newObj any) {
6161
return
6262
}
6363

64+
// Do not process node updates if there is no associated machine
65+
// In case of transient errors while fetching machine, do not retry
66+
// as the update handler will be triggered again due to kubelet updates.
67+
machine, err := c.getMachineFromNode(node.Name)
68+
if err != nil {
69+
klog.Errorf("unable to handle update event for node %q, couldn't fetch associated machine. Error: %v", node.Name, err)
70+
return
71+
}
72+
6473
// delete the machine if the node is deleted
6574
if node.DeletionTimestamp != nil {
6675
err := c.triggerMachineDeletion(context.Background(), node.Name)
@@ -69,18 +78,11 @@ func (c *controller) updateNode(oldObj, newObj any) {
6978
}
7079
return
7180
}
72-
// Check if finalizer was removed - re-add it
73-
if c.hasNodeFinalizerBeenRemoved(oldNode, node, NodeFinalizerName) {
74-
c.enqueueNodeAfter(node, time.Duration(machineutils.MediumRetry), fmt.Sprintf("MCM finalizer was removed from node %q, re-queuing", node.Name))
75-
return
76-
}
7781

78-
machine, err := c.getMachineFromNode(node.Name)
79-
if err != nil {
80-
klog.Errorf("unable to handle update event for node %q, couldn't fetch associated machine. Error: %v", node.Name, err)
82+
if !HasFinalizer(node, NodeFinalizerName) {
83+
c.enqueueNodeAfter(node, time.Duration(machineutils.MediumRetry), fmt.Sprintf("MCM finalizer missing from node %q, re-queuing", node.Name))
8184
return
8285
}
83-
8486
// to reconcile on addition/removal of essential taints in machine lifecycle, example - critical component taint
8587
if addedOrRemovedEssentialTaints(oldNode, node, machineutils.EssentialTaints) {
8688
c.enqueueMachine(machine, fmt.Sprintf("handling node UPDATE event. Atleast one of essential taints on node %q has changed", getNodeName(machine)))
@@ -145,6 +147,17 @@ func (c *controller) reconcileClusterNodeKey(key string) error {
145147
return nil
146148
}
147149

150+
// Ignore node updates without an associated machine. Retry only for errors other than errNoMachineMatch;
151+
// transient fetch errors will be eventually requeued by the update handler due to kubelet updates.
152+
if _, err := c.getMachineFromNode(node.Name); err != nil {
153+
if errors.Is(err, errNoMachineMatch) {
154+
klog.Errorf("ClusterNode %q: No machine found matching node, skipping adding finalizers", key)
155+
return nil
156+
}
157+
klog.Errorf("ClusterNode %q: error fetching machine for node: %v", key, err)
158+
return err
159+
}
160+
148161
if node.DeletionTimestamp != nil {
149162
err := c.triggerMachineDeletion(context.Background(), node.Name)
150163
if err != nil {
@@ -271,10 +284,6 @@ func (c *controller) updateNodeFinalizers(ctx context.Context, node *corev1.Node
271284
return nil
272285
}
273286

274-
func (c *controller) hasNodeFinalizerBeenRemoved(oldNode, newNode *corev1.Node, finalizerName string) bool {
275-
return HasFinalizer(oldNode, finalizerName) && !HasFinalizer(newNode, finalizerName)
276-
}
277-
278287
// HasFinalizer checks if the given object has the specified finalizer.
279288
func HasFinalizer(o metav1.Object, finalizer string) bool {
280289
return sets.NewString(o.GetFinalizers()...).Has(finalizer)

0 commit comments

Comments
 (0)