forward

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package forward manages port-forwards into the cluster.

The daily loop ends with "now let me hit the service", so a tool that stops short of that sends the developer back to a terminal for the last step. This closes it.

Two rules shape the implementation. Every listener binds loopback only: forwarding a production database onto the office network would be a hole kubeside opened. And nothing survives the process: a tunnel into production left behind by a crashed UI is exactly what this tool must not leave running.

Index

Constants

View Source
const (
	StateReady   = "ready"
	StateStopped = "stopped"
	StateFailed  = "failed"
)

Forward states.

View Source
const DefaultStartTimeout = 15 * time.Second

DefaultStartTimeout bounds how long a caller waits for a tunnel to come up.

View Source
const LocalAddress = "127.0.0.1"

LocalAddress is where forwards bind. It is a constant rather than an option, for the same reason the web server's bind address is.

Variables

This section is empty.

Functions

func ValidTarget

func ValidTarget(t Target) error

ValidTarget rejects a namespace or pod that cannot be safely encoded as one path segment.

Every other cluster call in this product goes through client-go's typed builders, which run this same check before a request is built. The tunnel is the one path assembled by hand, because SPDY needs the URL rather than a request object, so the check has to be made explicitly here rather than inherited.

Types

type Forward

type Forward struct {
	ID          string `json:"id"`
	Context     string `json:"context"`
	Namespace   string `json:"namespace"`
	Workload    string `json:"workload"`
	Pod         string `json:"pod"`
	RemotePort  int    `json:"remotePort"`
	LocalPort   int    `json:"localPort"`
	Address     string `json:"address"`
	State       string `json:"state"`
	Environment string `json:"environment,omitempty"`
	Risk        string `json:"risk,omitempty"`
	StartedAt   string `json:"startedAt"`
	Error       string `json:"error,omitempty"`
}

Forward is one running tunnel.

type KubeTunnel

type KubeTunnel struct {
	// RESTConfig returns the config for one context. Credential plugins run
	// here, the same as everywhere else.
	RESTConfig func(contextName string) (*rest.Config, error)
}

KubeTunnel is the production tunnel: SPDY to the apiserver, exactly the mechanism kubectl port-forward uses.

func (KubeTunnel) Open

func (k KubeTunnel) Open(ctx context.Context, t Target, ready func(localPort int)) error

Open holds the forward until ctx is cancelled.

type Manager

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

Manager owns every live forward.

func New

func New(t Tunnel) *Manager

New builds a manager. Nothing is opened until Start.

func (*Manager) List

func (m *Manager) List() []Forward

List returns every live forward, oldest first.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context, t Target) (Forward, error)

Start opens a forward, or hands back the one already serving this target.

Asking twice for the same service should not produce two tunnels on two ports, because then half the developer's terminal history points at a port that is no longer the one.

func (*Manager) Stop

func (m *Manager) Stop(id string) error

Stop closes one forward.

func (*Manager) StopAll

func (m *Manager) StopAll()

StopAll closes every forward. It runs when kubeside exits, so no tunnel outlives the process that opened it.

type Target

type Target struct {
	Context   string
	Namespace string
	Workload  string
	Pod       string
	// RemotePort is the container port. LocalPort is a request, and zero means
	// the operating system picks a free one.
	RemotePort int
	LocalPort  int
	// Environment and Risk travel with the forward so the UI can colour it. A
	// tunnel into production is a different thing from one into qa.
	Environment string
	Risk        string
}

Target is what to forward to.

type Tunnel

type Tunnel interface {
	Open(ctx context.Context, t Target, ready func(localPort int)) error
}

Tunnel opens one port-forward and holds it until the context is cancelled. Keeping it an interface lets the lifecycle be tested without an apiserver.

Jump to

Keyboard shortcuts

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