Fix windows kubectl log -f.

This commit is contained in:
Lantao Liu 2019-08-21 14:09:34 -07:00
parent 90df64b75b
commit 7767ff3bb2

View File

@ -26,6 +26,7 @@ import (
"io"
"math"
"os"
"path/filepath"
"time"
"github.com/docker/docker/daemon/logger/jsonfilelog/jsonlog"
@ -271,6 +272,16 @@ func (w *logWriter) write(msg *logMessage) error {
// Note that containerID is only needed when following the log, or else
// just pass in empty string "".
func ReadLogs(ctx context.Context, path, containerID string, opts *LogOptions, runtimeService internalapi.RuntimeService, stdout, stderr io.Writer) error {
// fsnotify has different behavior for symlinks in different platform,
// for example it follows symlink on Linux, but not on Windows,
// so we explicitly resolve symlinks before reading the logs.
// There shouldn't be security issue because the container log
// path is owned by kubelet and the container runtime.
evaluated, err := filepath.EvalSymlinks(path)
if err != nil {
return fmt.Errorf("failed to try resolving symlinks in path %q: %v", path, err)
}
path = evaluated
f, err := os.Open(path)
if err != nil {
return fmt.Errorf("failed to open log file %q: %v", path, err)