portforwarder

package
v1.19.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type    EventType
	Message string
}

Event is a signal that PortForwarder emits on its event channel

type EventType

type EventType string

EventType is a type of event sent by PortForwarder

const (
	// ErrorEvent indicates a fatal error occurred which caused PortForwarder to exit
	ErrorEvent EventType = "ERROR"
	// InitEvent indicates PortForwarder was started and is ready
	InitEvent EventType = "INIT"
	// DoneEvent indicates PortForwarder exited gracefully
	DoneEvent EventType = "DONE"
)

type PortForwardOpt

type PortForwardOpt func(pf *PortForwarder)

PortForwardOpt is an optional parameter for PortForwarder

func WithOnReadyCallback

func WithOnReadyCallback(onReadyFunc func(int, string)) PortForwardOpt

WithOnReadyCallback registers a callback that will be invoked whenever the deployment's underlying pod changes and the port-forward is recreated. The callback must not invoke LocalPort from inside the callback, as this will lead to a deadlock.

type PortForwarder

type PortForwarder struct {
	// contains filtered or unexported fields
}

PortForwarder creates a port forwarding from localhost to a Deployment in the cluster. Assumes the Deployment has a single Pod, and keeps the port forward open if the Pod is deleted.

func NewPortForwarder

func NewPortForwarder(
	kubeClient *testkubeclient.KubeClient,
	watcher *testwatcher.Watcher,
	logger *testlogger.TestLogger,
	retryTimeout time.Duration,
	kubeConfigPath, ns, deployment, port string,
	opts ...PortForwardOpt,
) *PortForwarder

NewPortForwarder creates a new instance of a PortForwarder

func (*PortForwarder) LocalPort

func (pf *PortForwarder) LocalPort() (int, error)

LocalPort returns the current localhost port which forwards to the pod. lazily starts the port forward when called the first time.

func (*PortForwarder) Start

func (pf *PortForwarder) Start(ctx context.Context) chan Event

Start creates a port forward to a deployment's pod and keeps it open, even if the pod is recreated. Once ctx is cancelled, the port forward will be closed and will no longer be recreated. Returns an unbuffered channel that returns instances of Event. Consumers must read from this channel. The channel will be closed when the PortForwarder stops.

Jump to

Keyboard shortcuts

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