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 1, 2023
1 parent 03e582c commit 2cb4334
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions pkg/backup/item_backupper.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,35 @@ 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))
for _, volume := range includedVolumes {
// 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.
ib.podVolumeSnapshotTracker.Track(pod, volume)

if found, pvcName := ib.podVolumeSnapshotTracker.TakenForPodVolume(pod, volume); found {
log.WithFields(map[string]interface{}{
"podVolume": volume,
"pvcName": pvcName,
}).Info("Pod volume uses a persistent volume claim which has already been backed up from another pod, skipping.")
continue
includedVolumesLoop:
for _, volume := range includedVolumes {
// 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.
ib.podVolumeSnapshotTracker.Track(pod, volume)

if found, pvcName := ib.podVolumeSnapshotTracker.TakenForPodVolume(pod, volume); found {
log.WithFields(map[string]interface{}{
"podVolume": volume,
"pvcName": pvcName,
}).Info("Pod volume uses a persistent volume claim which has already been backed up from another pod, skipping.")
continue
}
if ( !ib.backupRequest.ResourceIncludesExcludes.ShouldInclude(kuberesource.PersistentVolumeClaims.String()) ) {

for _, podVolume := range pod.Spec.Volumes {
if podVolume.Name != volume {
continue
}

if podVolume.PersistentVolumeClaim != nil {
log.Infof("Skipping volume %s because it's a %s type and this resource excluded in the backup.", volume, kuberesource.PersistentVolumeClaims.String())
continue includedVolumesLoop
}
}
}
pvbVolumes = append(pvbVolumes, volume)
}
pvbVolumes = append(pvbVolumes, volume)
}
for _, optedOutVol := range optedOutVolumes {
ib.podVolumeSnapshotTracker.Optout(pod, optedOutVol)
}
Expand Down

0 comments on commit 2cb4334

Please sign in to comment.