@@ -56,6 +56,7 @@ The primary change occurs in `pkg/backup/item_collector.go` in the `nsTracker.in
5656Currently, this method tracks namespaces for filtering but doesn't change the fundamental inclusion behavior.
5757
5858** Current behavior:**
59+
5960``` go
6061// Namespace matches selector -> track for resource filtering only
6162if nt.singleLabelSelector != nil && nt.singleLabelSelector .Matches (labels.Set (namespace.GetLabels ())) {
@@ -64,6 +65,7 @@ if nt.singleLabelSelector != nil && nt.singleLabelSelector.Matches(labels.Set(na
6465```
6566
6667** New behavior:**
68+
6769``` go
6870// Namespace matches selector -> track AND include all resources in namespace
6971if nt.singleLabelSelector != nil && nt.singleLabelSelector .Matches (labels.Set (namespace.GetLabels ())) {
@@ -77,16 +79,19 @@ if nt.singleLabelSelector != nil && nt.singleLabelSelector.Matches(labels.Set(na
7779Full Kubernetes label selector support including:
7880
7981** Equality-based requirements:**
82+
8083- ` key=value ` (equality)
8184- ` key!=value ` (inequality)
8285
8386** Set-based requirements:**
87+
8488- ` key in (value1,value2) ` (set inclusion)
8589- ` key notin (value1,value2) ` (set exclusion)
8690- ` key ` (key exists)
8791- ` !key ` (key does not exist)
8892
8993** MatchExpressions support:**
94+
9095``` yaml
9196labelSelector :
9297 matchLabels :
@@ -102,6 +107,7 @@ labelSelector:
102107### API Schema (No Changes Required)
103108
104109The existing ` BackupSpec` already supports the required fields:
110+
105111` ` ` go
106112type BackupSpec struct {
107113 // ... existing fields ...
@@ -113,6 +119,7 @@ type BackupSpec struct {
113119### Example Usage Scenarios
114120
115121#### Scenario 1: Basic Environment-Based Backup
122+
116123``` yaml
117124apiVersion : velero.io/v1
118125kind : Backup
@@ -123,9 +130,11 @@ spec:
123130 matchLabels :
124131 environment : production
125132` ` `
133+
126134Result: All namespaces with ` environment=production` are completely backed up.
127135
128136# ### Scenario 2: Complex Selection with Exclusions
137+
129138` ` ` yaml
130139spec:
131140 includedNamespaces: ["critical-ns"]
@@ -138,9 +147,11 @@ spec:
138147 operator: DoesNotExist
139148 excludedNamespaces: ["temp-ns"]
140149` ` `
150+
141151Result : ` critical-ns` + (namespaces with `backup-tier` in daily/weekly AND no `deprecated` label) - `temp-ns`.
142152
143153# ### Scenario 3: OrLabelSelectors Usage
154+
144155` ` ` yaml
145156spec:
146157 orLabelSelectors:
@@ -150,13 +161,14 @@ spec:
150161 critical: "true"
151162 environment: "production"
152163` ` `
164+
153165Result : Namespaces with `backup=true` OR (`critical=true` AND `environment=production`).
154166
155167# ## Logging and Observability
156168
157169Enhanced logging will provide clear visibility into namespace selection :
158170
159- ` ` `
171+ ` ` ` sh
160172INFO Backup namespace selection:
161173 Explicitly included: [ns1, ns2]
162174 Selected by labelSelector 'environment=production': [ns3, ns4]
@@ -166,6 +178,7 @@ INFO Backup namespace selection:
166178` ` `
167179
168180Backup status will include selected namespace information :
181+
169182` ` ` yaml
170183status:
171184 phase: Completed
@@ -179,43 +192,51 @@ status:
179192# ## Validation and Warnings
180193
181194Warning messages for potentially confusing configurations :
195+
182196- " Namespace 'ns2' is both explicitly included and excluded - exclusion takes precedence"
183197- " Using both labelSelector and orLabelSelectors - both will be evaluated"
184198- " Complex label selectors may select unexpected namespaces - verify selection before running"
185199
186200# ## Breaking Change Considerations
187201
188202This is a **breaking change** from current behavior :
203+
189204- Existing backups using `labelSelector` will include more resources
190205- Backup size and duration may increase
191206- Current behavior has limited practical value, reducing migration impact
192207
193208Migration considerations :
209+
194210- Document change prominently in release notes
195211- Provide before/after examples
196212- Consider deprecation warning in prior version
197213
198214# # Alternatives Considered
199215
200216# ## Alternative 1: New NamespaceSelector Field
217+
201218` ` ` go
202219type BackupSpec struct {
203220 NamespaceSelector *metav1.LabelSelector ` json:"namespaceSelector,omitempty"`
204221}
205222```
223+
206224** Pros:** No breaking changes, clear separation of concerns
207225** Cons:** Adds API complexity, community feedback against new fields
208226
209227### Alternative 2: Boolean Flag to Change Behavior
228+
210229``` go
211230type BackupSpec struct {
212231 IncludeResourcesInLabeledNamespaces *bool ` json:"includeResourcesInLabeledNamespaces,omitempty"`
213232}
214233```
234+
215235** Pros:** Backward compatible, explicit opt-in
216236** Cons:** Complex configuration, confusing API surface
217237
218238### Alternative 3: Separate Namespace and Resource Selectors
239+
219240Keep existing ` labelSelector ` for resources, add ` namespaceSelector ` for namespaces.
220241** Cons:** Most complex option, unclear interaction patterns
221242
@@ -224,36 +245,44 @@ Keep existing `labelSelector` for resources, add `namespaceSelector` for namespa
224245## Security Considerations
225246
226247### RBAC Implications
248+
227249Users with permission to modify backup specs can now potentially backup additional namespaces through label manipulation.
228250Existing RBAC controls on backup resources remain the primary security boundary.
229251
230252### Label-based Access Control
253+
231254Organizations using label-based policies should ensure backup service accounts have appropriate namespace and resource access.
232255No additional privileges are required beyond current backup operations.
233256
234257### Sensitive Data Exposure
258+
235259The expanded scope of backups may include additional sensitive data.
236260Users should audit namespace labels and exclusion rules to prevent unintended data exposure.
237261
238262## Compatibility
239263
240264### Backward Compatibility
265+
241266** Breaking Change:** Existing backups using ` labelSelector ` will behave differently.
242267Impact assessment:
268+
243269- Current ` labelSelector ` usage is limited due to reduced utility
244270- Most users already avoid this pattern in favor of explicit namespace listing
245271- Change aligns behavior with user expectations
246272
247273### API Compatibility
274+
248275No API schema changes required.
249276Existing backup configurations remain syntactically valid but may produce different results.
250277
251278### Velero Version Compatibility
279+
252280- Backups created with new behavior remain compatible with older Velero versions for restore
253281- Backup metadata format unchanged
254282- No changes to backup storage format
255283
256284### Kubernetes Version Compatibility
285+
257286No changes to Kubernetes version requirements.
258287Label selector functionality leverages existing Kubernetes APIs.
259288
@@ -273,44 +302,29 @@ Label selector functionality leverages existing Kubernetes APIs.
273302### Testing Strategy
274303
275304** Unit Tests:**
305+
276306- Namespace selection algorithm with all operator combinations
277307- Precedence rules with various include/exclude patterns
278308- Edge cases (empty selectors, wildcard usage, non-existent namespaces)
279309
280310** Integration Tests:**
311+
281312- Backup creation with namespace selectors
282313- Verification of complete namespace resource inclusion
283314- Backup status and logging validation
284315
285316** E2E Tests:**
317+
286318- Multi-namespace backup/restore scenarios
287319- Cross-cluster restore operations
288- - Performance testing with large namespace counts
289-
290- ### Resources
291-
292- - ** Primary Developer:** Tiger Kaovilai (@kaovilai )
293- - ** Reviewers:** Daniel Jiang, blackpiglet, shubham-pampattiwar
294- - ** Target Release:** Velero v1.18
295- - ** Estimated Effort:** 6 weeks total development + testing
296320
297321## Open Issues
298322
299323### Issue 1: Performance Impact with Large Cluster
324+
300325Large clusters with many namespaces may experience performance degradation during label selector evaluation.
301326** Potential Solution:** Implement caching for namespace label queries, optimize selector evaluation.
302327
303- ### Issue 2: Label Change Detection
304- Currently, Velero doesn't re-evaluate namespace selection if labels change between backup creation and execution.
305- ** Potential Solution:** Document current behavior, consider future enhancement for dynamic re-evaluation.
328+ ### Issue 2: Complex Selector User Education
306329
307- ### Issue 3: Complex Selector User Education
308330Users may create overly complex selectors that are difficult to understand or maintain.
309- ** Potential Solution:** Provide comprehensive documentation, examples, and possibly a selector validation tool.
310-
311- ### Issue 4: Interaction with Other Velero Features
312- Need to verify behavior interaction with:
313- - Resource policies
314- - Item actions and plugins
315- - Hooks and pre/post backup operations
316- ** Status:** Requires additional analysis and testing during implementation.
0 commit comments