Fix excluded namespace objects leaking into backup with cross-namespa… (#10159)

* Fix excluded namespace objects leaking into backup with cross-namespace listing

Signed-off-by: Pragati <Pragati5-DEBUG@users.noreply.github.com>

* Add changelog for PR 10159

Signed-off-by: Pragati <Pragati5-DEBUG@users.noreply.github.com>

---------

Signed-off-by: Pragati <Pragati5-DEBUG@users.noreply.github.com>
Co-authored-by: Pragati <Pragati5-DEBUG@users.noreply.github.com>
This commit is contained in:
PragatiVerma111
2026-08-09 10:15:29 -05:00
committed by GitHub
co-authored by Pragati
parent 7346ec527c
commit 22ae12575c
3 changed files with 26 additions and 1 deletions
@@ -0,0 +1 @@
Fix excluded namespace objects leaking into backups when using cross-namespace listing
+23
View File
@@ -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(),
+2 -1
View File
@@ -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())
}