From 10ea526a9e1fe1e75d68cb36ab39ad2834208de1 Mon Sep 17 00:00:00 2001 From: chrismark Date: Tue, 26 Jan 2021 22:29:27 +0200 Subject: [PATCH] fixes and changelog Signed-off-by: chrismark --- CHANGELOG.next.asciidoc | 1 + libbeat/common/kubernetes/metadata/pod.go | 6 ++++-- libbeat/common/kubernetes/metadata/pod_test.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 0480d59e246f..6fc3100acd8e 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -598,6 +598,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Update the baseline version of Sarama (Kafka support library) to 1.27.2. {pull}23595[23595] - Add kubernetes.volume.fs.used.pct field. {pull}23564[23564] - Add the `enable_krb5_fast` flag to the Kafka output to explicitly opt-in to FAST authentication. {pull}23629[23629] +- Add deployment name in pod's meta. {pull}23610[23610] *Auditbeat* diff --git a/libbeat/common/kubernetes/metadata/pod.go b/libbeat/common/kubernetes/metadata/pod.go index 5e2d2439151f..991d946be750 100644 --- a/libbeat/common/kubernetes/metadata/pod.go +++ b/libbeat/common/kubernetes/metadata/pod.go @@ -63,8 +63,7 @@ func (p *pod) Generate(obj kubernetes.Resource, opts ...FieldOptions) common.Map // check if Pod is handled by a ReplicaSet which is controlled by a Deployment rsName, _ := out.GetValue("replicaset.name") - if rsName != nil { - rsName := rsName.(string) + if rsName, ok := rsName.(string); ok { dep := p.getRSDeployment(rsName, po.GetNamespace()) if dep != "" { out.Put("deployment.name", dep) @@ -114,6 +113,9 @@ func (p *pod) GenerateFromName(name string, opts ...FieldOptions) common.MapStr // getRSDeployment return the name of the Deployment object that // owns the ReplicaSet with the given name under the given Namespace func (p *pod) getRSDeployment(rsName string, ns string) string { + if p.client == nil { + return "" + } rs, err := p.client.AppsV1().ReplicaSets(ns).Get(context.TODO(), rsName, metav1.GetOptions{}) if err != nil { return "" diff --git a/libbeat/common/kubernetes/metadata/pod_test.go b/libbeat/common/kubernetes/metadata/pod_test.go index 47041f6896bf..52186a8ae727 100644 --- a/libbeat/common/kubernetes/metadata/pod_test.go +++ b/libbeat/common/kubernetes/metadata/pod_test.go @@ -87,7 +87,7 @@ func TestPod_Generate(t *testing.T) { }, } - _, err := client.AppsV1().ReplicaSets(namespace).Create(context.TODO(), rs, metav1.CreateOptions{}) + _, err := client.AppsV1().ReplicaSets(namespace).Create(context.Background(), rs, metav1.CreateOptions{}) if err != nil { t.Fatalf("failed to create k8s deployment: %v", err) }