type LogOutput … var expectedErrors … // CopyPodLogs is basically CopyPodLogs for all current or future pods in the given namespace ns func CopyAllLogs(ctx context.Context, cs clientset.Interface, ns string, to LogOutput) error { … } // CopyPodLogs follows the logs of all containers in pod with the given podName, // including those that get created in the future, and writes each log // line as configured in the output options. It does that until the // context is done or until an error occurs. // // If podName is empty, it will follow all pods in the given namespace ns. // // Beware that there is currently no way to force log collection // before removing pods, which means that there is a known race // between "stop pod" and "collecting log entries". The alternative // would be a blocking function with collects logs from all currently // running pods, but that then would have the disadvantage that // already deleted pods aren't covered. // // Another race occurs is when a pod shuts down. Logging stops, but if // then the pod is not removed from the apiserver quickly enough, logging // resumes and dumps the old log again. Previously, this was allowed based // on the assumption that it is better to log twice than miss log messages // of pods that started and immediately terminated or when logging temporarily // stopped. // // But it turned out to be rather confusing, so now a heuristic is used: if // log output of a container was already captured, then capturing does not // resume if the pod is marked for deletion. func CopyPodLogs(ctx context.Context, cs clientset.Interface, ns, podName string, to LogOutput) error { … } // logsForPod starts reading the logs for a certain pod. If the pod has more than one // container, opts.Container must be set. Reading stops when the context is done. // The stream includes formatted error messages and ends with // // rpc error: code = Unknown desc = Error: No such container: 41a... // // when the pod gets deleted while streaming. func logsForPod(ctx context.Context, cs clientset.Interface, ns, pod string, opts *v1.PodLogOptions) (io.ReadCloser, error) { … } // WatchPods prints pod status events for a certain namespace or all namespaces // when namespace name is empty. The closer can be nil if the caller doesn't want // the file to be closed when watching stops. func WatchPods(ctx context.Context, cs clientset.Interface, ns string, to io.Writer, toCloser io.Closer) (finalErr error) { … }