Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/9684-Joeavaikath
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix wildcard expansion when includes is empty and excludes has wildcards
10 changes: 10 additions & 0 deletions pkg/util/collections/includes_excludes.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ func (nie *NamespaceIncludesExcludes) ExpandIncludesExcludes() error {
return err
}

// Empty includes means "include all", so normalize to "*" to
// prevent the wildcardExpanded+empty guard from excluding
// everything, and to match the CLI path's behavior.
// Note: Namespace CRs for excluded namespaces will still be
// backed up — this is intentional Velero behavior (see
// item_backupper.go itemInclusionChecks).
if len(includes) == 0 {
expandedIncludes = []string{"*"}
Comment thread
Joeavaikath marked this conversation as resolved.
Outdated
}

nie.SetIncludes(expandedIncludes)
nie.SetExcludes(expandedExcludes)
nie.wildcardExpanded = true
Expand Down
16 changes: 16 additions & 0 deletions pkg/util/collections/includes_excludes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,22 @@ func TestNamespaceIncludesExcludesShouldIncludeAfterWildcardExpansion(t *testing
testNamespace: "default",
expectedResult: true,
},
{
name: "empty includes with wildcard excludes - should include non-matching namespace",
includes: []string{},
excludes: []string{"test-backup*"},
activeNamespaces: []string{"default", "kube-system", "test-backup-ns1", "test-backup-ns2"},
testNamespace: "default",
expectedResult: true,
},
{
name: "empty includes with wildcard excludes - should exclude matching namespace",
includes: []string{},
excludes: []string{"test-backup*"},
activeNamespaces: []string{"default", "kube-system", "test-backup-ns1", "test-backup-ns2"},
testNamespace: "test-backup-ns1",
expectedResult: false,
},
}

for _, tc := range tests {
Expand Down
Loading