From 664fd795577bb5978f98cadb37e0c953e3486736 Mon Sep 17 00:00:00 2001 From: Alex Vest Date: Fri, 16 Feb 2024 09:40:12 +0000 Subject: [PATCH] Wrap node update in retry (#175) Fixes an issue where the update could fail if the node object had been updated outside the CCM --- cloud/linode/node_controller.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/cloud/linode/node_controller.go b/cloud/linode/node_controller.go index ed53a41c..d8be9eda 100644 --- a/cloud/linode/node_controller.go +++ b/cloud/linode/node_controller.go @@ -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" ) @@ -139,10 +140,23 @@ 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 { + 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 }