From 75c19da8431f4fa44e6b80fd6eb79b4fefa6fb00 Mon Sep 17 00:00:00 2001 From: pacoxu Date: Mon, 29 Mar 2021 10:33:17 +0800 Subject: [PATCH] correct messages in post start hook error handling Signed-off-by: pacoxu --- pkg/kubelet/kuberuntime/kuberuntime_container.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go index 5720576e07f..bb205c60755 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go @@ -226,12 +226,14 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb } msg, handlerErr := m.runner.Run(kubeContainerID, pod, container, container.Lifecycle.PostStart) if handlerErr != nil { + klog.ErrorS(handlerErr, "Failed to execute PostStartHook", "pod", klog.KObj(pod), + "podUID", pod.UID, "containerName", container.Name, "containerID", kubeContainerID.String()) m.recordContainerEvent(pod, container, kubeContainerID.ID, v1.EventTypeWarning, events.FailedPostStartHook, msg) if err := m.killContainer(pod, kubeContainerID, container.Name, "FailedPostStartHook", reasonFailedPostStartHook, nil); err != nil { - klog.ErrorS(fmt.Errorf("%s: %v", ErrPostStartHook, handlerErr), "Failed to kill container", "pod", klog.KObj(pod), + klog.ErrorS(err, "Failed to kill container", "pod", klog.KObj(pod), "podUID", pod.UID, "containerName", container.Name, "containerID", kubeContainerID.String()) } - return msg, fmt.Errorf("%s: %v", ErrPostStartHook, handlerErr) + return msg, ErrPostStartHook } }