From 81081128f40e5e6aebb22e2597e9f268d7b2c443 Mon Sep 17 00:00:00 2001 From: Avesh Agarwal Date: Mon, 5 Mar 2018 16:40:43 -0500 Subject: [PATCH] Do not create dangling legacy symlink if the new symlink to container logs does not exist. These dangling legacy symlink are removed by kube runtime gc, so it's better if we do not create them in the first place to avoid unnecessary work from kube runtime gc. --- pkg/kubelet/kuberuntime/kuberuntime_container.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/kubelet/kuberuntime/kuberuntime_container.go b/pkg/kubelet/kuberuntime/kuberuntime_container.go index 2dadd7a66e6..64c01e15e6b 100644 --- a/pkg/kubelet/kuberuntime/kuberuntime_container.go +++ b/pkg/kubelet/kuberuntime/kuberuntime_container.go @@ -146,9 +146,15 @@ func (m *kubeGenericRuntimeManager) startContainer(podSandboxID string, podSandb legacySymlink := legacyLogSymlink(containerID, containerMeta.Name, sandboxMeta.Name, sandboxMeta.Namespace) containerLog := filepath.Join(podSandboxConfig.LogDirectory, containerConfig.LogPath) - if err := m.osInterface.Symlink(containerLog, legacySymlink); err != nil { - glog.Errorf("Failed to create legacy symbolic link %q to container %q log %q: %v", - legacySymlink, containerID, containerLog, err) + // only create legacy symlink if containerLog path exists (or the error is not IsNotExist). + // Because if containerLog path does not exist, only dandling legacySymlink is created. + // This dangling legacySymlink is later removed by container gc, so it does not make sense + // to create it in the first place. it happens when journald logging driver is used with docker. + if _, err := m.osInterface.Stat(containerLog); !os.IsNotExist(err) { + if err := m.osInterface.Symlink(containerLog, legacySymlink); err != nil { + glog.Errorf("Failed to create legacy symbolic link %q to container %q log %q: %v", + legacySymlink, containerID, containerLog, err) + } } // Step 4: execute the post start hook.