@@ -434,19 +434,6 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
434
434
}
435
435
}
436
436
437
- for namespace , cfg := range opts .DefaultNamespaces {
438
- cfg = defaultConfig (cfg , optionDefaultsToConfig (& opts ))
439
- if namespace == metav1 .NamespaceAll {
440
- cfg .FieldSelector = fields .AndSelectors (
441
- appendIfNotNil (
442
- namespaceAllSelector (maps .Keys (opts .DefaultNamespaces )),
443
- cfg .FieldSelector ,
444
- )... ,
445
- )
446
- }
447
- opts .DefaultNamespaces [namespace ] = cfg
448
- }
449
-
450
437
for obj , byObject := range opts .ByObject {
451
438
isNamespaced , err := apiutil .IsObjectNamespaced (obj , opts .Scheme , opts .Mapper )
452
439
if err != nil {
@@ -500,6 +487,22 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
500
487
opts .ByObject [obj ] = byObject
501
488
}
502
489
490
+ // Default namespaces after byObject has been defaulted, otherwise a namespace without selectors
491
+ // will get the `Default` selectors, then get copied to byObject and then not get defaulted from
492
+ // byObject, as it already has selectors.
493
+ for namespace , cfg := range opts .DefaultNamespaces {
494
+ cfg = defaultConfig (cfg , optionDefaultsToConfig (& opts ))
495
+ if namespace == metav1 .NamespaceAll {
496
+ cfg .FieldSelector = fields .AndSelectors (
497
+ appendIfNotNil (
498
+ namespaceAllSelector (maps .Keys (opts .DefaultNamespaces )),
499
+ cfg .FieldSelector ,
500
+ )... ,
501
+ )
502
+ }
503
+ opts .DefaultNamespaces [namespace ] = cfg
504
+ }
505
+
503
506
// Default the resync period to 10 hours if unset
504
507
if opts .SyncPeriod == nil {
505
508
opts .SyncPeriod = & defaultSyncPeriod
0 commit comments