@@ -419,19 +419,6 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
419419 }
420420 }
421421
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-
435422 for obj , byObject := range opts .ByObject {
436423 isNamespaced , err := apiutil .IsObjectNamespaced (obj , opts .Scheme , opts .Mapper )
437424 if err != nil {
@@ -485,6 +472,22 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
485472 opts .ByObject [obj ] = byObject
486473 }
487474
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+
488491 // Default the resync period to 10 hours if unset
489492 if opts .SyncPeriod == nil {
490493 opts .SyncPeriod = & defaultSyncPeriod
0 commit comments