diff --git a/pkg/kubelet/dockershim/docker_container.go b/pkg/kubelet/dockershim/docker_container.go index 5ee0d8e539d..064dd6edf85 100644 --- a/pkg/kubelet/dockershim/docker_container.go +++ b/pkg/kubelet/dockershim/docker_container.go @@ -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) diff --git a/pkg/kubelet/dockershim/docker_container_test.go b/pkg/kubelet/dockershim/docker_container_test.go index a8b70925b62..ed99cc27752 100644 --- a/pkg/kubelet/dockershim/docker_container_test.go +++ b/pkg/kubelet/dockershim/docker_container_test.go @@ -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