Merge pull request #100608 from pacoxu/fix/poststart-hook

correct messages in post start hook error handling
This commit is contained in:
Kubernetes Prow Robot 2021-05-24 21:48:32 -07:00 committed by GitHub
commit a49b4a1018
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -279,12 +279,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
}
}