Skip to content

Commit

Permalink
Wrap node update in retry
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Vest committed Feb 12, 2024
1 parent 63b9937 commit 2b83cf9
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cloud/linode/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
v1informers "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/retry"
"k8s.io/client-go/util/workqueue"
"k8s.io/klog/v2"
)
Expand Down Expand Up @@ -139,10 +140,24 @@ func (s *nodeController) handleNode(ctx context.Context, node *v1.Node) error {
return nil
}

node.Labels[annLinodeHostUUID] = linode.HostUUID
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
// Get a fresh copy of the node so the resource version is up to date
n, err := s.kubeclient.CoreV1().Nodes().Get(ctx, node.Name, metav1.GetOptions{})
if err != nil {
return err
}

_, err = s.kubeclient.CoreV1().Nodes().Update(ctx, node, metav1.UpdateOptions{})
if err != nil {
// It may be that the UUID has been set
if n.Labels[annLinodeHostUUID] == linode.HostUUID {
s.SetLastMetadataUpdate(node.Name)
return nil
}

// Try to update the node
n.Labels[annLinodeHostUUID] = linode.HostUUID
_, err = s.kubeclient.CoreV1().Nodes().Update(ctx, node, metav1.UpdateOptions{})
return err
}); err != nil {
klog.Infof("node update error: %s", err.Error())
return err
}
Expand Down

0 comments on commit 2b83cf9

Please sign in to comment.