From afd8a847608beda10856d7f9b814617a12aeacfe Mon Sep 17 00:00:00 2001 From: Shahaf Bahar Date: Wed, 1 Nov 2023 14:39:35 +0200 Subject: [PATCH] Skip pvb creation when pvc excluded --- pkg/backup/item_backupper.go | 42 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/pkg/backup/item_backupper.go b/pkg/backup/item_backupper.go index 61f6834d60..4779198a51 100644 --- a/pkg/backup/item_backupper.go +++ b/pkg/backup/item_backupper.go @@ -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) }