mirror of
https://github.com/amir20/dozzle.git
synced 2026-01-03 11:35:00 +01:00
feat: adds streams to k8s
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user