Skip to content

Commit

Permalink
fix(backup): fix returning backup volume list info
Browse files Browse the repository at this point in the history
for recurring job and CSI snapshotter.

ref: longhorn/longhorn 5411

Signed-off-by: James Lu <[email protected]>
  • Loading branch information
mantissahz authored and derekbit committed Dec 23, 2024
1 parent fb9c6ca commit 7ae8f60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 27 deletions.
19 changes: 8 additions & 11 deletions app/recurring_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,23 +702,20 @@ func (job *Job) doRecurringBackup() (err error) {
}

func (job *Job) getBackupVolume(backupTargetName string) (*longhornclient.BackupVolume, error) {
list, err := job.api.BackupVolume.List(&longhornclient.ListOpts{
Filters: map[string]interface{}{
types.LonghornLabelBackupTarget: backupTargetName,
types.LonghornLabelBackupVolume: job.volumeName,
}})
list, err := job.api.BackupVolume.List(&longhornclient.ListOpts{})
if err != nil {
return nil, err
}

if len(list.Data) > 1 {
return nil, fmt.Errorf("found more than one backup volume %v of the backup target %v", job.volumeName, backupTargetName)
}
if len(list.Data) == 0 {
return nil, fmt.Errorf("failed to find backup volume %s of the backup target %s", job.volumeName, backupTargetName)
backupVolumeName := ""
for _, bv := range list.Data {
if bv.BackupTargetName == backupTargetName && bv.VolumeName == job.volumeName {
backupVolumeName = bv.Name
break
}
}

return &list.Data[0], nil
return job.api.BackupVolume.ById(backupVolumeName)
}

func (job *Job) doRecurringFilesystemTrim(volume *longhornclient.Volume) (err error) {
Expand Down
29 changes: 13 additions & 16 deletions csi/controller_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,29 +270,26 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol

func (cs *ControllerServer) getBackupVolume(volumeName string) (*longhornclient.BackupVolume, error) {
log := cs.log.WithFields(logrus.Fields{"function": "getBackupVolume"})
vol, err := cs.apiClient.Volume.ById(volumeName)
list, err := cs.apiClient.BackupVolume.List(&longhornclient.ListOpts{})
if err != nil {
return nil, errors.Wrapf(err, "getBackupVolume: fail to get source volume %v", volumeName)
return nil, err
}
if len(list.Data) == 0 {
return nil, nil
}

list, err := cs.apiClient.BackupVolume.List(&longhornclient.ListOpts{
Filters: map[string]interface{}{
types.LonghornLabelBackupTarget: vol.BackupTargetName,
types.LonghornLabelBackupVolume: volumeName,
}})
vol, err := cs.apiClient.Volume.ById(volumeName)
if err != nil {
return nil, errors.Wrap(err, "failed to list backup volumes")
return nil, errors.Wrapf(err, "getBackupVolume: fail to get source volume %v", volumeName)
}

if len(list.Data) > 1 {
return nil, fmt.Errorf("found multiple backup volumes for backup target %s and volume %s", vol.BackupTargetName, volumeName)
}
if len(list.Data) == 0 {
log.Debugf("cannot find backup volume with backup target %s and volume %s", vol.BackupTargetName, volumeName)
return nil, nil
for _, bv := range list.Data {
if bv.BackupTargetName == vol.BackupTargetName && bv.VolumeName == volumeName {
return &bv, nil
}
}

return &list.Data[0], nil
log.Debugf("cannot find backup volume with backup target %s and volume %s", vol.BackupTargetName, volumeName)
return nil, nil
}

func (cs *ControllerServer) checkAndPrepareBackingImage(volumeName, backingImageName string, volumeParameters map[string]string) error {
Expand Down

0 comments on commit 7ae8f60

Please sign in to comment.