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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user