diff --git a/internal/k8s/client.go b/internal/k8s/client.go index e37fa51b..03182bc7 100644 --- a/internal/k8s/client.go +++ b/internal/k8s/client.go @@ -151,12 +151,28 @@ func (k *K8sClient) FindContainer(ctx context.Context, id string) (container.Con func (k *K8sClient) ContainerLogs(ctx context.Context, id string, since time.Time, stdType container.StdType) (io.ReadCloser, error) { namespace, podName, containerName := parsePodContainerID(id) + + stream := "" + switch stdType { + case container.STDOUT: + stream = "Stdout" + case container.STDERR: + stream = "Stderr" + + case container.STDALL: + stream = "All" + + default: + return nil, fmt.Errorf("unknown stream type %s", stdType) + } + opts := &corev1.PodLogOptions{ Container: containerName, Follow: true, Previous: false, Timestamps: true, SinceTime: &metav1.Time{Time: since}, + Stream: &stream, } return k.Clientset.CoreV1().Pods(namespace).GetLogs(podName, opts).Stream(ctx) @@ -164,11 +180,25 @@ func (k *K8sClient) ContainerLogs(ctx context.Context, id string, since time.Tim func (k *K8sClient) ContainerLogsBetweenDates(ctx context.Context, id string, start time.Time, end time.Time, stdType container.StdType) (io.ReadCloser, error) { namespace, podName, containerName := parsePodContainerID(id) + + stream := "" + switch stdType { + case container.STDOUT: + stream = "Stdout" + case container.STDERR: + stream = "Stderr" + case container.STDALL: + stream = "All" + default: + return nil, fmt.Errorf("unknown stream type %s", stdType) + } + opts := &corev1.PodLogOptions{ Container: containerName, Follow: false, Timestamps: true, SinceTime: &metav1.Time{Time: start}, + Stream: &stream, } return k.Clientset.CoreV1().Pods(namespace).GetLogs(podName, opts).Stream(ctx)