Skip to content

Commit

Permalink
Add daemonset name in pods controlled by DaemonSets (#26808)
Browse files Browse the repository at this point in the history
* Add daemonset name in pods controller by DaemonSets

(cherry picked from commit 4933aef)
  • Loading branch information
MichaelKatsoulis authored and mergify-bot committed Jul 9, 2021
1 parent 8433e97 commit be6870d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Remove id_field_data {pull}25239[25239]
- Removed beats central management {pull}25696[25696], {issue}23908[23908]
- MacOSX minimum supported version set to 10.14 {issue}24193{24193}
- Add daemonset.name in pods controlled by DaemonSets {pull}26808[26808], {issue}25816[25816]

*Auditbeat*

Expand Down
2 changes: 1 addition & 1 deletion libbeat/common/kubernetes/metadata/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func NewPodMetadataGenerator(
// "kubernetes": {},
// "some.ecs.field": "asdf"
// }
// All Kubernetes fields that need to be stored under kuberentes. prefix are populetad by
// All Kubernetes fields that need to be stored under kubernetes. prefix are populated by
// GenerateK8s method while fields that are part of ECS are generated by GenerateECS method
func (p *pod) Generate(obj kubernetes.Resource, opts ...FieldOptions) common.MapStr {
ecsFields := p.GenerateECS(obj)
Expand Down
57 changes: 56 additions & 1 deletion libbeat/common/kubernetes/metadata/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestPod_Generate(t *testing.T) {
},
},
{
name: "test object with owner reference",
name: "test object with owner reference to Deployment",
input: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down Expand Up @@ -195,6 +195,61 @@ func TestPod_Generate(t *testing.T) {
},
},
},
{
name: "test object with owner reference to DaemonSet",
input: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
UID: types.UID(uid),
Namespace: namespace,
Labels: map[string]string{
"foo": "bar",
},
Annotations: map[string]string{
"app": "production",
},
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: "apps",
Kind: "DaemonSet",
Name: "owner",
UID: "005f3b90-4b9d-12f8-acf0-31020a840144",
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{
"kubernetes": common.MapStr{
"pod": common.MapStr{
"name": "obj",
"uid": uid,
"ip": "127.0.0.5",
},
"namespace": "default",
"daemonset": common.MapStr{
"name": "owner",
},
"node": common.MapStr{
"name": "testnode",
},
"labels": common.MapStr{
"foo": "bar",
},
"annotations": common.MapStr{
"app": "production",
},
},
},
},
{
name: "test object with owner reference to replicaset",
input: &v1.Pod{
Expand Down
3 changes: 2 additions & 1 deletion libbeat/common/kubernetes/metadata/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func (r *Resource) GenerateK8s(kind string, obj kubernetes.Resource, options ...
// TODO grow this list as we keep adding more `state_*` metricsets
case "Deployment",
"ReplicaSet",
"StatefulSet":
"StatefulSet",
"DaemonSet":
safemapstr.Put(meta, strings.ToLower(ref.Kind)+".name", ref.Name)
}
}
Expand Down

0 comments on commit be6870d

Please sign in to comment.