Skip to content

Commit

Permalink
Merge pull request #8630 from ywk253100/250116_update
Browse files Browse the repository at this point in the history
Handle update conflict when restoring the status
  • Loading branch information
ywk253100 authored Jan 23, 2025
2 parents bedea9c + f0efe2a commit 9afad9a
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 9afad9a

Please sign in to comment.