From 077bb6654c67005a46bee5d9c17c8df4d3fd1249 Mon Sep 17 00:00:00 2001 From: Mustafa Akin Date: Mon, 22 Jun 2020 18:28:11 +0300 Subject: [PATCH] Namespace support to work without cluster scope, fixes #42 --- config.example.yaml | 1 + config.yaml | 3 ++- main.go | 2 +- pkg/exporter/config.go | 1 + pkg/kube/watcher.go | 4 ++-- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/config.example.yaml b/config.example.yaml index 56deaf54..21300a7f 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -1,5 +1,6 @@ logLevel: debug logFormat: json +# namespace: my-namespace-only # Omitting it defaults to all namespaces. route: # Main route routes: diff --git a/config.yaml b/config.yaml index 66d03716..12de81fd 100644 --- a/config.yaml +++ b/config.yaml @@ -1,5 +1,6 @@ logLevel: error logFormat: json +# namespace: tekton-pipelines route: routes: - match: @@ -7,4 +8,4 @@ route: receivers: - name: "dump" file: - path: "/tmp/deneme1" \ No newline at end of file + path: "/dev/stdout" \ No newline at end of file diff --git a/main.go b/main.go index 68cedfa1..aa971b2a 100644 --- a/main.go +++ b/main.go @@ -63,7 +63,7 @@ func main() { } engine := exporter.NewEngine(&cfg, &exporter.ChannelBasedReceiverRegistry{}) - w := kube.NewEventWatcher(kubeconfig, engine.OnEvent) + w := kube.NewEventWatcher(kubeconfig, cfg.Namespace, engine.OnEvent) ctx, cancel := context.WithCancel(context.Background()) leaderLost := make(chan bool) diff --git a/pkg/exporter/config.go b/pkg/exporter/config.go index 674909e7..4a799083 100644 --- a/pkg/exporter/config.go +++ b/pkg/exporter/config.go @@ -12,6 +12,7 @@ type Config struct { // TODO: I am not sure what to do here. LogLevel string `yaml:"logLevel"` LogFormat string `yaml:"logFormat"` + Namespace string `yaml:"namespace"` LeaderElection kube.LeaderElectionConfig `yaml:"leaderElection"` Route Route `yaml:"route"` Receivers []sinks.ReceiverConfig `yaml:"receivers"` diff --git a/pkg/kube/watcher.go b/pkg/kube/watcher.go index ad3c8cea..0fcb6e21 100644 --- a/pkg/kube/watcher.go +++ b/pkg/kube/watcher.go @@ -20,9 +20,9 @@ type EventWatcher struct { fn EventHandler } -func NewEventWatcher(config *rest.Config, fn EventHandler) *EventWatcher { +func NewEventWatcher(config *rest.Config, namespace string, fn EventHandler) *EventWatcher { clientset := kubernetes.NewForConfigOrDie(config) - factory := informers.NewSharedInformerFactory(clientset, 0) + factory := informers.NewSharedInformerFactoryWithOptions(clientset, 0, informers.WithNamespace(namespace)) informer := factory.Core().V1().Events().Informer() watcher := &EventWatcher{