1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 13:23:07 +01:00

feat: adds shell support for k8s mode (#3747)

This commit is contained in:
Amir Raminfar
2025-04-02 09:27:57 -07:00
committed by GitHub
parent 8c4fcc6a7a
commit 8b058cae07
6 changed files with 154 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ package k8s_support
import (
"context"
"io"
"sync"
"github.com/rs/zerolog/log"
@@ -92,9 +93,65 @@ func (k *K8sClientService) SubscribeContainersStarted(ctx context.Context, conta
}
func (k *K8sClientService) Attach(ctx context.Context, container container.Container, stdin io.Reader, stdout io.Writer) error {
panic("not implemented")
cancelCtx, cancel := context.WithCancel(ctx)
writer, reader, err := k.client.ContainerAttach(cancelCtx, container.ID)
if err != nil {
cancel()
return err
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer writer.Close()
defer cancel()
defer wg.Done()
if _, err := io.Copy(writer, stdin); err != nil {
log.Error().Err(err).Msg("error copying stdin")
}
}()
go func() {
defer cancel()
defer wg.Done()
if _, err := io.Copy(stdout, reader); err != nil {
log.Error().Err(err).Msg("error copying stdout")
}
}()
wg.Wait()
return nil
}
func (k *K8sClientService) Exec(ctx context.Context, container container.Container, cmd []string, stdin io.Reader, stdout io.Writer) error {
panic("not implemented")
cancelCtx, cancel := context.WithCancel(ctx)
writer, reader, err := k.client.ContainerExec(cancelCtx, container.ID, cmd)
if err != nil {
cancel()
return err
}
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer writer.Close()
defer cancel()
defer wg.Done()
if _, err := io.Copy(writer, stdin); err != nil {
log.Error().Err(err).Msg("error copying stdin")
}
}()
go func() {
defer cancel()
defer wg.Done()
if _, err := io.Copy(stdout, reader); err != nil {
log.Error().Err(err).Msg("error copying stdout")
}
}()
wg.Wait()
return nil
}