@@ -484,18 +484,33 @@ func createInformerFactory(clientset kubernetes.Interface, namespace string, exc
484484 var factory informers.SharedInformerFactory
485485 switch {
486486 case namespace != "" :
487+ slog .Info ("Namespace to watch" ,
488+ "namespace" ,
489+ namespace ,
490+ )
487491 factory = informers .NewSharedInformerFactoryWithOptions (
488492 clientset ,
489493 30 * time .Second ,
490494 informers .WithNamespace (namespace ),
491495 )
492496 case excludeNamespaces != "" :
493- excludedNamespacesList := strings .Split (excludeNamespaces , "," )
494- for i := 0 ; i < len (excludedNamespacesList ); i ++ {
495- excludedNamespacesList [i ] = fmt .Sprintf ("metadata.namespace!=%s" , strings .TrimSpace (excludedNamespacesList [i ]))
497+ seenNamespaces := make (map [string ]bool )
498+ fieldSelectorParts := make ([]string , 0 )
499+
500+ for _ , ns := range strings .Split (excludeNamespaces , "," ) {
501+ ns = strings .TrimSpace (ns )
502+ if ns != "" && ! seenNamespaces [ns ] {
503+ seenNamespaces [ns ] = true
504+ fieldSelectorParts = append (fieldSelectorParts , fmt .Sprintf ("metadata.namespace!=%s" , ns ))
505+ }
496506 }
507+
508+ slog .Info ("Excluding namespaces from watch" ,
509+ "field_selector" ,
510+ strings .Join (fieldSelectorParts , "," ),
511+ )
497512 tweakListOptions := func (options * metav1.ListOptions ) {
498- options .FieldSelector = strings .Join (excludedNamespacesList , "," )
513+ options .FieldSelector = strings .Join (fieldSelectorParts , "," )
499514 }
500515
501516 factory = informers .NewSharedInformerFactoryWithOptions (
0 commit comments