Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix 'make setup' instructions for a new beat {pull}24944[24944]
- Fix inode removal tracking code when files are replaced by files with the same name {pull}25002[25002]
- Fix `mage GenerateCustomBeat` instructions for a new beat {pull}17679[17679]
- Fix bug with annotations dedot config on k8s not used {pull}25111[25111]
- Fix negative Kafka partition bug {pull}25048[25048]

*Auditbeat*
Expand Down
65 changes: 61 additions & 4 deletions libbeat/common/kubernetes/metadata/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,67 @@ func TestPod_Generate(t *testing.T) {
},
},
},
{
name: "test object with owner reference to replicaset honors annotations.dedot: false",
input: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
UID: types.UID(uid),
Namespace: namespace,
Labels: map[string]string{
"foo": "bar",
},
Annotations: map[string]string{
"k8s.app": "production",
},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "apps",
Kind: "ReplicaSet",
Name: "nginx-rs",
UID: "005f3b90-4b9d-12f8-acf0-31020a8409087",
Controller: &boolean,
},
},
},
TypeMeta: metav1.TypeMeta{
Kind: "Pod",
APIVersion: "v1",
},
Spec: v1.PodSpec{
NodeName: "testnode",
},
Status: v1.PodStatus{PodIP: "127.0.0.5"},
},
output: common.MapStr{
"pod": common.MapStr{
"name": "obj",
"uid": uid,
"ip": "127.0.0.5",
},
"namespace": "default",
"deployment": common.MapStr{
"name": "nginx-deployment",
},
"replicaset": common.MapStr{
"name": "nginx-rs",
},
"node": common.MapStr{
"name": "testnode",
},
"labels": common.MapStr{
"foo": "bar",
},
"annotations": common.MapStr{
"k8s": common.MapStr{"app": "production"},
},
},
},
}

config, err := common.NewConfigFrom(map[string]interface{}{
"include_annotations": []string{"app"},
"include_annotations": []string{"app", "k8s.app"},
"annotations.dedot": false,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we have some other test case that would cover the default annotations.dedot: true?

Copy link
Copy Markdown
Member Author

@ChrsMark ChrsMark Apr 15, 2021

Choose a reason for hiding this comment

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

Unfortunately we had no test cases for these options. I can add one before merging (CI is red anyways)

})
assert.NoError(t, err)

Expand Down Expand Up @@ -283,7 +340,7 @@ func TestPod_GenerateFromName(t *testing.T) {
"foo": "bar",
},
Annotations: map[string]string{
"app": "production",
"k8s.app": "production",
},
},
TypeMeta: metav1.TypeMeta{
Expand All @@ -309,7 +366,7 @@ func TestPod_GenerateFromName(t *testing.T) {
"foo": "bar",
},
"annotations": common.MapStr{
"app": "production",
"k8s_app": "production",
},
},
},
Expand Down Expand Up @@ -370,7 +427,7 @@ func TestPod_GenerateFromName(t *testing.T) {

for _, test := range tests {
config, err := common.NewConfigFrom(map[string]interface{}{
"include_annotations": []string{"app"},
"include_annotations": []string{"app", "k8s.app"},
})
assert.NoError(t, err)
pods := cache.NewStore(cache.MetaNamespaceKeyFunc)
Expand Down
2 changes: 1 addition & 1 deletion libbeat/common/kubernetes/metadata/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (r *Resource) Generate(kind string, obj kubernetes.Resource, options ...Fie
labelMap.Delete(label)
}

annotationsMap := generateMapSubset(accessor.GetAnnotations(), r.config.IncludeAnnotations, r.config.LabelsDedot)
annotationsMap := generateMapSubset(accessor.GetAnnotations(), r.config.IncludeAnnotations, r.config.AnnotationsDedot)

meta := common.MapStr{
strings.ToLower(kind): common.MapStr{
Expand Down