From 1e12c3cb8276bd82bec5fe8f548c7c2fe0db47fd Mon Sep 17 00:00:00 2001 From: Santosh Kumar Gajawada Date: Fri, 18 Oct 2024 10:37:49 +0530 Subject: [PATCH] PB-8347: - Update CreateVolumeBackup to return a boolean based upon the snapshotID - Update KopiaBackup runBackup to exit successfully in case the VB CR already holds the snapshotID --- pkg/executor/common.go | 13 ++++++++----- pkg/executor/kopia/kopiabackup.go | 4 +++- pkg/executor/restic/resticbackup.go | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/executor/common.go b/pkg/executor/common.go index b0a6e9922..40004ccda 100644 --- a/pkg/executor/common.go +++ b/pkg/executor/common.go @@ -607,7 +607,7 @@ func UpdateResourceBackupStatus( } // CreateVolumeBackup creates volumebackup CRD -func CreateVolumeBackup(name, namespace, repository, blName, blNamespace string) error { +func CreateVolumeBackup(name, namespace, repository, blName, blNamespace string) (bool, error) { new := &kdmpapi.VolumeBackup{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -630,18 +630,21 @@ func CreateVolumeBackup(name, namespace, repository, blName, blNamespace string) if errors.IsNotFound(err) { _, err = kdmpops.Instance().CreateVolumeBackup(context.Background(), new) } - return err + return false, err } if !reflect.DeepEqual(vb.Spec, new.Spec) { - return fmt.Errorf("volumebackup %s/%s with different spec already exists", namespace, name) + return false, fmt.Errorf("volumebackup %s/%s with different spec already exists", namespace, name) } + // The Kopia snapshot is considered successful if the volume backup CR status is updated with the SnapshotID. + // In this case, we will mark the KDMP pod as successful without performing any further processing. if vb.Status.SnapshotID != "" { - return fmt.Errorf("volumebackup %s/%s with snapshot id already exists", namespace, name) + logrus.Infof("volumebackup %s/%s with snapshot id already exists", namespace, name) + return true, nil } - return nil + return false, nil } // GetSourcePath data source path diff --git a/pkg/executor/kopia/kopiabackup.go b/pkg/executor/kopia/kopiabackup.go index ea59d1a3c..40192a37c 100644 --- a/pkg/executor/kopia/kopiabackup.go +++ b/pkg/executor/kopia/kopiabackup.go @@ -89,7 +89,7 @@ func runBackup(sourcePath string) error { repo.Name = repoName } if volumeBackupName != "" { - if err := executor.CreateVolumeBackup( + if isSnapshotIDExists, err := executor.CreateVolumeBackup( volumeBackupName, bkpNamespace, repoName, @@ -98,6 +98,8 @@ func runBackup(sourcePath string) error { ); err != nil { logrus.Errorf("%s: %v", fn, err) return err + } else if isSnapshotIDExists { + return nil } } if rErr != nil { diff --git a/pkg/executor/restic/resticbackup.go b/pkg/executor/restic/resticbackup.go index 27c91643d..dc2942fd2 100644 --- a/pkg/executor/restic/resticbackup.go +++ b/pkg/executor/restic/resticbackup.go @@ -57,7 +57,7 @@ func runBackup(sourcePath string) error { } if volumeBackupName != "" { - if err = executor.CreateVolumeBackup( + if _, err = executor.CreateVolumeBackup( volumeBackupName, namespace, repo.Name,