Merge pull request #59297 from joelsmith/master
Automatic merge from submit-queue (batch tested with PRs 59010, 59212, 59281, 59014, 59297). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Improve error returned when fetching container logs during pod termination **What this PR does / why we need it**: This change better handles fetching of logs when a container is in a crash loop backoff state. In cases where it is unable to fetch the logs, it gives a helpful error message back to a user who has requested logs of a container from a terminated pod. Rather than attempting to get logs for a container using an empty container ID, it returns a useful error message. In cases where the container runtime gets an error, log the error but don't leak it back through the API to the user. **Which issue(s) this PR fixes**: Fixes #59296 **Release note**: ```release-note NONE ```
This commit is contained in:
@@ -1129,7 +1129,7 @@ func (kl *Kubelet) validateContainerLogStatus(podName string, podStatus *v1.PodS
|
||||
|
||||
switch {
|
||||
case previous:
|
||||
if lastState.Terminated == nil {
|
||||
if lastState.Terminated == nil || lastState.Terminated.ContainerID == "" {
|
||||
return kubecontainer.ContainerID{}, fmt.Errorf("previous terminated container %q in pod %q not found", containerName, podName)
|
||||
}
|
||||
cID = lastState.Terminated.ContainerID
|
||||
@@ -1138,9 +1138,21 @@ func (kl *Kubelet) validateContainerLogStatus(podName string, podStatus *v1.PodS
|
||||
cID = cStatus.ContainerID
|
||||
|
||||
case terminated != nil:
|
||||
cID = terminated.ContainerID
|
||||
// in cases where the next container didn't start, terminated.ContainerID will be empty, so get logs from the lastState.Terminated.
|
||||
if terminated.ContainerID == "" {
|
||||
if lastState.Terminated != nil && lastState.Terminated.ContainerID != "" {
|
||||
cID = lastState.Terminated.ContainerID
|
||||
} else {
|
||||
return kubecontainer.ContainerID{}, fmt.Errorf("container %q in pod %q is terminated", containerName, podName)
|
||||
}
|
||||
} else {
|
||||
cID = terminated.ContainerID
|
||||
}
|
||||
|
||||
case lastState.Terminated != nil:
|
||||
if lastState.Terminated.ContainerID == "" {
|
||||
return kubecontainer.ContainerID{}, fmt.Errorf("container %q in pod %q is terminated", containerName, podName)
|
||||
}
|
||||
cID = lastState.Terminated.ContainerID
|
||||
|
||||
case waiting != nil:
|
||||
|
Reference in New Issue
Block a user