diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 429e4b0e549..8e5c016585d 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -42,6 +42,7 @@ https://github.com/elastic/beats/compare/v6.0.0-beta2...master[Check the HEAD di - Do not require template if index change and template disabled {pull}5319[5319] - Correctly send configured `Host` header to the remote server. {issue}4842[4842] - Fix missing ACK in redis output. {issue}5404[5404] +- Change add_kubernetes_metadata to attempt detection of namespace. {pull}5482[5482] *Auditbeat* diff --git a/libbeat/processors/add_kubernetes_metadata/config.go b/libbeat/processors/add_kubernetes_metadata/config.go index 6f1c1f0b898..adeba81a284 100644 --- a/libbeat/processors/add_kubernetes_metadata/config.go +++ b/libbeat/processors/add_kubernetes_metadata/config.go @@ -30,12 +30,11 @@ type Enabled struct { type PluginConfig []map[string]common.Config -func defaultKuberentesAnnotatorConfig() kubeAnnotatorConfig { +func defaultKubernetesAnnotatorConfig() kubeAnnotatorConfig { return kubeAnnotatorConfig{ InCluster: true, SyncPeriod: 1 * time.Second, CleanupTimeout: 60 * time.Second, - Namespace: "kube-system", DefaultMatchers: Enabled{true}, DefaultIndexers: Enabled{true}, } diff --git a/libbeat/processors/add_kubernetes_metadata/kubernetes.go b/libbeat/processors/add_kubernetes_metadata/kubernetes.go index a98b51a07ce..5780aa99cee 100644 --- a/libbeat/processors/add_kubernetes_metadata/kubernetes.go +++ b/libbeat/processors/add_kubernetes_metadata/kubernetes.go @@ -44,7 +44,7 @@ func init() { func newKubernetesAnnotator(cfg *common.Config) (processors.Processor, error) { cfgwarn.Beta("The kubernetes processor is beta") - config := defaultKuberentesAnnotatorConfig() + config := defaultKubernetesAnnotatorConfig() err := cfg.Unpack(&config) if err != nil { @@ -87,7 +87,7 @@ func newKubernetesAnnotator(cfg *common.Config) (processors.Processor, error) { if config.InCluster == true { client, err = k8s.NewInClusterClient() if err != nil { - return nil, fmt.Errorf("Unable to get in cluster configuration") + return nil, fmt.Errorf("Unable to get in cluster configuration: %v", err) } } else { data, err := ioutil.ReadFile(config.KubeConfig) @@ -109,11 +109,11 @@ func newKubernetesAnnotator(cfg *common.Config) (processors.Processor, error) { ctx := context.Background() if config.Host == "" { podName := os.Getenv("HOSTNAME") - logp.Info("Using pod name %s and namespace %s", podName, config.Namespace) + logp.Info("Using pod name %s and namespace %s", podName, client.Namespace) if podName == "localhost" { config.Host = "localhost" } else { - pod, error := client.CoreV1().GetPod(ctx, podName, config.Namespace) + pod, error := client.CoreV1().GetPod(ctx, podName, client.Namespace) if error != nil { logp.Err("Querying for pod failed with error: ", error.Error()) logp.Info("Unable to find pod, setting host to localhost")