Skip to content

Commit

Permalink
fix(backup restore): fix backup volume synced delay restore failed
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 6213

Signed-off-by: Jack Lin <jack.lin@suse.com>
(cherry picked from commit 4a57a72)
  • Loading branch information
ChanYiLin authored and David Ko committed Jun 29, 2023
1 parent ba2d3d1 commit a9bf977
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions webhook/resources/volume/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,18 @@ func (v *volumeMutator) Create(request *admission.Request, newObj runtime.Object
if err != nil {
return nil, werror.NewInvalidError(fmt.Sprintf("cannot get backup volume %s: %v", bvName, err), "")
}
if bv != nil && bv.Status.BackingImageName != "" {

backup, err := v.ds.GetBackupRO(bName)
if err != nil {
return nil, werror.NewInvalidError(fmt.Sprintf("cannot get backup %s: %v", bName, err), "")
}

if bv != nil && backup != nil && backup.Status.VolumeBackingImageName != "" {
if bv.Status.BackingImageName != backup.Status.VolumeBackingImageName {
err = fmt.Errorf("backup volume's backing image %v does not match backup's backing image %v. The backup volume resource is being updated and please retry later", bv.Status.BackingImageName, backup.Status.VolumeBackingImageName)
return nil, werror.NewForbiddenError(err.Error())
}

if volume.Spec.BackingImage == "" {
volume.Spec.BackingImage = bv.Status.BackingImageName
patchOps = append(patchOps, fmt.Sprintf(`{"op": "replace", "path": "/spec/backingImage", "value": "%s"}`, bv.Status.BackingImageName))
Expand All @@ -166,11 +177,6 @@ func (v *volumeMutator) Create(request *admission.Request, newObj runtime.Object
}
}

backup, err := v.ds.GetBackupRO(bName)
if err != nil {
return nil, werror.NewInvalidError(fmt.Sprintf("cannot get backup %s: %v", bName, err), "")
}

logrus.Infof("Override size of volume %v to %v because it's from backup", name, backup.Status.VolumeSize)
// formalize the final size to the unit in bytes
size, err = util.ConvertSize(backup.Status.VolumeSize)
Expand Down

0 comments on commit a9bf977

Please sign in to comment.