Skip to content

Commit

Permalink
PB-8347:
Browse files Browse the repository at this point in the history
	- 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
  • Loading branch information
sgajawada-px committed Oct 18, 2024
1 parent 7cde58b commit 1e12c3c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
13 changes: 8 additions & 5 deletions pkg/executor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/executor/kopia/kopiabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/restic/resticbackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func runBackup(sourcePath string) error {
}

if volumeBackupName != "" {
if err = executor.CreateVolumeBackup(
if _, err = executor.CreateVolumeBackup(
volumeBackupName,
namespace,
repo.Name,
Expand Down

0 comments on commit 1e12c3c

Please sign in to comment.