Documentation
¶
Overview ¶
Package portforward adds support for SSH-like port forwarding from the client's local host to remote containers.
Index ¶
- Constants
- Variables
- func NewFallbackDialer(primary, secondary httpstream.Dialer, shouldFallback func(error) bool) httpstream.Dialer
- func NewFallbackDialerForStreaming(primary, secondary streamhttp.Dialer, shouldFallback func(error) bool) streamhttp.Dialer
- func NewSPDYOverWebsocketDialer(url *url.URL, config *restclient.Config) (httpstream.Dialer, error)
- func NewSPDYOverWebsocketDialerForStreaming(url *url.URL, config *restclient.Config) (streamhttp.Dialer, error)
- func NewSPDYOverWebsocketDialerForStreamingWithLogger(logger klog.Logger, url *url.URL, config *restclient.Config) (streamhttp.Dialer, error)
- func NewSPDYOverWebsocketDialerWithLogger(logger klog.Logger, url *url.URL, config *restclient.Config) (httpstream.Dialer, error)
- type FallbackDialer
- type ForwardedPort
- type PortForwarder
- func New(dialer httpstream.Dialer, ports []string, stopChan <-chan struct{}, ...) (*PortForwarder, error)
- func NewForStreaming(dialer streamhttp.Dialer, ports []string, stopChan <-chan struct{}, ...) (*PortForwarder, error)
- func NewOnAddresses(dialer httpstream.Dialer, addresses []string, ports []string, ...) (*PortForwarder, error)
- func NewOnAddressesForStreaming(dialer streamhttp.Dialer, addresses []string, ports []string, ...) (*PortForwarder, error)
- func NewOnAddressesForStreamingWithContext(ctx context.Context, dialer streamhttp.Dialer, addresses []string, ...) (*PortForwarder, error)
- func NewOnAddressesWithContext(ctx context.Context, dialer httpstream.Dialer, addresses []string, ...) (*PortForwarder, error)
- type StreamingFallbackDialer
- type TunnelingConnection
- func (c *TunnelingConnection) Close() error
- func (c *TunnelingConnection) LocalAddr() net.Addr
- func (c *TunnelingConnection) Read(p []byte) (len int, err error)
- func (c *TunnelingConnection) RemoteAddr() net.Addr
- func (c *TunnelingConnection) SetDeadline(t time.Time) error
- func (c *TunnelingConnection) SetReadDeadline(t time.Time) error
- func (c *TunnelingConnection) SetWriteDeadline(t time.Time) error
- func (c *TunnelingConnection) Write(p []byte) (n int, err error)
Constants ¶
const PingPeriod = 10 * time.Second
const PortForwardProtocolV1Name = "portforward.k8s.io"
PortForwardProtocolV1Name is the subprotocol used for port forwarding. TODO move to API machinery and re-unify with kubelet/server/portfoward
Variables ¶
var ( // error returned whenever we lost connection to a pod ErrLostConnectionToPod = errors.New("lost connection to pod") )
Functions ¶
func NewFallbackDialer ¶ added in v0.30.0
func NewFallbackDialer(primary, secondary httpstream.Dialer, shouldFallback func(error) bool) httpstream.Dialer
NewFallbackDialer creates the FallbackDialer with the primary and secondary dialers, as well as the boolean function to determine if the primary dialer failed.
func NewFallbackDialerForStreaming ¶ added in v0.36.0
func NewFallbackDialerForStreaming(primary, secondary streamhttp.Dialer, shouldFallback func(error) bool) streamhttp.Dialer
NewFallbackDialerForStreaming creates a fallback dialer for in-tree callers that use k8s.io/streaming/pkg/httpstream types.
func NewSPDYOverWebsocketDialer ¶ added in v0.30.0
func NewSPDYOverWebsocketDialer(url *url.URL, config *restclient.Config) (httpstream.Dialer, error)
NewTunnelingDialer creates and returns the tunnelingDialer structure which implemements the "httpstream.Dialer" interface. The dialer can upgrade a websocket request, creating a websocket connection. This function returns an error if one occurs.
func NewSPDYOverWebsocketDialerForStreaming ¶ added in v0.36.0
func NewSPDYOverWebsocketDialerForStreaming(url *url.URL, config *restclient.Config) (streamhttp.Dialer, error)
NewSPDYOverWebsocketDialerForStreaming creates a SPDY-over-websocket dialer for in-tree callers that use k8s.io/streaming/pkg/httpstream types.
func NewSPDYOverWebsocketDialerForStreamingWithLogger ¶ added in v0.37.0
func NewSPDYOverWebsocketDialerForStreamingWithLogger(logger klog.Logger, url *url.URL, config *restclient.Config) (streamhttp.Dialer, error)
NewSPDYOverWebsocketDialerForStreamingWithLogger creates a SPDY-over-websocket dialer for in-tree callers that use k8s.io/streaming/pkg/httpstream types.
func NewSPDYOverWebsocketDialerWithLogger ¶ added in v0.37.0
func NewSPDYOverWebsocketDialerWithLogger(logger klog.Logger, url *url.URL, config *restclient.Config) (httpstream.Dialer, error)
NewTunnelingDialer creates and returns the tunnelingDialer structure which implemements the "httpstream.Dialer" interface. The dialer can upgrade a websocket request, creating a websocket connection. This function returns an error if one occurs.
Types ¶
type FallbackDialer ¶ added in v0.31.0
type FallbackDialer struct {
// contains filtered or unexported fields
}
FallbackDialer encapsulates a primary and secondary dialer, including the boolean function to determine if the primary dialer failed. Implements the httpstream.Dialer interface.
func (*FallbackDialer) Dial ¶ added in v0.31.0
func (f *FallbackDialer) Dial(protocols ...string) (httpstream.Connection, string, error)
Dial is the single function necessary to implement the "httpstream.Dialer" interface. It takes the protocol version strings to request, returning an the upgraded httstream.Connection and the negotiated protocol version accepted. If the initial primary dialer fails, this function attempts the secondary dialer. Returns an error if one occurs.
type ForwardedPort ¶
ForwardedPort contains a Local:Remote port pairing.
type PortForwarder ¶
type PortForwarder struct {
Ready chan struct{}
// contains filtered or unexported fields
}
PortForwarder knows how to listen for local connections and forward them to a remote pod via an upgraded HTTP request.
func New ¶
func New(dialer httpstream.Dialer, ports []string, stopChan <-chan struct{}, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error)
New creates a new PortForwarder with localhost listen addresses.
func NewForStreaming ¶ added in v0.36.0
func NewForStreaming(dialer streamhttp.Dialer, ports []string, stopChan <-chan struct{}, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error)
NewForStreaming creates a new PortForwarder with localhost listen addresses for in-tree callers that use k8s.io/streaming/pkg/httpstream types.
func NewOnAddresses ¶
func NewOnAddresses(dialer httpstream.Dialer, addresses []string, ports []string, stopChan <-chan struct{}, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error)
NewOnAddresses creates a new PortForwarder with custom listen addresses.
func NewOnAddressesForStreaming ¶ added in v0.36.0
func NewOnAddressesForStreaming(dialer streamhttp.Dialer, addresses []string, ports []string, stopChan <-chan struct{}, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error)
NewOnAddressesForStreaming creates a new PortForwarder with custom listen addresses for in-tree callers that use k8s.io/streaming/pkg/httpstream types.
func NewOnAddressesForStreamingWithContext ¶ added in v0.37.0
func NewOnAddressesForStreamingWithContext(ctx context.Context, dialer streamhttp.Dialer, addresses []string, ports []string, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error)
NewOnAddressesForStreamingWithContext creates a new PortForwarder with custom listen addresses for in-tree callers that use k8s.io/streaming/pkg/httpstream types.
func NewOnAddressesWithContext ¶ added in v0.37.0
func NewOnAddressesWithContext(ctx context.Context, dialer httpstream.Dialer, addresses []string, ports []string, readyChan chan struct{}, out, errOut io.Writer) (*PortForwarder, error)
NewOnAddressesWithContext creates a new PortForwarder with custom listen addresses.
func (*PortForwarder) Close ¶
func (pf *PortForwarder) Close()
Close stops all listeners of PortForwarder.
func (*PortForwarder) ForwardPorts ¶
func (pf *PortForwarder) ForwardPorts() error
ForwardPorts formats and executes a port forwarding request. The connection will remain open until stopChan is closed.
func (*PortForwarder) GetPorts ¶
func (pf *PortForwarder) GetPorts() ([]ForwardedPort, error)
GetPorts will return the ports that were forwarded; this can be used to retrieve the locally-bound port in cases where the input was port 0. This function will signal an error if the Ready channel is nil or if the listeners are not ready yet; this function will succeed after the Ready channel has been closed.
type StreamingFallbackDialer ¶ added in v0.36.0
type StreamingFallbackDialer struct {
// contains filtered or unexported fields
}
StreamingFallbackDialer encapsulates a primary and secondary streaming dialer with fallback behavior.
func (*StreamingFallbackDialer) Dial ¶ added in v0.36.0
func (f *StreamingFallbackDialer) Dial(protocols ...string) (streamhttp.Connection, string, error)
Dial is the single function necessary to implement the "k8s.io/streaming/pkg/httpstream.Dialer" interface.
type TunnelingConnection ¶ added in v0.30.0
type TunnelingConnection struct {
// contains filtered or unexported fields
}
TunnelingConnection implements the "httpstream.Connection" interface, wrapping a websocket connection that tunnels SPDY.
func NewTunnelingConnection ¶ added in v0.30.0
func NewTunnelingConnection(name string, conn *gwebsocket.Conn) *TunnelingConnection
NewTunnelingConnection wraps the passed gorilla/websockets connection with the TunnelingConnection struct (implementing net.Conn). The name is added to all log entries with klog.LoggerWithName.
func NewTunnelingConnectionWithLogger ¶ added in v0.37.0
func NewTunnelingConnectionWithLogger(logger klog.Logger, conn *gwebsocket.Conn) *TunnelingConnection
NewTunnelingConnectionWithLogger is a variant of NewTunnelingConnection where the caller is in control of logging. For example, klog.LoggerWithName can be used to add a common name for all log entries to identify the connection.
func (*TunnelingConnection) Close ¶ added in v0.30.0
func (c *TunnelingConnection) Close() error
Close implements "io.Closer" interface, signaling the other tunneled connection endpoint, and closing the tunneled connection only once.
func (*TunnelingConnection) LocalAddr ¶ added in v0.30.0
func (c *TunnelingConnection) LocalAddr() net.Addr
LocalAddr implements part of the "net.Conn" interface, returning the local endpoint network address of the tunneled connection.
func (*TunnelingConnection) Read ¶ added in v0.30.0
func (c *TunnelingConnection) Read(p []byte) (len int, err error)
Read implements "io.Reader" interface, reading from the stored connection into the passed buffer "p". Returns the number of bytes read and an error. Can keep track of the "inProgress" messsage from the tunneled connection.
func (*TunnelingConnection) RemoteAddr ¶ added in v0.30.0
func (c *TunnelingConnection) RemoteAddr() net.Addr
LocalAddr implements part of the "net.Conn" interface, returning the remote endpoint network address of the tunneled connection.
func (*TunnelingConnection) SetDeadline ¶ added in v0.30.0
func (c *TunnelingConnection) SetDeadline(t time.Time) error
SetDeadline sets the *absolute* time in the future for both read and write deadlines. Returns an error if one occurs.
func (*TunnelingConnection) SetReadDeadline ¶ added in v0.30.0
func (c *TunnelingConnection) SetReadDeadline(t time.Time) error
SetDeadline sets the *absolute* time in the future for the read deadlines. Returns an error if one occurs.
func (*TunnelingConnection) SetWriteDeadline ¶ added in v0.30.0
func (c *TunnelingConnection) SetWriteDeadline(t time.Time) error
SetDeadline sets the *absolute* time in the future for the write deadlines. Returns an error if one occurs.