portforward

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FreePort

func FreePort(preferred int) int

FreePort finds a free TCP port starting from the preferred port. It tries the preferred port first, then increments until one is available.

func Stop

func Stop(name string) error

Stop terminates a named port-forward and removes its PID file.

Types

type Info

type Info struct {
	PID        int       `json:"pid"`
	Name       string    `json:"name"`
	Namespace  string    `json:"namespace"`
	Pod        string    `json:"pod"`
	LocalPort  int       `json:"local_port"`
	RemotePort int       `json:"remote_port"`
	StartedAt  time.Time `json:"started_at"`
}

Info holds metadata about a running port-forward.

func FindByNamespaceAndPod

func FindByNamespaceAndPod(namespace, pod string) (*Info, bool)

FindByNamespaceAndPod finds an active port-forward for the given namespace and pod. Returns the info and true if found and running, or nil and false otherwise.

func IsRunning

func IsRunning(name string) (*Info, bool)

IsRunning checks if a named port-forward is active. Returns the info and true if running, or nil and false otherwise. Cleans up stale PID files.

func List

func List() ([]*Info, error)

List returns all tracked port-forwards, cleaning up stale entries.

func Start

func Start(name, namespace, pod string, localPort, remotePort int) (*Info, error)

Start launches a detached kubectl port-forward process. If the same target is already running, it returns the existing info. If a different target is running under the same name, it stops the old one first.

Jump to

Keyboard shortcuts

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