Skip to content

Commit

Permalink
Skip pvb creation when pvc excluded
Browse files Browse the repository at this point in the history
Signed-off-by: Shahaf Bahar <[email protected]>
  • Loading branch information
sbahar619 committed Nov 6, 2023
1 parent 03e582c commit 23fbc19
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions changelogs/unreleased/7045-sbahar619
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FS backup create PodVolumeBackup when the backup excluded PVC,
so I added logic to skip PVC volume type when PVC is not included in the backup resources to be backed up.
6 changes: 6 additions & 0 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3114,6 +3114,9 @@ func TestBackupWithPodVolume(t *testing.T) {
Volumes(builder.ForVolume("bar").PersistentVolumeClaimSource("pvc-1").Result()).
Result(),
),
test.PVCs(
builder.ForPersistentVolumeClaim("ns-1", "pvc-1").VolumeName("pv-1").Result(),
),
},
want: []*velerov1.PodVolumeBackup{
builder.ForPodVolumeBackup("velero", "pvb-ns-1-pod-1-foo").Volume("foo").Result(),
Expand All @@ -3135,6 +3138,9 @@ func TestBackupWithPodVolume(t *testing.T) {
Volumes(builder.ForVolume("bar").PersistentVolumeClaimSource("pvc-1").Result()).
Result(),
),
test.PVCs(
builder.ForPersistentVolumeClaim("ns-1", "pvc-1").VolumeName("pv-1").Result(),
),
},
want: []*velerov1.PodVolumeBackup{
builder.ForPodVolumeBackup("velero", "pvb-ns-1-pod-2-bar").Volume("bar").Result(),
Expand Down
17 changes: 17 additions & 0 deletions pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,24 @@ func (ib *itemBackupper) backupItemInternal(logger logrus.FieldLogger, obj runti
// any volumes that use a PVC that we've already backed up (this would be in a read-write-many scenario,
// where it's been backed up from another pod), since we don't need >1 backup per PVC.
includedVolumes, optedOutVolumes := pdvolumeutil.GetVolumesByPod(pod, boolptr.IsSetToTrue(ib.backupRequest.Spec.DefaultVolumesToFsBackup))
includedVolumesLoop:
for _, volume := range includedVolumes {
// Check if the PVC resource is not included in the backup
if !ib.backupRequest.ResourceIncludesExcludes.ShouldInclude(kuberesource.PersistentVolumeClaims.String()) {
// Search for the matched volume in the Pod
for _, podVolume := range pod.Spec.Volumes {
if podVolume.Name != volume {
continue

Check warning on line 213 in pkg/backup/item_backupper.go

View check run for this annotation

Codecov / codecov/patch

pkg/backup/item_backupper.go#L212-L213

Added lines #L212 - L213 were not covered by tests
}
// Check if the volume is a PVC type
if podVolume.PersistentVolumeClaim != nil {
// Skip the volume and prevent PVB creation
log.Infof("Skipping volume %s because it's a %s type and this resource excluded in the backup.", volume, kuberesource.PersistentVolumeClaims.String())
continue includedVolumesLoop

Check warning on line 219 in pkg/backup/item_backupper.go

View check run for this annotation

Codecov / codecov/patch

pkg/backup/item_backupper.go#L216-L219

Added lines #L216 - L219 were not covered by tests
}
}
}

// track the volumes that are PVCs using 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 pod volume backup.
Expand Down

0 comments on commit 23fbc19

Please sign in to comment.