Skip to content

Commit

Permalink
Handle update conflict when restoring the status
Browse files Browse the repository at this point in the history
Handle update conflict when restoring the status

Fixes vmware-tanzu#8184

Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
  • Loading branch information
ywk253100 committed Jan 21, 2025
1 parent 223e1fc commit f0efe2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/8630-ywk253100
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handle update conflict when restoring the status
24 changes: 19 additions & 5 deletions pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
"k8s.io/client-go/dynamic/dynamicinformer"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/retry"
crclient "sigs.k8s.io/controller-runtime/pkg/client"

"github.com/vmware-tanzu/velero/internal/credentials"
Expand Down Expand Up @@ -1669,13 +1670,26 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
errs.Add(namespace, err)
return warnings, errs, itemExists
}
obj.SetResourceVersion(createdObj.GetResourceVersion())
updated, err := resourceClient.UpdateStatus(obj, metav1.UpdateOptions{})
if err != nil {

resourceVersion := createdObj.GetResourceVersion()
if err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
obj.SetResourceVersion(resourceVersion)
updated, err := resourceClient.UpdateStatus(obj, metav1.UpdateOptions{})
if err != nil {
if apierrors.IsConflict(err) {
res, err := resourceClient.Get(name, metav1.GetOptions{})
if err == nil {
resourceVersion = res.GetResourceVersion()
}
}
return err
}

createdObj = updated
return nil
}); err != nil {
ctx.log.Infof("status field update failed %s: %v", kube.NamespaceAndName(obj), err)
warnings.Add(namespace, err)
} else {
createdObj = updated
}
}

Expand Down

0 comments on commit f0efe2a

Please sign in to comment.