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

don't snapshot volumes that have been backed up with restic #608

Merged
merged 1 commit into from
Jun 28, 2018

Conversation

skriss
Copy link
Contributor

@skriss skriss commented Jun 25, 2018

Signed-off-by: Steve Kriss steve@heptio.com

Fixes #604

@skriss skriss requested review from ncdc and nrb June 25, 2018 18:43
@skriss skriss changed the title don't snapshot volumes that have been backed up with restic [WIP] don't snapshot volumes that have been backed up with restic Jun 25, 2018
@skriss skriss force-pushed the no-pv-snapshot-if-restic-backup branch 2 times, most recently from 445dcc3 to 3bbe0e6 Compare June 25, 2018 20:58
@skriss skriss changed the title [WIP] don't snapshot volumes that have been backed up with restic don't snapshot volumes that have been backed up with restic Jun 25, 2018
"k8s.io/apimachinery/pkg/util/sets"
)

// volumeSnapshotTracker keeps track of volumes that have been snapshotted.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd recommend stating that it tracks restic volumes that have been snapshotted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

// get the volumes to backup using restic, and add any of them that are PVCs to the pvc snapshot
// tracker, so that when we backup PVCs/PVs via an item action in the next step, we don't snapshot
// PVs that will have their data backed up with restic.
if pod, podVolumeBackups, err = getPodVolumesToBackup(obj, ib.pvcSnapshotTracker); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Having getPodVolumesToBackup also add to the tracker seems like it's doing more work than it should. What if we did this?

pod, err = podFromUnstructured(obj)
// check err

resticVolumesToBackup := restic.GetVolumesToBackup(pod)
ib.pvcSnapshotTracker.Track(pod, resticVolumesToBackup) // this has the looping logic

(I think resticVolumesToBackup is more descriptive than podVolumeBackups.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I think I was tired when I wrote this. updated.

@skriss skriss force-pushed the no-pv-snapshot-if-restic-backup branch from 3bbe0e6 to f3b88df Compare June 27, 2018 21:18
func backupPodVolumes(log logrus.FieldLogger, backup *api.Backup, obj runtime.Unstructured, backupper restic.Backupper) (runtime.Unstructured, []error) {
if backupper == nil {
log.Warn("No restic backupper, not backing up pod's volumes")
func (ib *defaultItemBackupper) backupPodVolumes(log logrus.FieldLogger, obj runtime.Unstructured, pod *corev1api.Pod, volumes []string) (runtime.Unstructured, []error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think this function would be cleaner if it didn't require both obj (an unstructured pod) and pod? We could have it return volumeSnapshots and call restic.SetPodSnapshotAnnotation outside of here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. updated and this is now much cleaner :)

@skriss skriss force-pushed the no-pv-snapshot-if-restic-backup branch from f3b88df to af30892 Compare June 27, 2018 21:53

// pvcSnapshotTracker keeps track of persistent volume claims that have been snapshotted
// with restic.
type pvcSnapshotTracker struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the comment on this. On a second pass, I'm wondering if having restic in the name might be helpful.

For example, in backup.go, L289, it's near snapshotService, which is for cloud volumes. Looking at the two names could get confusing, given they're for different types of snapshots.

I don't want to encode too much information in names, but the closeness here seems a bit off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed the variable to resticSnapshotTracker and left the type name as pvcSnapshotTracker. I think that makes it pretty clear. let me know what you think.

@skriss skriss force-pushed the no-pv-snapshot-if-restic-backup branch from af30892 to 93dbcd9 Compare June 28, 2018 00:00
@ncdc
Copy link
Contributor

ncdc commented Jun 28, 2018

I've been thinking a bit about how we're encoding more and more custom per-resource logic into the backupper/restorer instead of using item actions.

One way we could achieve this with an item action would be to create one that applies to pods and pvs. We would also need a prioritized order for resources when backing up (#586), where we make sure we do pods before pvs. We'd maybe want to consider creating a special-case interface specifically for snapshotting, that would run after the normal item actions. In this interface we'd need a way for 1 plugin to signal to ark either a) that it's handling the snapshot, or b) that no other plugins should execute a snapshot. If we have all that, we could have a theoretical resticSnapshotAction:

  1. The plugin would get its own copy of a restic repo manager (maybe a bad thing, but let's say it's ok)
  2. Upon seeing a pod, the plugin would create PVBs for all appropriate volumes and add the ns/pvcName to its tracking map
  3. Upon seeing a pv, if the pv's claimRef is in the tracking map, tell ark it's "handling" the snapshot / no other plugins should execute a snapshot

We should not do this now - this PR is fine to go in. But we should start to think about ways that we can make bits and pieces of logic like this a bit more self contained as plugins, instead of having to modify the core backup/restore functions.

@@ -355,6 +359,23 @@ func (ib *defaultItemBackupper) takePVSnapshot(pv runtime.Unstructured, backup *
return nil
}

// If this PV is claimed, see if we've already taken a (restic) snapshot of the contents
// of this PV. If so, don't take a snapshot.
if collections.Exists(pv.UnstructuredContent(), "spec.claimRef") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to convert to an actual PV here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, will make this simpler

@ncdc
Copy link
Contributor

ncdc commented Jun 28, 2018

Any plans to unit test the tracking in backupItem?

@skriss
Copy link
Contributor Author

skriss commented Jun 28, 2018

Yeah, I'll add some tests.

Signed-off-by: Steve Kriss <steve@heptio.com>
@skriss skriss force-pushed the no-pv-snapshot-if-restic-backup branch from 93dbcd9 to 11c176c Compare June 28, 2018 17:19
@skriss
Copy link
Contributor Author

skriss commented Jun 28, 2018

OK got tests updated

@ncdc
Copy link
Contributor

ncdc commented Jun 28, 2018

LGTM

@ncdc ncdc merged commit eaeb9d6 into vmware-tanzu:master Jun 28, 2018
@skriss skriss deleted the no-pv-snapshot-if-restic-backup branch June 28, 2018 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants