diff --git a/libbeat/autodiscover/providers/kubernetes/pod.go b/libbeat/autodiscover/providers/kubernetes/pod.go index 425459308845..6e96666161f1 100644 --- a/libbeat/autodiscover/providers/kubernetes/pod.go +++ b/libbeat/autodiscover/providers/kubernetes/pod.go @@ -88,13 +88,13 @@ func NewPodEventer(uuid uuid.UUID, cfg *common.Config, client k8s.Interface, pub } 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) + logger.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Node{}, err) } namespaceWatcher, err := kubernetes.NewWatcher(client, &kubernetes.Namespace{}, kubernetes.WatchOptions{ SyncTimeout: config.SyncPeriod, }, nil) if err != nil { - return nil, fmt.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Namespace{}, err) + logger.Errorf("couldn't create watcher for %T due to error %+v", &kubernetes.Namespace{}, err) } metaGen := metadata.GetPodMetaGen(cfg, watcher, nodeWatcher, namespaceWatcher, metaConf) diff --git a/libbeat/common/kubernetes/metadata/metadata.go b/libbeat/common/kubernetes/metadata/metadata.go index cf1ae9452485..e1cbd0e86293 100644 --- a/libbeat/common/kubernetes/metadata/metadata.go +++ b/libbeat/common/kubernetes/metadata/metadata.go @@ -60,8 +60,13 @@ func GetPodMetaGen( namespaceWatcher kubernetes.Watcher, metaConf *AddResourceMetadataConfig) MetaGen { - nodeMetaGen := NewNodeMetadataGenerator(metaConf.Node, nodeWatcher.Store()) - namespaceMetaGen := NewNamespaceMetadataGenerator(metaConf.Namespace, namespaceWatcher.Store()) + var nodeMetaGen, namespaceMetaGen MetaGen + if nodeWatcher != nil { + nodeMetaGen = NewNodeMetadataGenerator(metaConf.Node, nodeWatcher.Store()) + } + if namespaceWatcher != nil { + namespaceMetaGen = NewNamespaceMetadataGenerator(metaConf.Namespace, namespaceWatcher.Store()) + } metaGen := NewPodMetadataGenerator(cfg, podWatcher.Store(), nodeMetaGen, namespaceMetaGen) return metaGen diff --git a/libbeat/processors/add_kubernetes_metadata/kubernetes.go b/libbeat/processors/add_kubernetes_metadata/kubernetes.go index 90d4b393d65a..2ca864a5bcfa 100644 --- a/libbeat/processors/add_kubernetes_metadata/kubernetes.go +++ b/libbeat/processors/add_kubernetes_metadata/kubernetes.go @@ -220,13 +220,17 @@ func (k *kubernetesAnnotator) init(config kubeAnnotatorConfig, cfg *common.Confi // NOTE: order is important here since pod meta will include node meta and hence node.Store() should // be populated before trying to generate metadata for Pods. - if err := nodeWatcher.Start(); err != nil { - k.log.Debugf("add_kubernetes_metadata", "Couldn't start node watcher: %v", err) - return + if nodeWatcher != nil { + if err := nodeWatcher.Start(); err != nil { + k.log.Debugf("add_kubernetes_metadata", "Couldn't start node watcher: %v", err) + return + } } - if err := namespaceWatcher.Start(); err != nil { - k.log.Debugf("add_kubernetes_metadata", "Couldn't start namespace watcher: %v", err) - return + if namespaceWatcher != nil { + if err := namespaceWatcher.Start(); err != nil { + k.log.Debugf("add_kubernetes_metadata", "Couldn't start namespace watcher: %v", err) + return + } } if err := watcher.Start(); err != nil { k.log.Debugf("add_kubernetes_metadata", "Couldn't start pod watcher: %v", err)