From bfe760cef9abe155a9d0988ec13adf894225866d Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 23 Dec 2024 18:24:42 +0800 Subject: [PATCH] fix(backup): modify API for the Action backupList ref: longhorn/longhorn 5411 Signed-off-by: James Lu --- csi/controller_server.go | 1 + manager/engine.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/csi/controller_server.go b/csi/controller_server.go index 5370334e00..f0359ff67e 100644 --- a/csi/controller_server.go +++ b/csi/controller_server.go @@ -289,6 +289,7 @@ func (cs *ControllerServer) getBackupVolume(volumeName string) (*longhornclient. } } log.Debugf("cannot find backup volume with backup target %s and volume %s", vol.BackupTargetName, volumeName) + // return no error if no backup volume found as backup is not completed and backup volume is not created yet. return nil, nil } diff --git a/manager/engine.go b/manager/engine.go index 79dcff6055..1157e266a3 100644 --- a/manager/engine.go +++ b/manager/engine.go @@ -511,7 +511,20 @@ func (m *VolumeManager) ListBackupsForBackupVolumeSorted(backupVolumeName string return []*longhorn.Backup{}, err } - return m.ListBackupsForVolumeSorted(bv.Spec.VolumeName) + backupMap, err := m.ds.ListBackupsWithBackupTargetAndBackupVolumeRO(bv.Spec.BackupTargetName, bv.Spec.VolumeName) + if err != nil { + return []*longhorn.Backup{}, err + } + backupNames, err := util.SortKeys(backupMap) + if err != nil { + return []*longhorn.Backup{}, err + } + backups := make([]*longhorn.Backup, len(backupMap)) + for i, backupName := range backupNames { + backups[i] = backupMap[backupName] + } + + return backups, nil } func (m *VolumeManager) GetBackup(backupName, volumeName string) (*longhorn.Backup, error) {