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

Fix k8s pod labels tier in metadata #16480

Merged
merged 4 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
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
Copy link
Contributor

Choose a reason for hiding this comment

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

I thinks it's fair to create an issue for removing this TODO ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, that said. I'm not quite convinced this is the way to go. Let's move this fix forward and discuss future steps in the opened issue

out = p.fixLabels(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) fixLabels(in common.MapStr) common.MapStr {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm.. "fix" says nothing about the behavior. Could you rename this method to sth less vague? movePodLabels, extractPodLabel, etc.

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