Fix DeepEqual when status is updated

Signed-off-by: Rafael Leal <rafaelealdias@gmail.com>
pull/4785/head
Rafael Leal 2022-05-12 10:46:48 -03:00
parent 89907bd141
commit 6a721403fb
No known key found for this signature in database
GPG Key ID: 6A8C53E7546F9F5A
1 changed files with 13 additions and 1 deletions

View File

@ -1227,6 +1227,18 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
// and which backup they came from.
addRestoreLabels(obj, ctx.restore.Name, ctx.restore.Spec.BackupName)
// Clear out status.
objWithoutStatus := obj.DeepCopy()
if objWithoutStatus, err = resetStatus(objWithoutStatus); err != nil {
errs.Add(namespace, err)
return warnings, errs
}
if !shouldRestoreStatus {
ctx.log.Infof("Resetting status for obj %s/%s", obj.GetKind(), obj.GetName())
obj = objWithoutStatus
}
ctx.log.Infof("Attempting to restore %s: %v", obj.GroupVersionKind().Kind, name)
createdObj, restoreErr := resourceClient.Create(obj)
isAlreadyExistsError, err := isAlreadyExistsError(ctx, obj, restoreErr, resourceClient)
@ -1255,7 +1267,7 @@ func (ctx *restoreContext) restoreItem(obj *unstructured.Unstructured, groupReso
addRestoreLabels(fromCluster, labels[velerov1api.RestoreNameLabel], labels[velerov1api.BackupNameLabel])
fromClusterWithLabels := fromCluster.DeepCopy() // saving the in-cluster object so that we can create label patch if overall patch fails
if !equality.Semantic.DeepEqual(fromCluster, obj) {
if !equality.Semantic.DeepEqual(fromCluster, objWithoutStatus) {
switch groupResource {
case kuberesource.ServiceAccounts:
desired, err := mergeServiceAccounts(fromCluster, obj)