-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
don't snapshot volumes that have been backed up with restic #608
Conversation
445dcc3
to
3bbe0e6
Compare
"k8s.io/apimachinery/pkg/util/sets" | ||
) | ||
|
||
// volumeSnapshotTracker keeps track of volumes that have been snapshotted. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
pkg/backup/item_backupper.go
Outdated
// 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 { |
There was a problem hiding this comment.
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
.)
There was a problem hiding this comment.
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.
3bbe0e6
to
f3b88df
Compare
pkg/backup/item_backupper.go
Outdated
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
f3b88df
to
af30892
Compare
|
||
// pvcSnapshotTracker keeps track of persistent volume claims that have been snapshotted | ||
// with restic. | ||
type pvcSnapshotTracker struct { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
af30892
to
93dbcd9
Compare
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:
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. |
pkg/backup/item_backupper.go
Outdated
@@ -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") { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Any plans to unit test the tracking in |
Yeah, I'll add some tests. |
Signed-off-by: Steve Kriss <steve@heptio.com>
93dbcd9
to
11c176c
Compare
OK got tests updated |
LGTM |
Signed-off-by: Steve Kriss steve@heptio.com
Fixes #604