MCPcopy
hub / github.com/kubernetes/kubectl / RunLogsContext

Method RunLogsContext

pkg/cmd/logs/logs.go:368–398  ·  view source on GitHub ↗

RunLogsContext retrieves a pod log. When a signal is received, streaming is stopped, then followed by os.Exit(1).

(ctx context.Context)

Source from the content-addressed store, hash-verified

366//
367// When a signal is received, streaming is stopped, then followed by os.Exit(1).
368func (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
400func (o LogsOptions) parallelConsumeRequest(ctx context.Context, requests map[corev1.ObjectReference]rest.ResponseWrapper) error {
401 reader, writer := io.Pipe()

Callers 3

NewCmdLogsFunction · 0.95
RunLogsMethod · 0.95
TestLogFunction · 0.80

Calls 4

NewFunction · 0.92
RunMethod · 0.45

Tested by 1

TestLogFunction · 0.64