Skip to content

Commit c23115d

Browse files
authored
Merge pull request kubernetes#75903 from juanvallejo/jvallejo/allow-non-fatal-errors-when-fetching-pod-logs
allow for non-fatal errors when requesting and following multiple log streams
2 parents 6681c12 + ac4eebe commit c23115d

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

pkg/kubectl/cmd/logs/logs.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,15 @@ type LogsOptions struct {
9494
ConsumeRequestFn func(rest.ResponseWrapper, io.Writer) error
9595

9696
// PodLogOptions
97-
SinceTime string
98-
SinceSeconds time.Duration
99-
Follow bool
100-
Previous bool
101-
Timestamps bool
102-
LimitBytes int64
103-
Tail int64
104-
Container string
97+
SinceTime string
98+
SinceSeconds time.Duration
99+
Follow bool
100+
Previous bool
101+
Timestamps bool
102+
IgnoreLogErrors bool
103+
LimitBytes int64
104+
Tail int64
105+
Container string
105106

106107
// whether or not a container name was given via --container
107108
ContainerNameSpecified bool
@@ -153,6 +154,7 @@ func NewCmdLogs(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.C
153154
cmd.Flags().Int64Var(&o.LimitBytes, "limit-bytes", o.LimitBytes, "Maximum bytes of logs to return. Defaults to no limit.")
154155
cmd.Flags().BoolVarP(&o.Previous, "previous", "p", o.Previous, "If true, print the logs for the previous instance of the container in a pod if it exists.")
155156
cmd.Flags().Int64Var(&o.Tail, "tail", o.Tail, "Lines of recent log file to display. Defaults to -1 with no selector, showing all log lines otherwise 10, if a selector is provided.")
157+
cmd.Flags().BoolVar(&o.IgnoreLogErrors, "ignore-errors", o.IgnoreLogErrors, "If watching / following pod logs, allow for any errors that occur to be non-fatal")
156158
cmd.Flags().StringVar(&o.SinceTime, "since-time", o.SinceTime, i18n.T("Only return logs after a specific date (RFC3339). Defaults to all logs. Only one of since-time / since may be used."))
157159
cmd.Flags().DurationVar(&o.SinceSeconds, "since", o.SinceSeconds, "Only return logs newer than a relative duration like 5s, 2m, or 3h. Defaults to all logs. Only one of since-time / since may be used.")
158160
cmd.Flags().StringVarP(&o.Container, "container", "c", o.Container, "Print the logs of this container")
@@ -323,10 +325,14 @@ func (o LogsOptions) parallelConsumeRequest(requests []rest.ResponseWrapper) err
323325
for _, request := range requests {
324326
go func(request rest.ResponseWrapper) {
325327
if err := o.ConsumeRequestFn(request, writer); err != nil {
326-
writer.CloseWithError(err)
328+
if !o.IgnoreLogErrors {
329+
writer.CloseWithError(err)
327330

328-
// It's important to return here to propagate the error via the pipe
329-
return
331+
// It's important to return here to propagate the error via the pipe
332+
return
333+
}
334+
335+
fmt.Fprintf(writer, "error: %v\n", err)
330336
}
331337

332338
wg.Done()

0 commit comments

Comments
 (0)