@@ -419,19 +419,6 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
419
419
}
420
420
}
421
421
422
- for namespace , cfg := range opts .DefaultNamespaces {
423
- cfg = defaultConfig (cfg , optionDefaultsToConfig (& opts ))
424
- if namespace == metav1 .NamespaceAll {
425
- cfg .FieldSelector = fields .AndSelectors (
426
- appendIfNotNil (
427
- namespaceAllSelector (maps .Keys (opts .DefaultNamespaces )),
428
- cfg .FieldSelector ,
429
- )... ,
430
- )
431
- }
432
- opts .DefaultNamespaces [namespace ] = cfg
433
- }
434
-
435
422
for obj , byObject := range opts .ByObject {
436
423
isNamespaced , err := apiutil .IsObjectNamespaced (obj , opts .Scheme , opts .Mapper )
437
424
if err != nil {
@@ -485,6 +472,22 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
485
472
opts .ByObject [obj ] = byObject
486
473
}
487
474
475
+ // Default namespaces after byObject has been defaulted, otherwise a namespace without selectors
476
+ // will get the `Default` selectors, then get copied to byObject and then not get defaulted from
477
+ // byObject, as it already has selectors.
478
+ for namespace , cfg := range opts .DefaultNamespaces {
479
+ cfg = defaultConfig (cfg , optionDefaultsToConfig (& opts ))
480
+ if namespace == metav1 .NamespaceAll {
481
+ cfg .FieldSelector = fields .AndSelectors (
482
+ appendIfNotNil (
483
+ namespaceAllSelector (maps .Keys (opts .DefaultNamespaces )),
484
+ cfg .FieldSelector ,
485
+ )... ,
486
+ )
487
+ }
488
+ opts .DefaultNamespaces [namespace ] = cfg
489
+ }
490
+
488
491
// Default the resync period to 10 hours if unset
489
492
if opts .SyncPeriod == nil {
490
493
opts .SyncPeriod = & defaultSyncPeriod
0 commit comments