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 2, 2023
1 parent 03e582c commit 2483648
Show file tree
Hide file tree
Showing 2 changed files with 23 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.
21 changes: 21 additions & 0 deletions pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,28 @@ 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 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
}
}
}

// 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 2483648

Please sign in to comment.