TUN-8734: add log collection for kubernetes

## Summary
Adds the log collector for K8s based deployments.

Closes TUN-8734
This commit is contained in:
Luis Neto
2024-11-27 03:15:15 -08:00
parent 16e65c70ad
commit 46dc6316f9
3 changed files with 111 additions and 37 deletions

View File

@@ -3,7 +3,6 @@ package diagnostic
import (
"context"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
@@ -44,40 +43,5 @@ func (collector *DockerLogCollector) Collect(ctx context.Context) (*LogInformati
collector.containerID,
)
stdoutReader, err := command.StdoutPipe()
if err != nil {
return nil, fmt.Errorf(
"error retrieving output from command '%s': %w",
command.String(),
err,
)
}
if err := command.Start(); err != nil {
return nil, fmt.Errorf(
"error running command '%s': %w",
command.String(),
err,
)
}
_, err = io.Copy(outputHandle, stdoutReader)
if err != nil {
return nil, fmt.Errorf(
"error copying output from %s to file %s: %w",
command.String(),
outputHandle.Name(),
err,
)
}
if err := command.Wait(); err != nil {
return nil, fmt.Errorf(
"error waiting from command '%s': %w",
command.String(),
err,
)
}
return NewLogInformation(outputHandle.Name(), true, false), nil
return PipeCommandOutputToFile(command, outputHandle)
}