Fix spurious logs when dev loop is restarted
Fix
@@ -152,8 +152,12 @@ func (a *LogAggregator) streamContainerLogs(ctx context.Context, pod *v1.Pod, co
tr, tw := io.Pipe()
go func() {
if err := a.kubectlcli.Run(ctx, nil, tw, "logs", sinceSeconds, "-f", pod.Name, "-c", container.Name, "--namespace", pod.Namespace); err != nil {
+ // Don't print errors if the user interrupted the logs
+ // or if the logs were interrupted because of a configuration change
+ if ctx.Err() != context.Canceled {
logrus.Warn(err)
}
+ }
_ = tw.Close()
}()
@@ -193,7 +197,10 @@ func (a *LogAggregator) streamRequest(ctx context.Context, headerColor color.Col
// Read up to newline
line, err := r.ReadString('\n')
if err == io.EOF {
+ // Unless the context was interrupted, this means that the container was stopped.
+ if ctx.Err() != context.Canceled {
a.printLogLine(headerColor, prefix, "<Container was Terminated>\n")
+ }
return nil
}
if err != nil {
