From 7679a84c6d63442b64f7aca30b197ba85e741b61 Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Wed, 5 Apr 2017 00:11:53 +1000 Subject: [PATCH] server: issues.k8s.io/44043 workaround Because kubelet will create broken symlinks for logPath it is necessary to remove those symlinks before we attempt to write to them. This is a temporary workaround while the issue is fixed upstream. Ref: https://issues.k8s.io/44043 Signed-off-by: Aleksa Sarai --- server/container_create.go | 28 ++++++++++++++++++++++++++++ server/sandbox_run.go | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/server/container_create.go b/server/container_create.go index cad91100..94f4b390 100644 --- a/server/container_create.go +++ b/server/container_create.go @@ -203,6 +203,29 @@ func setupContainerUser(specgen *generate.Generator, rootfs string, sc *pb.Linux return nil } +// ensureSaneLogPath is a hack to fix https://issues.k8s.io/44043 which causes +// logPath to be a broken symlink to some magical Docker path. Ideally we +// wouldn't have to deal with this, but until that issue is fixed we have to +// remove the path if it's a broken symlink. +func ensureSaneLogPath(logPath string) error { + // If the path exists but the resolved path does not, then we have a broken + // symlink and we need to remove it. + fi, err := os.Lstat(logPath) + if err != nil || fi.Mode()&os.ModeSymlink == 0 { + // Non-existant files and non-symlinks aren't our problem. + return nil + } + + _, err = os.Stat(logPath) + if os.IsNotExist(err) { + err = os.RemoveAll(logPath) + if err != nil { + return fmt.Errorf("ensureSaneLogPath remove bad logPath: %s", err) + } + } + return nil +} + // CreateContainer creates a new container in specified PodSandbox func (s *Server) CreateContainer(ctx context.Context, req *pb.CreateContainerRequest) (res *pb.CreateContainerResponse, err error) { logrus.Debugf("CreateContainerRequest %+v", req) @@ -342,6 +365,11 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string, logPath = filepath.Join(sb.logDir, logPath) } + // Handle https://issues.k8s.io/44043 + if err := ensureSaneLogPath(logPath); err != nil { + return nil, err + } + logrus.WithFields(logrus.Fields{ "sbox.logdir": sb.logDir, "ctr.logfile": containerConfig.LogPath, diff --git a/server/sandbox_run.go b/server/sandbox_run.go index c9169fe4..362419f0 100644 --- a/server/sandbox_run.go +++ b/server/sandbox_run.go @@ -255,6 +255,11 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest // set log path inside log directory logPath := filepath.Join(logDir, id+".log") + // Handle https://issues.k8s.io/44043 + if err := ensureSaneLogPath(logPath); err != nil { + return nil, err + } + privileged := s.privilegedSandbox(req) g.AddAnnotation("ocid/metadata", string(metadataJSON)) g.AddAnnotation("ocid/labels", string(labelsJSON))