Merge pull request #49107 from edevil/try_remove_old_log

Automatic merge from submit-queue (batch tested with PRs 49107, 47177, 49234, 49224, 49227)

Make sure the previous symlink file is deleted before trying to create a new one

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

It deletes possibly existing symlinks to container log files.

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

fixes #49105

**Special notes for your reviewer**:

**Release note**:

```release-note
```
This commit is contained in:
Kubernetes Submit Queue 2017-07-20 15:08:17 -07:00 committed by GitHub
commit 84f773850e
2 changed files with 6 additions and 1 deletions

View File

@ -192,6 +192,10 @@ func (ds *dockerService) createContainerLogSymlink(containerID string) error {
if realPath != "" {
// Only create the symlink when container log path is specified and log file exists.
// Delete possibly existing file first
if err = ds.os.Remove(path); err == nil {
glog.Warningf("Deleted previously existing symlink file: %q", path)
}
if err = ds.os.Symlink(realPath, path); err != nil {
return fmt.Errorf("failed to create symbolic link %q to the container log file %q for container %q: %v",
path, realPath, containerID, err)

View File

@ -218,9 +218,10 @@ func TestContainerLogPath(t *testing.T) {
assert.NoError(t, err)
// Verify container log symlink deletion
// symlink is also tentatively deleted at startup
err = ds.RemoveContainer(id)
assert.NoError(t, err)
assert.Equal(t, fakeOS.Removes, []string{kubeletContainerLogPath})
assert.Equal(t, []string{kubeletContainerLogPath, kubeletContainerLogPath}, fakeOS.Removes)
}
// TestContainerCreationConflict tests the logic to work around docker container