Skip to content

Commit

Permalink
bugfix(k8s): stream logs needs pod name
Browse files Browse the repository at this point in the history
  • Loading branch information
cognifloyd committed Apr 12, 2022
1 parent 962ec2f commit eb7572f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion runtime/kubernetes/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io
// streamContainerLogs streams the logs to a cache up to a maxLogSize, restarting the stream as needed.
// streamContainerLogs is designed to run in its own goroutine.
func (p podTracker) streamContainerLogs(ctx context.Context, ctnTracker *containerTracker, maxLogSize uint) {
p.Logger.Tracef("begin streaming logs for container %s in %s", ctnTracker.Name, p.TrackedPod)
// create function for periodically capturing
// the logs from the container with backoff
logsFunc := func() (bool, error) {
Expand All @@ -264,7 +265,7 @@ func (p podTracker) streamContainerLogs(ctx context.Context, ctnTracker *contain
// https://pkg.go.dev/k8s.io/client-go/rest?tab=doc#Request.Stream
stream, err := p.Kubernetes.CoreV1().
Pods(ctnTracker.Namespace).
GetLogs(ctnTracker.Name, opts).
GetLogs(ctnTracker.PodName, opts).
Stream(context.Background())
if err != nil {
p.Logger.Errorf("failed to stream logs for %s, %v", p.TrackedPod, err)
Expand Down
3 changes: 3 additions & 0 deletions runtime/kubernetes/pod_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var ErrTruncatedLogs = errors.New("TruncatedLogs")
type containerTracker struct {
// Namespace is the namespace the tracked container is in
Namespace string
// PodName is the name of the pod
PodName string
// Name is the name of the container
Name string
// terminatedOnce ensures that the Terminated channel only gets closed once.
Expand Down Expand Up @@ -196,6 +198,7 @@ func newPodTracker(log *logrus.Entry, clientset kubernetes.Interface, pod *v1.Po
for _, ctn := range pod.Spec.Containers {
containers[ctn.Name] = &containerTracker{
Namespace: pod.ObjectMeta.Namespace,
PodName: pod.ObjectMeta.Name,
Name: ctn.Name,
Terminated: make(chan struct{}),
Logs: logBuffer.NewBuffer(),
Expand Down

0 comments on commit eb7572f

Please sign in to comment.