diff --git a/odiglet/pkg/ebpf/director.go b/odiglet/pkg/ebpf/director.go index 8e998ed14..57b41a163 100644 --- a/odiglet/pkg/ebpf/director.go +++ b/odiglet/pkg/ebpf/director.go @@ -307,7 +307,7 @@ func (d *EbpfDirector[T]) Cleanup(pod types.NamespacedName) { return } - log.Logger.V(0).Info("Cleaning up ebpf go instrumentation for pod", "pod", pod) + log.Logger.V(0).Info("Cleaning up ebpf instrumentation for pod", "pod", pod, "language", d.language) delete(d.podsToDetails, pod) // clear the pod from the workloadToPods map diff --git a/odiglet/pkg/kube/instrumentation_ebpf/manager.go b/odiglet/pkg/kube/instrumentation_ebpf/manager.go index d090eb722..9dfcac882 100644 --- a/odiglet/pkg/kube/instrumentation_ebpf/manager.go +++ b/odiglet/pkg/kube/instrumentation_ebpf/manager.go @@ -37,7 +37,11 @@ func (i *podPredicate) Update(e event.UpdateEvent) bool { return true } - return false + // Sum the restart counts for both oldPod and newPod containers, then compare them. + // If the newPod has a higher restart count than the oldPod, we need to re-instrument it. + // This happens because the pod was abruptly killed, which caused an increment in the restart count. + // This check is required because the pod will remain running during the process kill and re-launch. + return GetPodSumRestarts(newPod) > GetPodSumRestarts(oldPod) } func (i *podPredicate) Delete(e event.DeleteEvent) bool { diff --git a/odiglet/pkg/kube/instrumentation_ebpf/pods.go b/odiglet/pkg/kube/instrumentation_ebpf/pods.go index 2102e3e4c..b2263c8b3 100644 --- a/odiglet/pkg/kube/instrumentation_ebpf/pods.go +++ b/odiglet/pkg/kube/instrumentation_ebpf/pods.go @@ -123,3 +123,11 @@ func (p *PodsReconciler) getPodWorkloadObject(ctx context.Context, pod *corev1.P // Pod does not necessarily have to be managed by a controller return nil, nil } + +func GetPodSumRestarts(pod *corev1.Pod) int { + restartCount := 0 + for _, containerStatus := range pod.Status.ContainerStatuses { + restartCount += int(containerStatus.RestartCount) + } + return restartCount +}