Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #16480 to 7.6: Fix k8s pod labels tier in metadata #16547

Merged
merged 2 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Affecting all Beats*

- TLS or Beats that accept connections over TLS and validate client certificates. {pull}14146[14146]
- Fix panics that could result from invalid TLS certificates. This can affect Beats that connect over TLS, or Beats that accept connections over TLS and validate client certificates. {pull}14146[14146]
- Fix panic in the Logstash output when trying to send events to closed connection. {pull}15568[15568]
- Fix missing output in dockerlogbeat {pull}15719[15719]
- Fix logging target settings being ignored when Beats are started via systemd or docker. {issue}12024[12024] {pull}15422[15442]
- Do not load dashboards where not available. {pull}15802[15802]
- Fix issue where TLS settings would be ignored when a forward proxy was in use. {pull}15516{15516}
- Update replicaset group to apps/v1 {pull}15854[15802]
- Fix issue where default go logger is not discarded when either * or stdout is selected. {issue}10251[10251] {pull}15708[15708]
- Upgrade go-ucfg to latest v0.8.1. {pull}15937{15937}
- Fix index names for indexing not always guaranteed to be lower case. {pull}16081[16081]
- Add `ssl.ca_sha256` option to the supported TLS option, this allow to check that a specific certificate is used as part of the verified chain. {issue}15717[15717]
- Fix loading processors from annotation hints. {pull}16348[16348]
- Fix k8s pods labels broken schema. {pull}16480[16480]
- Upgrade go-ucfg to latest v0.8.3. {pull}16450{16450}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will need a clean up :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 as usual, hehe😅


*Auditbeat*

Expand Down
13 changes: 13 additions & 0 deletions libbeat/common/kubernetes/metadata/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func (p *pod) Generate(obj kubernetes.Resource, opts ...FieldOptions) common.Map
}

out := p.resource.Generate("pod", obj, opts...)
// TODO: remove this call when moving to 8.0
out = p.exportPodLabels(out)

if p.node != nil {
meta := p.node.GenerateFromName(po.Spec.NodeName)
Expand Down Expand Up @@ -89,3 +91,14 @@ func (p *pod) GenerateFromName(name string, opts ...FieldOptions) common.MapStr

return nil
}

func (p *pod) exportPodLabels(in common.MapStr) common.MapStr {
labels, err := in.GetValue("pod.labels")
if err != nil {
return in
}
in.Put("labels", labels)
in.Delete("pod.labels")

return in
}
30 changes: 15 additions & 15 deletions libbeat/common/kubernetes/metadata/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func TestPod_Generate(t *testing.T) {
"pod": common.MapStr{
"name": "obj",
"uid": uid,
"labels": common.MapStr{
"foo": "bar",
},
},
"labels": common.MapStr{
"foo": "bar",
},
"namespace": "default",
"node": common.MapStr{
Expand Down Expand Up @@ -110,9 +110,6 @@ func TestPod_Generate(t *testing.T) {
"pod": common.MapStr{
"name": "obj",
"uid": uid,
"labels": common.MapStr{
"foo": "bar",
},
},
"namespace": "default",
"deployment": common.MapStr{
Expand All @@ -121,6 +118,9 @@ func TestPod_Generate(t *testing.T) {
"node": common.MapStr{
"name": "testnode",
},
"labels": common.MapStr{
"foo": "bar",
},
},
},
}
Expand Down Expand Up @@ -168,14 +168,14 @@ func TestPod_GenerateFromName(t *testing.T) {
"pod": common.MapStr{
"name": "obj",
"uid": uid,
"labels": common.MapStr{
"foo": "bar",
},
},
"namespace": "default",
"node": common.MapStr{
"name": "testnode",
},
"labels": common.MapStr{
"foo": "bar",
},
},
},
{
Expand Down Expand Up @@ -211,9 +211,6 @@ func TestPod_GenerateFromName(t *testing.T) {
"pod": common.MapStr{
"name": "obj",
"uid": uid,
"labels": common.MapStr{
"foo": "bar",
},
},
"namespace": "default",
"deployment": common.MapStr{
Expand All @@ -222,6 +219,9 @@ func TestPod_GenerateFromName(t *testing.T) {
"node": common.MapStr{
"name": "testnode",
},
"labels": common.MapStr{
"foo": "bar",
},
},
},
}
Expand Down Expand Up @@ -304,9 +304,6 @@ func TestPod_GenerateWithNodeNamespace(t *testing.T) {
"pod": common.MapStr{
"name": "obj",
"uid": uid,
"labels": common.MapStr{
"foo": "bar",
},
},
"namespace": "default",
"namespace_uid": uid,
Expand All @@ -320,6 +317,9 @@ func TestPod_GenerateWithNodeNamespace(t *testing.T) {
"nodekey": "nodevalue",
},
},
"labels": common.MapStr{
"foo": "bar",
},
},
},
}
Expand Down
30 changes: 15 additions & 15 deletions libbeat/processors/add_kubernetes_metadata/indexers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func TestPodIndexer(t *testing.T) {
"pod": common.MapStr{
"name": "testpod",
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
"labels": common.MapStr{
"labelkey": "labelvalue",
},
},
"labels": common.MapStr{
"labelkey": "labelvalue",
},
"namespace": "testns",
"node": common.MapStr{
Expand Down Expand Up @@ -117,14 +117,14 @@ func TestPodUIDIndexer(t *testing.T) {
"pod": common.MapStr{
"name": "testpod",
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
"labels": common.MapStr{
"labelkey": "labelvalue",
},
},
"namespace": "testns",
"node": common.MapStr{
"name": "testnode",
},
"labels": common.MapStr{
"labelkey": "labelvalue",
},
}

assert.Equal(t, expected.String(), indexers[0].Data.String())
Expand Down Expand Up @@ -173,14 +173,14 @@ func TestContainerIndexer(t *testing.T) {
"pod": common.MapStr{
"name": "testpod",
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
"labels": common.MapStr{
"labelkey": "labelvalue",
},
},
"namespace": "testns",
"node": common.MapStr{
"name": "testnode",
},
"labels": common.MapStr{
"labelkey": "labelvalue",
},
}
container1 := "docker://abcde"
pod.Spec.NodeName = nodeName
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestFilteredGenMeta(t *testing.T) {
indexers := podIndexer.GetMetadata(&pod)
assert.Equal(t, len(indexers), 1)

rawLabels, _ := indexers[0].Data.GetValue("pod.labels")
rawLabels, _ := indexers[0].Data.GetValue("labels")
assert.NotNil(t, rawLabels)

labelMap, ok := rawLabels.(common.MapStr)
Expand All @@ -274,7 +274,7 @@ func TestFilteredGenMeta(t *testing.T) {
indexers = podIndexer.GetMetadata(&pod)
assert.Equal(t, len(indexers), 1)

rawLabels, _ = indexers[0].Data.GetValue("pod.labels")
rawLabels, _ = indexers[0].Data.GetValue("labels")
assert.NotNil(t, rawLabels)

labelMap, ok = rawLabels.(common.MapStr)
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestFilteredGenMetaExclusion(t *testing.T) {
indexers := podIndexer.GetMetadata(&pod)
assert.Equal(t, len(indexers), 1)

rawLabels, _ := indexers[0].Data.GetValue("pod.labels")
rawLabels, _ := indexers[0].Data.GetValue("labels")
assert.NotNil(t, rawLabels)

labelMap, ok := rawLabels.(common.MapStr)
Expand Down Expand Up @@ -392,14 +392,14 @@ func TestIpPortIndexer(t *testing.T) {
"pod": common.MapStr{
"name": "testpod",
"uid": "005f3b90-4b9d-12f8-acf0-31020a840133",
"labels": common.MapStr{
"labelkey": "labelvalue",
},
},
"namespace": "testns",
"node": common.MapStr{
"name": "testnode",
},
"labels": common.MapStr{
"labelkey": "labelvalue",
},
}

pod.Spec.Containers = []v1.Container{
Expand Down