design/Implemented/wildcard-namespace-support-design.md
Velero currently treats namespace patterns with glob characters as literal strings. This design adds wildcard expansion to support flexible namespace selection using patterns like app-* or test-{dev,staging}.
Requested in #1874 for more flexible namespace selection.
* behaviorWildcard expansion occurs early in both backup and restore flows, converting patterns to literal namespace lists before normal processing.
Expansion happens in getResourceItems() before namespace collection:
ShouldExpandWildcards()Expansion occurs in execute() after parsing backup contents:
This ensures restore wildcards match actual backup contents, not current cluster state.
Add wildcard expansion tracking to backup and restore CRDs:
type WildcardNamespaceStatus struct {
// IncludeWildcardMatches records namespaces that matched include patterns
// +optional
IncludeWildcardMatches []string `json:"includeWildcardMatches,omitempty"`
// ExcludeWildcardMatches records namespaces that matched exclude patterns
// +optional
ExcludeWildcardMatches []string `json:"excludeWildcardMatches,omitempty"`
// WildcardResult records final namespaces after wildcard processing
// +optional
WildcardResult []string `json:"wildcardResult,omitempty"`
}
// Added to both BackupStatus and RestoreStatus
type BackupStatus struct {
// WildcardNamespaces contains wildcard expansion results
// +optional
WildcardNamespaces *WildcardNamespaceStatus `json:"wildcardNamespaces,omitempty"`
}
New pkg/util/wildcard/expand.go package provides:
ShouldExpandWildcards() - Skip expansion for simple "*" caseExpandWildcards() - Main expansion function using github.com/gobwas/globSupported patterns: *, ?, [abc], {a,b,c}
Unsupported: |(), **
pkg/backup/item_collector.go)Expansion in getResourceItems():
wildcard.ExpandWildcards() with cluster namespacesNamespaceIncludesExcludes with expanded resultspkg/restore/restore.go)Expansion in execute():
if wildcard.ShouldExpandWildcards(includes, excludes) {
availableNamespaces := extractNamespacesFromBackup(backupResources)
expandedIncludes, expandedExcludes, err := wildcard.ExpandWildcards(
availableNamespaces, includes, excludes)
// Update context and status
}
collectNamespaces: Rejected because these functions expect literal namespacesMaintains full backward compatibility - existing "*" behavior unchanged.
Target: Velero 1.18