mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #93920 from zhouya0/log_with_limited_tail
[Flaky Test] Add limited lines to log when having tail option
This commit is contained in:
commit
b6e0aac05c
@ -303,6 +303,8 @@ func ReadLogs(ctx context.Context, path, containerID string, opts *LogOptions, r
|
|||||||
return fmt.Errorf("failed to seek %d in log file %q: %v", start, path, err)
|
return fmt.Errorf("failed to seek %d in log file %q: %v", start, path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
limitedMode := (opts.tail >= 0) && (!opts.follow)
|
||||||
|
limitedNum := opts.tail
|
||||||
// Start parsing the logs.
|
// Start parsing the logs.
|
||||||
r := bufio.NewReader(f)
|
r := bufio.NewReader(f)
|
||||||
// Do not create watcher here because it is not needed if `Follow` is false.
|
// Do not create watcher here because it is not needed if `Follow` is false.
|
||||||
@ -313,7 +315,7 @@ func ReadLogs(ctx context.Context, path, containerID string, opts *LogOptions, r
|
|||||||
writer := newLogWriter(stdout, stderr, opts)
|
writer := newLogWriter(stdout, stderr, opts)
|
||||||
msg := &logMessage{}
|
msg := &logMessage{}
|
||||||
for {
|
for {
|
||||||
if stop {
|
if stop || (limitedMode && limitedNum == 0) {
|
||||||
klog.V(2).Infof("Finish parsing log file %q", path)
|
klog.V(2).Infof("Finish parsing log file %q", path)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -401,6 +403,10 @@ func ReadLogs(ctx context.Context, path, containerID string, opts *LogOptions, r
|
|||||||
klog.Errorf("Failed with err %v when writing log for log file %q: %+v", err, path, msg)
|
klog.Errorf("Failed with err %v when writing log for log file %q: %+v", err, path, msg)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if limitedMode {
|
||||||
|
limitedNum--
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user