Skip to content

Commit 7767ff3

Browse files
committed
Fix windows kubectl log -f.
1 parent 90df64b commit 7767ff3

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"
@@ -271,6 +272,16 @@ func (w *logWriter) write(msg *logMessage) error {
271272
// Note that containerID is only needed when following the log, or else
272273
// just pass in empty string "".
273274
func ReadLogs(ctx context.Context, path, containerID string, opts *LogOptions, runtimeService internalapi.RuntimeService, stdout, stderr io.Writer) error {
275+
// fsnotify has different behavior for symlinks in different platform,
276+
// for example it follows symlink on Linux, but not on Windows,
277+
// so we explicitly resolve symlinks before reading the logs.
278+
// There shouldn't be security issue because the container log
279+
// path is owned by kubelet and the container runtime.
280+
evaluated, err := filepath.EvalSymlinks(path)
281+
if err != nil {
282+
return fmt.Errorf("failed to try resolving symlinks in path %q: %v", path, err)
283+
}
284+
path = evaluated
274285
f, err := os.Open(path)
275286
if err != nil {
276287
return fmt.Errorf("failed to open log file %q: %v", path, err)

0 commit comments

Comments
 (0)