Skip to content

Commit

Permalink
Add kubernetes job name as the controller
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsonge committed Dec 31, 2021
1 parent 84924e9 commit e443222
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Index template's default_fields setting is only populated with ECS fields. {pull}28596[28596] {issue}28215[28215]
- Remove deprecated `--template` and `--ilm-policy` flags. Use `--index-management` instead. {pull}28870[28870]
- Remove options `logging.files.suffix` and default to datetime endings. {pull}28927[28927]
- Add job.name in pods controlled by Jobs {pull}28954[28954]

*Auditbeat*

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 @@ -252,6 +252,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 @@ -118,7 +118,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 e443222

Please sign in to comment.