mirror of https://github.com/k3s-io/k3s
allow for non-fatal errors when requesting and following multiple log streams
parent
733f2478d3
commit
ac4eebeeb5
|
@ -99,6 +99,7 @@ type LogsOptions struct {
|
||||||
Follow bool
|
Follow bool
|
||||||
Previous bool
|
Previous bool
|
||||||
Timestamps bool
|
Timestamps bool
|
||||||
|
IgnoreLogErrors bool
|
||||||
LimitBytes int64
|
LimitBytes int64
|
||||||
Tail int64
|
Tail int64
|
||||||
Container string
|
Container string
|
||||||
|
@ -153,6 +154,7 @@ func NewCmdLogs(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.C
|
||||||
cmd.Flags().Int64Var(&o.LimitBytes, "limit-bytes", o.LimitBytes, "Maximum bytes of logs to return. Defaults to no limit.")
|
cmd.Flags().Int64Var(&o.LimitBytes, "limit-bytes", o.LimitBytes, "Maximum bytes of logs to return. Defaults to no limit.")
|
||||||
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.")
|
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.")
|
||||||
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.")
|
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.")
|
||||||
|
cmd.Flags().BoolVar(&o.IgnoreLogErrors, "ignore-errors", o.IgnoreLogErrors, "If watching / following pod logs, allow for any errors that occur to be non-fatal")
|
||||||
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."))
|
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."))
|
||||||
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.")
|
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.")
|
||||||
cmd.Flags().StringVarP(&o.Container, "container", "c", o.Container, "Print the logs of this container")
|
cmd.Flags().StringVarP(&o.Container, "container", "c", o.Container, "Print the logs of this container")
|
||||||
|
@ -323,12 +325,16 @@ func (o LogsOptions) parallelConsumeRequest(requests []rest.ResponseWrapper) err
|
||||||
for _, request := range requests {
|
for _, request := range requests {
|
||||||
go func(request rest.ResponseWrapper) {
|
go func(request rest.ResponseWrapper) {
|
||||||
if err := o.ConsumeRequestFn(request, writer); err != nil {
|
if err := o.ConsumeRequestFn(request, writer); err != nil {
|
||||||
|
if !o.IgnoreLogErrors {
|
||||||
writer.CloseWithError(err)
|
writer.CloseWithError(err)
|
||||||
|
|
||||||
// It's important to return here to propagate the error via the pipe
|
// It's important to return here to propagate the error via the pipe
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(writer, "error: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}(request)
|
}(request)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue