Skip to content

Commit 0e1bad3

Browse files
authored
Merge pull request kubernetes#81747 from Random-Liu/fix-windows-log-follow
Fix windows kubectl log -f.
2 parents 103e926 + 7767ff3 commit 0e1bad3

File tree

1 file changed

+11
-0
lines changed
  • pkg/kubelet/kuberuntime/logs

1 file changed

+11
-0
lines changed

pkg/kubelet/kuberuntime/logs/logs.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"io"
2727
"math"
2828
"os"
29+
"path/filepath"
2930
"time"
3031

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

0 commit comments

Comments
 (0)