Skip to content

Commit 7e4b0ae

Browse files
committed
address comments
1 parent 0a6ed1e commit 7e4b0ae

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

cmd/deployment-tracker/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949

5050
// Cannot use both
5151
if namespace != "" && excludeNamespaces != "" {
52-
slog.Error("Cannot set both --namespace and --exclude-namespace")
52+
slog.Error("Cannot set both -namespace and -exclude-namespaces")
5353
os.Exit(1)
5454
}
5555

internal/controller/controller.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)