Merge pull request #50509 from feiskyer/link-logs

Automatic merge from submit-queue (batch tested with PRs 50988, 50509, 52660, 52663, 52250). 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>.

Create container log symlink for all containers

**What this PR does / why we need it**:

dockershim only makes  log symlink for running containers now, we should also create the log symlink for failed containers.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #50499

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2017-09-27 05:32:23 -07:00 committed by GitHub
commit 0ea979a2f2
1 changed files with 10 additions and 7 deletions

View File

@ -232,18 +232,21 @@ func (ds *dockerService) removeContainerLogSymlink(containerID string) error {
// StartContainer starts the container. // StartContainer starts the container.
func (ds *dockerService) StartContainer(containerID string) error { func (ds *dockerService) StartContainer(containerID string) error {
err := ds.client.StartContainer(containerID) err := ds.client.StartContainer(containerID)
if err != nil {
err = transformStartContainerError(err) // Create container log symlink for all containers (including failed ones).
return fmt.Errorf("failed to start container %q: %v", containerID, err) if linkError := ds.createContainerLogSymlink(containerID); linkError != nil {
}
// Create container log symlink.
if err := ds.createContainerLogSymlink(containerID); err != nil {
// Do not stop the container if we failed to create symlink because: // Do not stop the container if we failed to create symlink because:
// 1. This is not a critical failure. // 1. This is not a critical failure.
// 2. We don't have enough information to properly stop container here. // 2. We don't have enough information to properly stop container here.
// Kubelet will surface this error to user via an event. // Kubelet will surface this error to user via an event.
return err return linkError
} }
if err != nil {
err = transformStartContainerError(err)
return fmt.Errorf("failed to start container %q: %v", containerID, err)
}
return nil return nil
} }