Skip to content

Commit

Permalink
Cherry-pick #28954 to 7.17: Add kubernetes job name as the controller (
Browse files Browse the repository at this point in the history
…#29679)

* Add kubernetes job name as the controller (#28954)

(cherry picked from commit eaa3b32)

* remove not relevand changelog records

Signed-off-by: Tetiana Kravchenko <tetiana.kravchenko@elastic.co>

Co-authored-by: George Wilson <georgejameswilson@googlemail.com>
  • Loading branch information
tetianakravchenko and wilsonge committed Jan 11, 2022
1 parent 53ef1a3 commit 685883f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

*Affecting all Beats*

- Add job.name in pods controlled by Jobs {pull}28954[28954]

*Auditbeat*

*Filebeat*
Expand Down
55 changes: 55 additions & 0 deletions libbeat/common/kubernetes/metadata/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,61 @@ func TestPod_Generate(t *testing.T) {
},
},
},
{
name: "test object with owner reference to Job",
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: "batch/v1",
Kind: "Job",
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",
"job": 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 @@ -120,7 +120,8 @@ func (r *Resource) GenerateK8s(kind string, obj kubernetes.Resource, options ...
case "Deployment",
"ReplicaSet",
"StatefulSet",
"DaemonSet":
"DaemonSet",
"Job":
safemapstr.Put(meta, strings.ToLower(ref.Kind)+".name", ref.Name)
}
}
Expand Down

0 comments on commit 685883f

Please sign in to comment.