From fcb20259d0d4cf74d9ef54d350bab39d8eba53ef Mon Sep 17 00:00:00 2001 From: Vijay Samuel Date: Mon, 16 Dec 2019 11:19:36 -0800 Subject: [PATCH] Incorporate review comments --- libbeat/autodiscover/providers/kubernetes/node.go | 3 +-- libbeat/autodiscover/providers/kubernetes/pod.go | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libbeat/autodiscover/providers/kubernetes/node.go b/libbeat/autodiscover/providers/kubernetes/node.go index 5125d4cded32..894133f3d121 100644 --- a/libbeat/autodiscover/providers/kubernetes/node.go +++ b/libbeat/autodiscover/providers/kubernetes/node.go @@ -21,8 +21,6 @@ import ( "fmt" "time" - "github.com/elastic/beats/libbeat/common/kubernetes/metadata" - "github.com/gofrs/uuid" v1 "k8s.io/api/core/v1" k8s "k8s.io/client-go/kubernetes" @@ -31,6 +29,7 @@ import ( "github.com/elastic/beats/libbeat/common" "github.com/elastic/beats/libbeat/common/bus" "github.com/elastic/beats/libbeat/common/kubernetes" + "github.com/elastic/beats/libbeat/common/kubernetes/metadata" "github.com/elastic/beats/libbeat/common/safemapstr" "github.com/elastic/beats/libbeat/logp" ) diff --git a/libbeat/autodiscover/providers/kubernetes/pod.go b/libbeat/autodiscover/providers/kubernetes/pod.go index a48ab2746f65..ee71f0a76736 100644 --- a/libbeat/autodiscover/providers/kubernetes/pod.go +++ b/libbeat/autodiscover/providers/kubernetes/pod.go @@ -78,10 +78,14 @@ func NewPodEventer(uuid uuid.UUID, cfg *common.Config, client k8s.Interface, pub metaConf := config.AddResourceMetadata if metaConf != nil { if metaConf.Node != nil && metaConf.Node.Enabled() { - nodeWatcher, err = kubernetes.NewWatcher(client, &kubernetes.Node{}, kubernetes.WatchOptions{ + options := kubernetes.WatchOptions{ SyncTimeout: config.SyncPeriod, Node: config.Node, - }, nil) + } + if config.Namespace != "" { + options.Namespace = config.Namespace + } + nodeWatcher, err = kubernetes.NewWatcher(client, &kubernetes.Node{}, options, nil) if err != nil { return nil, fmt.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Node{}, err) } @@ -97,7 +101,7 @@ func NewPodEventer(uuid uuid.UUID, cfg *common.Config, client k8s.Interface, pub return nil, fmt.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Namespace{}, err) } - nodeMeta = metadata.NewNamespaceMetadataGenerator(metaConf.Namespace, namespaceWatcher.Store()) + namespaceMeta = metadata.NewNamespaceMetadataGenerator(metaConf.Namespace, namespaceWatcher.Store()) } }