Skip to content
Merged
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
35 changes: 22 additions & 13 deletions pkg/util/provider/machinecontroller/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ func (c *controller) updateNode(oldObj, newObj any) {
return
}

// Do not process node updates if there is no associated machine
// In case of transient errors while fetching machine, do not retry
// as the update handler will be triggered again due to kubelet updates.
machine, err := c.getMachineFromNode(node.Name)
if err != nil {
klog.Errorf("unable to handle update event for node %q, couldn't fetch associated machine. Error: %v", node.Name, err)
return
}

// delete the machine if the node is deleted
if node.DeletionTimestamp != nil {
err := c.triggerMachineDeletion(context.Background(), node.Name)
Expand All @@ -69,18 +78,11 @@ func (c *controller) updateNode(oldObj, newObj any) {
}
return
}
// Check if finalizer was removed - re-add it
if c.hasNodeFinalizerBeenRemoved(oldNode, node, NodeFinalizerName) {
c.enqueueNodeAfter(node, time.Duration(machineutils.MediumRetry), fmt.Sprintf("MCM finalizer was removed from node %q, re-queuing", node.Name))
return
}

machine, err := c.getMachineFromNode(node.Name)
if err != nil {
klog.Errorf("unable to handle update event for node %q, couldn't fetch associated machine. Error: %v", node.Name, err)
if !HasFinalizer(node, NodeFinalizerName) {
c.enqueueNodeAfter(node, time.Duration(machineutils.MediumRetry), fmt.Sprintf("MCM finalizer missing from node %q, re-queuing", node.Name))
return
}

// to reconcile on addition/removal of essential taints in machine lifecycle, example - critical component taint
if addedOrRemovedEssentialTaints(oldNode, node, machineutils.EssentialTaints) {
c.enqueueMachine(machine, fmt.Sprintf("handling node UPDATE event. Atleast one of essential taints on node %q has changed", getNodeName(machine)))
Expand Down Expand Up @@ -145,6 +147,17 @@ func (c *controller) reconcileClusterNodeKey(key string) error {
return nil
}

// Ignore node updates without an associated machine. Retry only for errors other than errNoMachineMatch;
// transient fetch errors will be eventually requeued by the update handler due to kubelet updates.
if _, err := c.getMachineFromNode(node.Name); err != nil {
if errors.Is(err, errNoMachineMatch) {
klog.Errorf("ClusterNode %q: No machine found matching node, skipping adding finalizers", key)
return nil
}
klog.Errorf("ClusterNode %q: error fetching machine for node: %v", key, err)
return err
}

if node.DeletionTimestamp != nil {
err := c.triggerMachineDeletion(context.Background(), node.Name)
if err != nil {
Expand Down Expand Up @@ -271,10 +284,6 @@ func (c *controller) updateNodeFinalizers(ctx context.Context, node *corev1.Node
return nil
}

func (c *controller) hasNodeFinalizerBeenRemoved(oldNode, newNode *corev1.Node, finalizerName string) bool {
return HasFinalizer(oldNode, finalizerName) && !HasFinalizer(newNode, finalizerName)
}

// HasFinalizer checks if the given object has the specified finalizer.
func HasFinalizer(o metav1.Object, finalizer string) bool {
return sets.NewString(o.GetFinalizers()...).Has(finalizer)
Expand Down
Loading