portforward

package
v0.0.0-...-0f279ed Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, forwarder PortForwarder, opts PortForwardOptions) chan error

Run leverages forwarder to create a TCP tunnel according to opts. This function runs asynchronously and returns a channel that may: - produce and error and then close immediately. This means the forwarder couldn't establish the tunnel; - close without errors. In this case the tunnel is in place and ready to accept connections.

A client is not supposed to close the channel but it must wait for it to either close or produce an error; this function will leak a goroutine otherwise.

Good:

if err := <-Run(ctx, PortForwardOptions{}); err != nil {
	// handle the error somehow
}

Bad:

_ = Run(ctx, PortForwardOptions{}) // a goroutine will run forever, trying to push an error

func SPDYPortForwarder

func SPDYPortForwarder(method string, url *url.URL, readyChannel chan struct{}, opts PortForwardOptions) error

Types

type PodGetter

type PodGetter func(ctx context.Context, namespace, name string) (*corev1.Pod, error)

PodGetter knows how to get a pod

type PortForwardOptions

type PortForwardOptions struct {
	Namespace string
	PodName   string
	PodGetter PodGetter

	// Closing this channel stops the port forwarder
	StopChannel chan struct{}

	Config  *restclient.Config
	Out     io.Writer
	ErrOut  io.Writer
	Address []string
	Ports   []string
}

type PortForwarder

type PortForwarder func(method string, url *url.URL, readyChannel chan struct{}, opts PortForwardOptions) error

PortForwarder knows how to establish a tunnel to a pod at url, according to opts. It's likely the implementors of this interface will run async, readyChannel is here to inform clients when the tunnel has been successfully established.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL