Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PB-8347: Fix KDMP Backup Failure in-case KDMP job removed post VB CR is updated with SnapshotID #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Collaborator

@vikasit12 vikasit12 Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to change function signature?

Can't simply return nil if snaphotID is already there.

if volumeBackup.Status.SnapshotID != "" { // If SnapshotID exists, return early or handle accordingly return nil } // Proceed with the rest of the logic if SnapshotID does not exist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we return nil, then will go with the control flow and takes another snapshot (redoing the same work again). So instead will return from the runBackup to prevent taking another snapshot.

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
Loading