Skip to content

Commit

Permalink
fix: reconcile in case pod killed abruptly (#1512)
Browse files Browse the repository at this point in the history
Co-authored-by: Tamir David <tamirdavid@Tamirs-MacBook-Pro.local>
Co-authored-by: Ron Federman <73110295+RonFed@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent 5ccf3c2 commit 779b6cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion odiglet/pkg/ebpf/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion odiglet/pkg/kube/instrumentation_ebpf/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions odiglet/pkg/kube/instrumentation_ebpf/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 779b6cc

Please sign in to comment.