From 041e5e2a7ec46c1c4530a3b175af86a09ad4f1bd Mon Sep 17 00:00:00 2001 From: Shubham Pampattiwar Date: Tue, 9 Dec 2025 18:00:26 -0800 Subject: [PATCH] Address review feedback - Use ResolveNamespaceList() instead of GetIncludes() for more accurate namespace resolution when building the PVC-to-Pod cache - Refactor NewVolumeHelperImpl to call NewVolumeHelperImplWithCache with nil cache parameter to avoid code duplication Signed-off-by: Shubham Pampattiwar --- internal/volumehelper/volume_policy_helper.go | 18 +++++++++--------- pkg/backup/backup.go | 7 +++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/internal/volumehelper/volume_policy_helper.go b/internal/volumehelper/volume_policy_helper.go index 1808427fb..b4c3b467e 100644 --- a/internal/volumehelper/volume_policy_helper.go +++ b/internal/volumehelper/volume_policy_helper.go @@ -46,15 +46,15 @@ func NewVolumeHelperImpl( defaultVolumesToFSBackup bool, backupExcludePVC bool, ) VolumeHelper { - return &volumeHelperImpl{ - volumePolicy: volumePolicy, - snapshotVolumes: snapshotVolumes, - logger: logger, - client: client, - defaultVolumesToFSBackup: defaultVolumesToFSBackup, - backupExcludePVC: backupExcludePVC, - pvcPodCache: nil, // Cache will be nil by default for backward compatibility - } + return NewVolumeHelperImplWithCache( + volumePolicy, + snapshotVolumes, + logger, + client, + defaultVolumesToFSBackup, + backupExcludePVC, + nil, + ) } // NewVolumeHelperImplWithCache creates a VolumeHelper with a PVC-to-Pod cache for improved performance. diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index 23601c310..db6eec3a4 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -413,8 +413,11 @@ func (kb *kubernetesBackupper) BackupWithResolvers( // This avoids O(N*M) complexity when there are many PVCs and pods. // See issue #9179 for details. pvcPodCache := podvolumeutil.NewPVCPodCache() - namespaces := backupRequest.NamespaceIncludesExcludes.GetIncludes() - if len(namespaces) > 0 { + namespaces, err := backupRequest.NamespaceIncludesExcludes.ResolveNamespaceList() + if err != nil { + log.WithError(err).Warn("Failed to resolve namespace list for PVC-to-Pod cache, falling back to direct lookups") + pvcPodCache = nil + } else if len(namespaces) > 0 { if err := pvcPodCache.BuildCacheForNamespaces(context.Background(), namespaces, kb.kbClient); err != nil { // Log warning but continue - the cache will fall back to direct lookups log.WithError(err).Warn("Failed to build PVC-to-Pod cache, falling back to direct lookups")