open-telemetry / opentelemetry-network

eBPF Collector
https://opentelemetry.io
Apache License 2.0
297 stars 47 forks source link

Handle Pods owned by a CronJob #249

Closed golisai closed 10 months ago

golisai commented 10 months ago

Description: The pods created by the CronJob are currently being inaccurately attributed to an intermediate Job as their owner. This patch corrects this by properly associating the CronJob as the actual owner of those pods.

Testing:

  1. CronJob
    
    $ kubectl create cronjob cronjob1 --image=busybx --schedule="*/1 * * * *" -- sleep 20

$ kubectl get pods cronjob1-28413736-bpz85 -o json | jq -r '.metadata.ownerReferences' [ { "apiVersion": "batch/v1", "blockOwnerDeletion": true, "controller": true, "kind": "Job", "name": "cronjob1-28413736", "uid": "e25ce59b-1069-4775-99e6-a656b6aa448d" } ]

$ kubectl get jobs cronjob1-28413736 -o json | jq -r '.metadata.ownerReferences' [ { "apiVersion": "batch/v1", "blockOwnerDeletion": true, "controller": true, "kind": "CronJob", "name": "cronjob1", "uid": "07d02c09-ab5d-4f13-9d1b-fb2940ea27f0" } ]

k8s-relay logs:

2024-01-09 18:15:03.247431+00:00 trace [p:7 t:16] Merged pod into internal state: uid: "7dbf8dbf-502d-40cc-baa1-922ca643281d" ip: "10.1.235.207" owner { uid: "937cfa1e-758a-4cf7-9156-d0771d790031" name: "cronjob1-28413735" kind: "Job" } ns: "default" name: "cronjob1-28413735-rrnf6" version: "\'busybx\'" container_infos { name: "cronjob1" image: "busybx" }

2024-01-09 18:15:03.247460+00:00 trace [p:7 t:16] Pod's owner Job has CronJob owner. Sending pod with owner uid: "07d02c09-ab5d-4f13-9d1b-fb2940ea27f0" name: "cronjob1" kind: "CronJob"

2. Regular Job

$ kubectl create job test-job --image=busybox -- sleep 1000

$ kubectl get pods test-job-6p7bt -o json | jq -r '.metadata.ownerReferences' [ { "apiVersion": "batch/v1", "blockOwnerDeletion": true, "controller": true, "kind": "Job", "name": "test-job", "uid": "95422620-bd34-43b2-acb4-f6cfd542fb96" } ]

$ kubectl get jobs test-job -o json | jq -r '.metadata.ownerReferences' null

k8s-relay logs:

2024-01-09 01:47:52.133522+00:00 trace [p:7 t:15] Adding pod into internal state: uid: "412d8074-6059-4488-9e4e-3ec122975d2a" ip: "10.1.36.127" owner { uid: "95422620-bd34-43b2-acb4-f6cfd542fb96" name: "test-job" kind: "Job" } ns: "default" name: "test-job-6p7bt" version: "\'docker.io/library/busybox:latest\'" container_infos { id: "containerd://5ae7c37d4b2e86cc6b9f9cd9b6263247e9d38db9d9fbf671a9eb80753635424b" name: "test-job" image: "docker.io/library/busybox:latest" }

2024-01-09 01:47:52.133528+00:00 trace [p:7 t:15] Pod's owner Job has non-CronJob owner. Sending pod with owner uid: "95422620-bd34-43b2-acb4-f6cfd542fb96" name: "test-job" kind: "Job"



**Documentation:** None
golisai commented 10 months ago

Thanks. Will ping you once we are close to release.