diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index 34b38a9d780..d1dc6298030 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -2127,19 +2127,28 @@ func (kl *Kubelet) SyncPod(ctx context.Context, updateType kubetypes.SyncPodType // during eviction). This method is not guaranteed to be called if a pod is force deleted from the // configuration and the kubelet is restarted - SyncTerminatingRuntimePod handles those orphaned // pods. -func (kl *Kubelet) SyncTerminatingPod(_ context.Context, pod *v1.Pod, podStatus *kubecontainer.PodStatus, gracePeriod *int64, podStatusFn func(*v1.PodStatus)) error { +func (kl *Kubelet) SyncTerminatingPod(_ context.Context, pod *v1.Pod, podStatus *kubecontainer.PodStatus, gracePeriod *int64, podStatusFn func(*v1.PodStatus)) (err error) { // TODO(#113606): connect this with the incoming context parameter, which comes from the pod worker. // Currently, using that context causes test failures. - ctx, otelSpan := kl.tracer.Start(context.Background(), "syncTerminatingPod", trace.WithAttributes( + ctx := context.Background() + + logger := klog.FromContext(ctx) + klog.V(4).InfoS("SyncTerminatingPod enter", "pod", klog.KObj(pod), "podUID", pod.UID) + + ctx, otelSpan := kl.tracer.Start(ctx, "syncTerminatingPod", trace.WithAttributes( semconv.K8SPodUIDKey.String(string(pod.UID)), attribute.String("k8s.pod", klog.KObj(pod).String()), semconv.K8SPodNameKey.String(pod.Name), semconv.K8SNamespaceNameKey.String(pod.Namespace), )) - logger := klog.FromContext(ctx) - defer otelSpan.End() - klog.V(4).InfoS("SyncTerminatingPod enter", "pod", klog.KObj(pod), "podUID", pod.UID) - defer klog.V(4).InfoS("SyncTerminatingPod exit", "pod", klog.KObj(pod), "podUID", pod.UID) + defer func() { + if err != nil { + otelSpan.RecordError(err) + otelSpan.SetStatus(codes.Error, err.Error()) + } + otelSpan.End() + klog.V(4).InfoS("SyncTerminatingPod exit", "pod", klog.KObj(pod), "podUID", pod.UID) + }() apiPodStatus := kl.generateAPIPodStatus(pod, podStatus, false) if podStatusFn != nil {