From 22ae12575ca4a5ae412d5f2a7f9698ea6e96cae2 Mon Sep 17 00:00:00 2001 From: PragatiVerma111 Date: Sun, 9 Aug 2026 20:45:29 +0530 Subject: [PATCH] =?UTF-8?q?Fix=20excluded=20namespace=20objects=20leaking?= =?UTF-8?q?=20into=20backup=20with=20cross-namespa=E2=80=A6=20(#10159)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix excluded namespace objects leaking into backup with cross-namespace listing Signed-off-by: Pragati * Add changelog for PR 10159 Signed-off-by: Pragati --------- Signed-off-by: Pragati Co-authored-by: Pragati --- changelogs/unreleased/10159-Pragati5-DEBUG | 1 + pkg/backup/backup_test.go | 23 ++++++++++++++++++++++ pkg/backup/item_collector.go | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/10159-Pragati5-DEBUG diff --git a/changelogs/unreleased/10159-Pragati5-DEBUG b/changelogs/unreleased/10159-Pragati5-DEBUG new file mode 100644 index 000000000..e8f33122d --- /dev/null +++ b/changelogs/unreleased/10159-Pragati5-DEBUG @@ -0,0 +1 @@ +Fix excluded namespace objects leaking into backups when using cross-namespace listing diff --git a/pkg/backup/backup_test.go b/pkg/backup/backup_test.go index 3baae0131..b116d5376 100644 --- a/pkg/backup/backup_test.go +++ b/pkg/backup/backup_test.go @@ -5429,6 +5429,29 @@ func TestBackupNamespaces(t *testing.T) { "resources/namespaces/v1-preferredversion/cluster/ns-3.json", }, }, + { + name: "Wildcard star with excluded namespaces test", + backup: defaultBackup().IncludedNamespaces("*").ExcludedNamespaces("ns-2").Result(), + apiResources: []*test.APIResource{ + test.Namespaces( + builder.ForNamespace("ns-1").Phase(corev1api.NamespaceActive).Result(), + builder.ForNamespace("ns-2").Phase(corev1api.NamespaceActive).Result(), + builder.ForNamespace("ns-3").Phase(corev1api.NamespaceActive).Result(), + ), + test.Deployments( + builder.ForDeployment("ns-1", "deploy-1").Result(), + builder.ForDeployment("ns-2", "deploy-2").Result(), + ), + }, + want: []string{ + "resources/namespaces/cluster/ns-1.json", + "resources/namespaces/v1-preferredversion/cluster/ns-1.json", + "resources/namespaces/cluster/ns-3.json", + "resources/namespaces/v1-preferredversion/cluster/ns-3.json", + "resources/deployments.apps/namespaces/ns-1/deploy-1.json", + "resources/deployments.apps/v1-preferredversion/namespaces/ns-1/deploy-1.json", + }, + }, { name: "Empty namespace test", backup: defaultBackup().IncludedNamespaces("invalid*").Result(), diff --git a/pkg/backup/item_collector.go b/pkg/backup/item_collector.go index f4c712921..3aade5fad 100644 --- a/pkg/backup/item_collector.go +++ b/pkg/backup/item_collector.go @@ -508,7 +508,8 @@ func (r *itemCollector) getResourceItems( kind: resource.Kind, }) - if item.GetNamespace() != "" { + if item.GetNamespace() != "" && + r.backupRequest.NamespaceIncludesExcludes.ShouldInclude(item.GetNamespace()) { log.Debugf("Track namespace %s in nsTracker", item.GetNamespace()) r.nsTracker.track(item.GetNamespace()) }