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

Track status of volumesnapshots to update backup via backup_operations_controller #7172

Closed
Closed
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
36 changes: 36 additions & 0 deletions pkg/backup/snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import (
"context"
"fmt"

snapshotv1api "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
"github.com/sirupsen/logrus"
Expand All @@ -14,6 +15,40 @@
"github.com/vmware-tanzu/velero/pkg/util/boolptr"
)

// Tracks volume snapshots for this backup.
// Completion status will be updated in backup_operations_controller.go via ProgressOperations information.
var (
backupVolumeSnapshotTracker map[string]map[string]bool // backup name -> namespace/volume snapshot name -> completion status
)

func TrackVolumeSnapshotsForBackup(backup *velerov1api.Backup, volumeSnapshots []snapshotv1api.VolumeSnapshot, backupLog logrus.FieldLogger) {
if backupVolumeSnapshotTracker == nil {
backupVolumeSnapshotTracker = make(map[string]map[string]bool, 0)
}
if backupVolumeSnapshotTracker[backup.Name] == nil {
backupVolumeSnapshotTracker[backup.Name] = make(map[string]bool, 0)
}
for _, vs := range volumeSnapshots {
backupVolumeSnapshotTracker[backup.Name][VolumeSnapshotStatusTrackerName(&vs)] = false
}
backupLog.Infof("Tracking %d volume snapshots for backup %s", len(volumeSnapshots), backup.Name)

Check warning on line 34 in pkg/backup/snapshots.go

View check run for this annotation

Codecov / codecov/patch

pkg/backup/snapshots.go#L24-L34

Added lines #L24 - L34 were not covered by tests
}

func VolumeSnapshotStatusTrackerName(vs *snapshotv1api.VolumeSnapshot) string {
return fmt.Sprintf("%s/%s", vs.Namespace, vs.Name)

Check warning on line 38 in pkg/backup/snapshots.go

View check run for this annotation

Codecov / codecov/patch

pkg/backup/snapshots.go#L37-L38

Added lines #L37 - L38 were not covered by tests
}

func GetVolumeSnapshotTrackerNamesForBackupName(backupName string) map[string]bool {
return backupVolumeSnapshotTracker[backupName]

Check warning on line 42 in pkg/backup/snapshots.go

View check run for this annotation

Codecov / codecov/patch

pkg/backup/snapshots.go#L41-L42

Added lines #L41 - L42 were not covered by tests
}

func UntrackVolumeSnapshotsForBackup(backup *velerov1api.Backup) {
if backupVolumeSnapshotTracker == nil {
return
}
delete(backupVolumeSnapshotTracker, backup.Name)

Check warning on line 49 in pkg/backup/snapshots.go

View check run for this annotation

Codecov / codecov/patch

pkg/backup/snapshots.go#L45-L49

Added lines #L45 - L49 were not covered by tests
}

// Common function to update the status of CSI snapshots
// returns VolumeSnapshot, VolumeSnapshotContent, VolumeSnapshotClasses referenced
func UpdateBackupCSISnapshotsStatus(client kbclient.Client, globalCRClient kbclient.Client, backup *velerov1api.Backup, backupLog logrus.FieldLogger) (volumeSnapshots []snapshotv1api.VolumeSnapshot, volumeSnapshotContents []snapshotv1api.VolumeSnapshotContent, volumeSnapshotClasses []snapshotv1api.VolumeSnapshotClass) {
Expand All @@ -30,6 +65,7 @@
if err != nil {
backupLog.Error(err)
}

volumeSnapshots = append(volumeSnapshots, vsList.Items...)

if err := client.List(context.Background(), vscList, &kbclient.ListOptions{LabelSelector: selector}); err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/backup_finalizer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func (r *backupFinalizerReconciler) Reconcile(ctx context.Context, req ctrl.Requ
backup.Status.CompletionTimestamp = &metav1.Time{Time: r.clock.Now()}
recordBackupMetrics(log, backup, outBackupFile, r.metrics, true)

pkgbackup.UpdateBackupCSISnapshotsStatus(r.client, r.globalCRClient, backup, log)
// update backup metadata in object store
backupJSON := new(bytes.Buffer)
if err := encode.To(backup, "json", backupJSON); err != nil {
Expand Down
Loading