RunLogsContext retrieves a pod log. When a signal is received, streaming is stopped, then followed by os.Exit(1).
(ctx context.Context)
| 366 | // |
| 367 | // When a signal is received, streaming is stopped, then followed by os.Exit(1). |
| 368 | func (o LogsOptions) RunLogsContext(ctx context.Context) error { |
| 369 | ctx, cancel := context.WithCancel(ctx) |
| 370 | defer cancel() |
| 371 | intr := interrupt.New(nil, cancel) |
| 372 | return intr.Run(func() error { |
| 373 | var requests map[corev1.ObjectReference]rest.ResponseWrapper |
| 374 | var err error |
| 375 | if o.AllPods { |
| 376 | requests, err = o.AllPodLogsForObject(o.RESTClientGetter, o.Object, o.Options, o.GetPodTimeout, o.AllContainers) |
| 377 | } else { |
| 378 | requests, err = o.LogsForObject(o.RESTClientGetter, o.Object, o.Options, o.GetPodTimeout, o.AllContainers) |
| 379 | } |
| 380 | if err != nil { |
| 381 | return err |
| 382 | } |
| 383 | |
| 384 | if o.Follow && len(requests) > 1 { |
| 385 | if len(requests) > o.MaxFollowConcurrency { |
| 386 | return fmt.Errorf( |
| 387 | "you are attempting to follow %d log streams, but maximum allowed concurrency is %d, use --max-log-requests to increase the limit", |
| 388 | len(requests), o.MaxFollowConcurrency, |
| 389 | ) |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | if o.Follow && len(requests) > 1 { |
| 394 | return o.parallelConsumeRequest(ctx, requests) |
| 395 | } |
| 396 | return o.sequentialConsumeRequest(ctx, requests) |
| 397 | }) |
| 398 | } |
| 399 | |
| 400 | func (o LogsOptions) parallelConsumeRequest(ctx context.Context, requests map[corev1.ObjectReference]rest.ResponseWrapper) error { |
| 401 | reader, writer := io.Pipe() |