61 lines
1.3 KiB
Go

package kubernetes
import (
"io"
"net"
"time"
"k8s.io/client-go/tools/remotecommand"
)
type kubeConn struct {
stdinWriter *io.PipeWriter
stdoutReader *io.PipeReader
closeCh chan struct{}
}
func (c *kubeConn) Read(b []byte) (int, error) {
return c.stdoutReader.Read(b)
}
func (c *kubeConn) Write(b []byte) (int, error) {
return c.stdinWriter.Write(b)
}
func (c *kubeConn) Close() error {
close(c.closeCh)
c.stdinWriter.Close()
return nil
}
func (c *kubeConn) LocalAddr() net.Addr { return dummyAddr("local") }
func (c *kubeConn) RemoteAddr() net.Addr { return dummyAddr("remote") }
func (c *kubeConn) SetDeadline(t time.Time) error { return nil }
func (c *kubeConn) SetReadDeadline(t time.Time) error { return nil }
func (c *kubeConn) SetWriteDeadline(t time.Time) error { return nil }
type dummyAddr string
func (a dummyAddr) Network() string { return string(a) }
func (a dummyAddr) String() string { return string(a) }
func newKubeCon(stdin *io.PipeWriter, stdout *io.PipeReader) net.Conn {
return &kubeConn{
stdinWriter: stdin,
stdoutReader: stdout,
closeCh: make(chan struct{}),
}
}
type sizeQueue struct {
resizeChan chan remotecommand.TerminalSize
}
func (s *sizeQueue) Next() *remotecommand.TerminalSize {
size, ok := <-s.resizeChan
if !ok {
return nil
}
return &size
}