@@ -434,19 +434,6 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
434434 }
435435 }
436436
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-
450437 for obj , byObject := range opts .ByObject {
451438 isNamespaced , err := apiutil .IsObjectNamespaced (obj , opts .Scheme , opts .Mapper )
452439 if err != nil {
@@ -500,6 +487,22 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
500487 opts .ByObject [obj ] = byObject
501488 }
502489
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+
503506 // Default the resync period to 10 hours if unset
504507 if opts .SyncPeriod == nil {
505508 opts .SyncPeriod = & defaultSyncPeriod
0 commit comments